From ca3c1420dea9694ed5200c2f919fee92c068f347 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Thu, 21 Nov 2024 13:39:03 -0600 Subject: [PATCH 01/69] General traits WIP, including library tests --- Source/DafnyCore/Backends/Dafny/AST.dfy | 18 +- Source/DafnyCore/Backends/Dafny/ASTBuilder.cs | 2 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 7 +- .../Rust/Dafny-compiler-rust-rast.dfy | 21 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 97 ++++- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 190 +++++----- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 347 +++++++++--------- .../DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 18 +- .../DafnyRuntimeRust/src/tests/mod.rs | 95 +++++ .../LitTest/comp/rust/traits-datatypes.dfy | 40 ++ .../comp/rust/traits-datatypes.dfy.expect | 3 + 11 files changed, 550 insertions(+), 288 deletions(-) create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index c315565ad99..0e5f3c249c1 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -166,16 +166,16 @@ module {:extern "DAST"} DAST { datatype Attribute = Attribute(name: string, args: seq) - datatype DatatypeType = DatatypeType() - - datatype TraitType = TraitType() - datatype NewtypeType = NewtypeType(baseType: Type, range: NewtypeRange, erase: bool) + + datatype TraitType = + | ObjectTrait() // Traits that extend objects with --type-system-refresh, all traits otherwise + | GeneralTrait() // Traits that don't necessarily extend objects with --type-system-refresh datatype ResolvedTypeBase = | Class() | Datatype(variances: seq) - | Trait() + | Trait(traitType: TraitType) | SynonymType(baseType: Type) | Newtype(baseType: Type, range: NewtypeRange, erase: bool) @@ -208,7 +208,13 @@ module {:extern "DAST"} DAST { datatype Class = Class(name: Name, enclosingModule: Ident, typeParams: seq, superClasses: seq, fields: seq, body: seq, attributes: seq) - datatype Trait = Trait(name: Name, typeParams: seq, parents: seq, body: seq, attributes: seq) + datatype Trait = Trait( + name: Name, + typeParams: seq, + traitType: TraitType, + parents: seq, + body: seq, + attributes: seq) datatype Datatype = Datatype(name: Name, enclosingModule: Ident, typeParams: seq, ctors: seq, body: seq, isCo: bool, attributes: seq) diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index 29b36afbb3c..11f319b4e04 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -1021,7 +1021,7 @@ public void AddExpr(DAST.Expression value) { public void AddBuildable(BuildableExpr value) { if (this.value != null) { - throw new InvalidOperationException(); + AddUnsupported("Second value for ReturnBuilder"); } else { this.value = value; } diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 0cc3c439777..6eea3632e92 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -1755,8 +1755,11 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type } else if (topLevel is TypeSynonymDecl typeSynonym) { // Also SubsetTypeDecl resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_SynonymType( GenType(typeSynonym.Rhs.Subst(typeSynonym.TypeArgs.Zip(typeArgs).ToDictionary(kv => kv.Item1, kv => kv.Item2)).NormalizeExpand())); - } else if (topLevel is TraitDecl) { - resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Trait(); + } else if (topLevel is TraitDecl traitDecl) { + var traitType = traitDecl.IsReferenceTypeDecl + ? TraitType.create_ObjectTrait() + : TraitType.create_GeneralTrait(); + resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Trait(traitType); } else if (topLevel is DatatypeDecl dd) { var variances = Sequence.FromArray(dd.TypeArgs.Select(GenTypeVariance).ToArray()); resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Datatype(variances); diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index 795027f71b7..2f7b3f5e647 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -593,6 +593,8 @@ module RAST } const PtrPath: Path := dafny_runtime.MSel("Ptr") + + const BoxPath := std.MSel("box").MSel("Box") const Ptr := PtrPath.AsExpr() @@ -624,10 +626,25 @@ module RAST } function Box(content: Type): Type { - TypeApp(TIdentifier("Box"), [content]) + TypeApp(BoxPath.AsType(), [content]) } function BoxNew(content: Expr): Expr { - Identifier("Box").FSel("new").Apply([content]) + BoxPath.AsExpr().FSel("new").Apply([content]) + } + predicate IsBox() { + match this { + case TypeApp(TypeFromPath(o), elems1) => + o == BoxPath && |elems1| == 1 + case _ => false + } + } + function BoxUnderlying(): Type + requires IsBox() + { + match this { + case TypeApp(TypeFromPath(o), elems1) => + elems1[0] + } } datatype Path = diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 4d8df58e8dd..c3fcd3a7cda 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -354,7 +354,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := s + testMethods; } var genSelfPath := GenPathType(path); - // TODO: If general traits, check whether the trait extends object or not. if className != "_default" { s := s + [ R.ImplDecl( @@ -377,7 +376,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { for i := 0 to |superClasses| { var superClass := superClasses[i]; match superClass { - case UserDefined(ResolvedType(traitPath, typeArgs, Trait(), _, properMethods, _)) => { + case UserDefined(ResolvedType(traitPath, typeArgs, Trait(traitType), _, properMethods, _)) => { var pathStr := GenPathType(traitPath); var typeArgs := GenTypeArgs(typeArgs, GenTypeContext.default()); var body: seq := []; @@ -385,7 +384,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { body := traitBodies[traitPath]; } - var traitType := R.TypeApp(pathStr, typeArgs); + var fullTraitPath := R.TypeApp(pathStr, typeArgs); if !extern.NoExtern? { // An extern of some kind // Either the Dafny code implements all the methods of the trait or none, if |body| == 0 && |properMethods| != 0 { @@ -393,7 +392,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } if |body| != |properMethods| { error := Some("Error: In the class " + R.SeqToString(path, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + - traitType.ToString("") + " are marked {:extern} and some are not." + + fullTraitPath.ToString("") + " are marked {:extern} and some are not." + " For the Rust compiler, please make all methods (" + R.SeqToString(properMethods, (s: Name) => s.dafny_name, ", ") + ") bodiless and mark as {:extern} and implement them in a Rust file, "+ "or mark none of them as {:extern} and implement them in Dafny. " + @@ -403,10 +402,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if |body| == 0 { // Extern type, we assume } + if traitType.GeneralTrait? { + // One more method: Cloning when boxed + /*impl Test for Wrapper { + fn _clone(&self) -> Box { + Box::new(self.clone()) + } + }*/ + body := body + [ + R.FnDecl( + R.PRIV, + R.Fn( + "_clone", [], [R.Formal.selfBorrowed], R.Boxed(R.DynType(fullTraitPath)), + "", + Some(R.BoxNew(R.self.MSel("clone").Apply0())))) + ]; + } var x := R.ImplDecl( R.ImplFor( rTypeParamsDecls, - traitType, + fullTraitPath, R.TypeApp(genSelfPath, rTypeParams), whereConstraints, body @@ -417,14 +432,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplDecl( R.ImplFor( rTypeParamsDecls, - R.dafny_runtime.MSel(Upcast).AsType().Apply([R.DynType(traitType)]), + R.dafny_runtime.MSel(Upcast).AsType().Apply([R.DynType(fullTraitPath)]), R.TypeApp(genSelfPath, rTypeParams), whereConstraints, [ R.ImplMemberMacro( R.dafny_runtime .MSel(UpcastFnMacro).AsExpr() - .Apply1(R.ExprFromType(R.DynType(traitType)))) + .Apply1(R.ExprFromType(R.DynType(fullTraitPath)))) ] ) ) @@ -439,28 +454,41 @@ module {:extern "DCOMP"} DafnyToRustCompiler { modifies this { var typeParamsSeq := []; - var typeParamDecls := []; - var typeParams := []; + var rTypeParamsDecls: seq := []; + var typeParams: seq := []; if |t.typeParams| > 0 { for tpI := 0 to |t.typeParams| { var tp := t.typeParams[tpI]; var typeArg, typeParamDecl := GenTypeParam(tp); typeParamsSeq := typeParamsSeq + [typeArg]; - typeParamDecls := typeParamDecls + [typeParamDecl]; + rTypeParamsDecls := rTypeParamsDecls + [typeParamDecl]; var typeParam := GenType(typeArg, GenTypeContext.default()); typeParams := typeParams + [typeParam]; } } var fullPath := containingPath + [Ident.Ident(t.name)]; + var traitFulltype := R.TypeApp(R.TIdentifier(escapeName(t.name)), typeParams); var implBody, _ := GenClassImplBody( t.body, true, UserDefined( ResolvedType( fullPath, [], - ResolvedTypeBase.Trait(), t.attributes, + ResolvedTypeBase.Trait(t.traitType), t.attributes, [], [])), typeParamsSeq); + if t.traitType.GeneralTrait? { // Cloning is boxed + // fn _clone(&self) -> Box; + implBody := implBody + [ + R.FnDecl( + R.PRIV, + R.Fn( + "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(traitFulltype))), + "", + None + )); + ]; + } var parents := []; for i := 0 to |t.parents| { var tpe := GenType(t.parents[i], GenTypeContext.ForTraitParents()); @@ -469,10 +497,32 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := [ R.TraitDecl( R.Trait( - typeParamDecls, R.TypeApp(R.TIdentifier(escapeName(t.name)), typeParams), + rTypeParamsDecls, traitFulltype, parents, implBody ))]; + if t.traitType.GeneralTrait? { + /*impl Clone for Box { + fn clone(&self) -> Box { + self._clone() + } + }*/ + s := s + [ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.std.MSel("clone").MSel("Clone"), + R.Box(R.DynType(traitFulltype)), + "", + [R.FnDecl( + R.PRIV, + R.Fn("clone", [], + [ R.Formal.selfBorrowed ], + Some(R.SelfOwned), + "", + Some(R.self.FSel("_clone").Apply0()) + )]))]; + } } method GenNewtype(c: Newtype, path: seq) returns (s: seq) @@ -802,6 +852,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ResolvedTypeBase.Datatype(variances), c.attributes, [], [])), typeParamsSeq); + if |traitBodies| > 0 { + error := Some("No support for trait in datatypes yet"); + } var implBody: seq := implBodyRaw; var emittedFields: set := {}; for i := 0 to |c.ctors| { @@ -1273,7 +1326,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := R.Rc(s); } } - case Trait() => { + case Trait(GeneralTrait()) => { + if !genTypeContext.forTraitParents { + s := R.Box(R.DynType(s)); + } + } + case Trait(ObjectTrait()) => { if resolved.path == [Ident.Ident(Name("_System")), Ident.Ident(Name("object"))] { s := R.AnyTrait; } @@ -2623,10 +2681,19 @@ module {:extern "DCOMP"} DafnyToRustCompiler { { if fromTpe == toTpe then Success(R.dafny_runtime.MSel("upcast_id").AsExpr().ApplyType([fromTpe]).Apply0()) + else if toTpe.IsBox() then // General trait + var toTpeUnderlying := toTpe.BoxUnderlying(); + if !toTpeUnderlying.DynType? then Failure((fromType, fromTpe, toType, toTpe, typeParams)) else + if fromTpe.IsBox() then + var fromTpeUnderlying := fromTpe.BoxUnderlying(); + if !fromTpeUnderlying.DynType? then Failure((fromType, fromTpe, toType, toTpe, typeParams)) else + Success(R.dafny_runtime.MSel("upcast_box_box").AsExpr().ApplyType([fromTpeUnderlying, toTpeUnderlying]).Apply0()) + else + Success(R.dafny_runtime.MSel("upcast_box").AsExpr().ApplyType([fromTpe, toTpeUnderlying]).Apply0()) else if fromTpe.IsObjectOrPointer() && toTpe.IsObjectOrPointer() then - if !toTpe.ObjectOrPointerUnderlying().DynType? then Failure((fromType, fromTpe, toType, toTpe, typeParams)) else - var fromTpeUnderlying := fromTpe.ObjectOrPointerUnderlying(); var toTpeUnderlying := toTpe.ObjectOrPointerUnderlying(); + if !toTpeUnderlying.DynType? then Failure((fromType, fromTpe, toType, toTpe, typeParams)) else + var fromTpeUnderlying := fromTpe.ObjectOrPointerUnderlying(); Success(R.dafny_runtime.MSel(upcast).AsExpr().ApplyType([fromTpeUnderlying, toTpeUnderlying]).Apply0()) else if (fromTpe, toTpe) in typeParams then Success(typeParams[(fromTpe, toTpe)]) diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 42aeb9b108d..566db364bee 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -2165,98 +2165,6 @@ public Dafny.ISequence> dtor_args { } } - public interface _IDatatypeType { - bool is_DatatypeType { get; } - _IDatatypeType DowncastClone(); - } - public class DatatypeType : _IDatatypeType { - public DatatypeType() { - } - public _IDatatypeType DowncastClone() { - if (this is _IDatatypeType dt) { return dt; } - return new DatatypeType(); - } - public override bool Equals(object other) { - var oth = other as DAST.DatatypeType; - 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.DatatypeType.DatatypeType"; - return s; - } - private static readonly DAST._IDatatypeType theDefault = create(); - 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() { - return new DatatypeType(); - } - public static _IDatatypeType create_DatatypeType() { - return create(); - } - public bool is_DatatypeType { get { return true; } } - public static System.Collections.Generic.IEnumerable<_IDatatypeType> AllSingletonConstructors { - get { - yield return DatatypeType.create(); - } - } - } - - public interface _ITraitType { - bool is_TraitType { get; } - _ITraitType DowncastClone(); - } - public class TraitType : _ITraitType { - public TraitType() { - } - public _ITraitType DowncastClone() { - if (this is _ITraitType dt) { return dt; } - return new TraitType(); - } - public override bool Equals(object other) { - var oth = other as DAST.TraitType; - 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.TraitType.TraitType"; - return s; - } - private static readonly DAST._ITraitType theDefault = create(); - public static DAST._ITraitType Default() { - return theDefault; - } - private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.TraitType.Default()); - public static Dafny.TypeDescriptor _TypeDescriptor() { - return _TYPE; - } - public static _ITraitType create() { - return new TraitType(); - } - public static _ITraitType create_TraitType() { - return create(); - } - public bool is_TraitType { get { return true; } } - public static System.Collections.Generic.IEnumerable<_ITraitType> AllSingletonConstructors { - get { - yield return TraitType.create(); - } - } - } - public interface _INewtypeType { bool is_NewtypeType { get; } DAST._IType dtor_baseType { get; } @@ -2332,6 +2240,81 @@ public bool dtor_erase { } } + public interface _ITraitType { + bool is_ObjectTrait { get; } + bool is_GeneralTrait { get; } + _ITraitType DowncastClone(); + } + public abstract class TraitType : _ITraitType { + public TraitType() { + } + private static readonly DAST._ITraitType theDefault = create_ObjectTrait(); + public static DAST._ITraitType Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.TraitType.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _ITraitType create_ObjectTrait() { + return new TraitType_ObjectTrait(); + } + public static _ITraitType create_GeneralTrait() { + return new TraitType_GeneralTrait(); + } + public bool is_ObjectTrait { get { return this is TraitType_ObjectTrait; } } + public bool is_GeneralTrait { get { return this is TraitType_GeneralTrait; } } + public static System.Collections.Generic.IEnumerable<_ITraitType> AllSingletonConstructors { + get { + yield return TraitType.create_ObjectTrait(); + yield return TraitType.create_GeneralTrait(); + } + } + public abstract _ITraitType DowncastClone(); + } + public class TraitType_ObjectTrait : TraitType { + public TraitType_ObjectTrait() : base() { + } + public override _ITraitType DowncastClone() { + if (this is _ITraitType dt) { return dt; } + return new TraitType_ObjectTrait(); + } + public override bool Equals(object other) { + var oth = other as DAST.TraitType_ObjectTrait; + 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.TraitType.ObjectTrait"; + return s; + } + } + public class TraitType_GeneralTrait : TraitType { + public TraitType_GeneralTrait() : base() { + } + public override _ITraitType DowncastClone() { + if (this is _ITraitType dt) { return dt; } + return new TraitType_GeneralTrait(); + } + public override bool Equals(object other) { + var oth = other as DAST.TraitType_GeneralTrait; + 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.TraitType.GeneralTrait"; + return s; + } + } + public interface _IResolvedTypeBase { bool is_Class { get; } bool is_Datatype { get; } @@ -2339,6 +2322,7 @@ public interface _IResolvedTypeBase { bool is_SynonymType { get; } bool is_Newtype { get; } Dafny.ISequence dtor_variances { get; } + DAST._ITraitType dtor_traitType { get; } DAST._IType dtor_baseType { get; } DAST._INewtypeRange dtor_range { get; } bool dtor_erase { get; } @@ -2361,8 +2345,8 @@ public static _IResolvedTypeBase create_Class() { public static _IResolvedTypeBase create_Datatype(Dafny.ISequence variances) { return new ResolvedTypeBase_Datatype(variances); } - public static _IResolvedTypeBase create_Trait() { - return new ResolvedTypeBase_Trait(); + public static _IResolvedTypeBase create_Trait(DAST._ITraitType traitType) { + return new ResolvedTypeBase_Trait(traitType); } public static _IResolvedTypeBase create_SynonymType(DAST._IType baseType) { return new ResolvedTypeBase_SynonymType(baseType); @@ -2381,6 +2365,12 @@ public Dafny.ISequence dtor_variances { return ((ResolvedTypeBase_Datatype)d)._variances; } } + public DAST._ITraitType dtor_traitType { + get { + var d = this; + return ((ResolvedTypeBase_Trait)d)._traitType; + } + } public DAST._IType dtor_baseType { get { var d = this; @@ -2451,23 +2441,29 @@ public override string ToString() { } } public class ResolvedTypeBase_Trait : ResolvedTypeBase { - public ResolvedTypeBase_Trait() : base() { + public readonly DAST._ITraitType _traitType; + public ResolvedTypeBase_Trait(DAST._ITraitType traitType) : base() { + this._traitType = traitType; } public override _IResolvedTypeBase DowncastClone() { if (this is _IResolvedTypeBase dt) { return dt; } - return new ResolvedTypeBase_Trait(); + return new ResolvedTypeBase_Trait(_traitType); } public override bool Equals(object other) { var oth = other as DAST.ResolvedTypeBase_Trait; - return oth != null; + return oth != null && object.Equals(this._traitType, oth._traitType); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._traitType)); return (int) hash; } public override string ToString() { string s = "DAST.ResolvedTypeBase.Trait"; + s += "("; + s += Dafny.Helpers.ToString(this._traitType); + s += ")"; return s; } } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index f50e161fc1a..5085b997b7c 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -493,12 +493,12 @@ public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAss Dafny.ISequence> _8_fullPath; _8_fullPath = Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((t).dtor_name)); Dafny.ISequence _9_implBody; - Dafny.IMap>,Dafny.ISequence> _10___v5; + Dafny.IMap>,Dafny.ISequence> _10___v6; Dafny.ISequence _out3; Dafny.IMap>,Dafny.ISequence> _out4; - (this).GenClassImplBody((t).dtor_body, true, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_8_fullPath, Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Trait(), (t).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out3, out _out4); + (this).GenClassImplBody((t).dtor_body, true, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_8_fullPath, Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Trait(DAST.TraitType.create_ObjectTrait()), (t).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out3, out _out4); _9_implBody = _out3; - _10___v5 = _out4; + _10___v6 = _out4; Dafny.ISequence _11_parents; _11_parents = Dafny.Sequence.FromElements(); BigInteger _hi1 = new BigInteger(((t).dtor_parents).Count); @@ -562,15 +562,15 @@ public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAss DAST._IExpression _13_e; _13_e = DAST.Expression.create_Convert(_12_e, (c).dtor_base, _7_newtypeType); RAST._IExpr _14_r; - Defs._IOwnership _15___v6; - Dafny.ISet> _16___v7; + Defs._IOwnership _15___v7; + Dafny.ISet> _16___v8; RAST._IExpr _out5; Defs._IOwnership _out6; Dafny.ISet> _out7; (this).GenExpr(_13_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); _14_r = _out5; - _15___v6 = _out6; - _16___v7 = _out7; + _15___v7 = _out6; + _16___v8 = _out7; _11_fnBody = _14_r; } goto after_match0; @@ -595,14 +595,14 @@ public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAss DAST._IFormal _18_formal = value0.dtor_variable; Dafny.ISequence _19_constraintStmts = value0.dtor_constraintStmts; RAST._IExpr _20_rStmts; - Dafny.ISet> _21___v8; + Dafny.ISet> _21___v9; Defs._IEnvironment _22_newEnv; RAST._IExpr _out8; Dafny.ISet> _out9; Defs._IEnvironment _out10; (this).GenStmts(_19_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out8, out _out9, out _out10); _20_rStmts = _out8; - _21___v8 = _out9; + _21___v9 = _out9; _22_newEnv = _out10; Dafny.ISequence _23_rFormals; Dafny.ISequence _out11; @@ -670,25 +670,25 @@ public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAss DAST._IExpression _7_e = _source0.dtor_value; { RAST._IExpr _8_rStmts; - Dafny.ISet> _9___v9; + Dafny.ISet> _9___v10; Defs._IEnvironment _10_newEnv; RAST._IExpr _out5; Dafny.ISet> _out6; Defs._IEnvironment _out7; (this).GenStmts((c).dtor_witnessStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out5, out _out6, out _out7); _8_rStmts = _out5; - _9___v9 = _out6; + _9___v10 = _out6; _10_newEnv = _out7; RAST._IExpr _11_rExpr; - Defs._IOwnership _12___v10; - Dafny.ISet> _13___v11; + Defs._IOwnership _12___v11; + Dafny.ISet> _13___v12; RAST._IExpr _out8; Defs._IOwnership _out9; Dafny.ISet> _out10; (this).GenExpr(_7_e, Defs.SelfInfo.create_NoSelf(), _10_newEnv, Defs.Ownership.create_OwnershipOwned(), out _out8, out _out9, out _out10); _11_rExpr = _out8; - _12___v10 = _out9; - _13___v11 = _out10; + _12___v11 = _out9; + _13___v12 = _out10; Dafny.ISequence _14_constantName; _14_constantName = Defs.__default.escapeName(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_init_"), ((c).dtor_name))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_14_constantName, _6_defaultConstrainedTypeParams, Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_5_resultingType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((_8_rStmts).Then(_11_rExpr))))))); @@ -903,6 +903,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_23_selfPath, _0_typeParamsSeq, DAST.ResolvedTypeBase.create_Datatype(_6_variances), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out5, out _out6); _24_implBodyRaw = _out5; _25_traitBodies = _out6; + if ((new BigInteger((_25_traitBodies).Count)).Sign == 1) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("No support for trait in datatypes yet")); + } Dafny.ISequence _26_implBody; _26_implBody = _24_implBodyRaw; Dafny.ISet> _27_emittedFields; @@ -1015,7 +1018,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _53_types = Dafny.Sequence.Concat(_53_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_58_rTypeArg)))); if (((_54_typeI) < (new BigInteger((_6_variances).Count))) && (((_6_variances).Select(_54_typeI)).is_Nonvariant)) { _47_coerceTypes = Dafny.Sequence.Concat(_47_coerceTypes, Dafny.Sequence.FromElements(_58_rTypeArg)); - goto continue_2_0; + goto continue_3_0; } DAST._ITypeArgDecl _59_coerceTypeParam; DAST._ITypeArgDecl _60_dt__update__tmp_h0 = _55_typeParam; @@ -1040,9 +1043,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _65_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_54_typeI)); _52_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_52_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_58_rTypeArg, _64_rCoerceType), (RAST.Expr.create_Identifier(_65_coerceFormal)).Clone()))); _49_coerceArguments = Dafny.Sequence.Concat(_49_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_65_coerceFormal, RAST.__default.Rc(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_58_rTypeArg), _64_rCoerceType)), RAST.__default.StaticTrait))))); - continue_2_0: ; + continue_3_0: ; } - after_2_0: ; + after_3_0: ; if ((new BigInteger((_20_unusedTypeParams).Count)).Sign == 1) { _5_ctors = Dafny.Sequence.Concat(_5_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_66_tpe) => { return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _66_tpe); @@ -1327,15 +1330,31 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) } { if (_source1.is_Trait) { - { - if (((_0_resolved).dtor_path).Equals(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("_System"), Dafny.Sequence.UnicodeFromString("object")))) { - s = RAST.__default.AnyTrait; + DAST._ITraitType traitType0 = _source1.dtor_traitType; + if (traitType0.is_GeneralTrait) { + { + if (!((genTypeContext))) { + s = RAST.__default.Box(RAST.Type.create_DynType(s)); + } } - if (!((genTypeContext))) { - s = (this).Object(RAST.Type.create_DynType(s)); + goto after_match1; + } + } + } + { + if (_source1.is_Trait) { + DAST._ITraitType traitType1 = _source1.dtor_traitType; + if (traitType1.is_ObjectTrait) { + { + if (((_0_resolved).dtor_path).Equals(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("_System"), Dafny.Sequence.UnicodeFromString("object")))) { + s = RAST.__default.AnyTrait; + } + if (!((genTypeContext))) { + s = (this).Object(RAST.Type.create_DynType(s)); + } } + goto after_match1; } - goto after_match1; } } { @@ -1876,15 +1895,15 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e after_match1: ; _32_env = Defs.Environment.create(Dafny.Sequence>.Concat(_34_preAssignNames, _1_paramNames), Dafny.Map, RAST._IType>.Merge(_35_preAssignTypes, _2_paramTypes)); RAST._IExpr _48_body; - Dafny.ISet> _49___v20; - Defs._IEnvironment _50___v21; + Dafny.ISet> _49___v21; + Defs._IEnvironment _50___v22; RAST._IExpr _out6; Dafny.ISet> _out7; Defs._IEnvironment _out8; (this).GenStmts((m).dtor_body, _8_selfIdent, _32_env, true, _36_earlyReturn, out _out6, out _out7, out _out8); _48_body = _out6; - _49___v20 = _out7; - _50___v21 = _out8; + _49___v21 = _out7; + _50___v22 = _out8; _31_fBody = Std.Wrappers.Option.create_Some((_33_preBody).Then(_48_body)); } else { _32_env = Defs.Environment.create(_1_paramNames, _2_paramTypes); @@ -2111,14 +2130,14 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Defs._ISelfInfo BigInteger _hi0 = new BigInteger((_12_indices).Count); for (BigInteger _18_i = BigInteger.Zero; _18_i < _hi0; _18_i++) { RAST._IExpr _19_idx; - Defs._IOwnership _20___v30; + Defs._IOwnership _20___v31; Dafny.ISet> _21_recIdentsIdx; RAST._IExpr _out6; Defs._IOwnership _out7; Dafny.ISet> _out8; (this).GenExpr((_12_indices).Select(_18_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out6, out _out7, out _out8); _19_idx = _out6; - _20___v30 = _out7; + _20___v31 = _out7; _21_recIdentsIdx = _out8; Dafny.ISequence _22_varName; _22_varName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("__idx"), Std.Strings.__default.OfNat(_18_i)); @@ -2162,15 +2181,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _5_isAssignedVar = Defs.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { RAST._IExpr _6_rhs; - Defs._IOwnership _7___v31; - Dafny.ISet> _8___v32; + Defs._IOwnership _7___v32; + Dafny.ISet> _8___v33; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr(DAST.Expression.create_InitializationValue(((_2_field).dtor_formal).dtor_typ), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); _6_rhs = _out1; - _7___v31 = _out2; - _8___v32 = _out3; + _7___v32 = _out2; + _8___v33 = _out3; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); Dafny.ISequence _9_update__if__uninit; if ((_2_field).dtor_isConstant) { @@ -2263,14 +2282,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _23_expression = _source0.dtor_value; { RAST._IExpr _24_exprGen; - Defs._IOwnership _25___v33; + Defs._IOwnership _25___v34; Dafny.ISet> _26_exprIdents; RAST._IExpr _out11; Defs._IOwnership _out12; Dafny.ISet> _out13; (this).GenExpr(_23_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out11, out _out12, out _out13); _24_exprGen = _out11; - _25___v33 = _out12; + _25___v34 = _out12; _26_exprIdents = _out13; if ((_22_lhs).is_Ident) { Dafny.ISequence _27_rustId; @@ -2320,14 +2339,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _37_elsDafny = _source0.dtor_els; { RAST._IExpr _38_cond; - Defs._IOwnership _39___v34; + Defs._IOwnership _39___v35; Dafny.ISet> _40_recIdents; RAST._IExpr _out18; Defs._IOwnership _out19; Dafny.ISet> _out20; (this).GenExpr(_35_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out18, out _out19, out _out20); _38_cond = _out18; - _39___v34 = _out19; + _39___v35 = _out19; _40_recIdents = _out20; Dafny.ISequence _41_condString; _41_condString = (_38_cond)._ToString(Defs.__default.IND); @@ -2388,14 +2407,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _54_body = _source0.dtor_body; { RAST._IExpr _55_cond; - Defs._IOwnership _56___v35; + Defs._IOwnership _56___v36; Dafny.ISet> _57_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr(_53_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _55_cond = _out30; - _56___v35 = _out31; + _56___v36 = _out31; _57_recIdents = _out32; readIdents = _57_recIdents; RAST._IExpr _58_bodyExpr; @@ -2423,14 +2442,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _64_body = _source0.dtor_body; { RAST._IExpr _65_over; - Defs._IOwnership _66___v36; + Defs._IOwnership _66___v37; Dafny.ISet> _67_recIdents; RAST._IExpr _out36; Defs._IOwnership _out37; Dafny.ISet> _out38; (this).GenExpr(_63_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out36, out _out37, out _out38); _65_over = _out36; - _66___v36 = _out37; + _66___v37 = _out37; _67_recIdents = _out38; if (((_63_overExpr).is_MapBoundedPool) || ((_63_overExpr).is_SetBoundedPool)) { _65_over = ((_65_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); @@ -2494,15 +2513,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _76_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { RAST._IExpr _77_selfClone; - Defs._IOwnership _78___v37; - Dafny.ISet> _79___v38; + Defs._IOwnership _78___v38; + Dafny.ISet> _79___v39; RAST._IExpr _out43; Defs._IOwnership _out44; Dafny.ISet> _out45; (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out43, out _out44, out _out45); _77_selfClone = _out43; - _78___v37 = _out44; - _79___v38 = _out45; + _78___v38 = _out44; + _79___v39 = _out45; generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_77_selfClone))); if (((_76_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { _76_oldEnv = (_76_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); @@ -2522,15 +2541,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv goto continue_4_0; } RAST._IExpr _83_paramInit; - Defs._IOwnership _84___v39; - Dafny.ISet> _85___v40; + Defs._IOwnership _84___v40; + Dafny.ISet> _85___v41; RAST._IExpr _out46; Defs._IOwnership _out47; Dafny.ISet> _out48; (this).GenIdent(_82_param, selfIdent, _76_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out46, out _out47, out _out48); _83_paramInit = _out46; - _84___v39 = _out47; - _85___v40 = _out48; + _84___v40 = _out47; + _85___v41 = _out48; Dafny.ISequence _86_recVar; _86_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_81_paramI)); generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _86_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_83_paramInit))); @@ -2636,14 +2655,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { RAST._IExpr _108_onExpr; - Defs._IOwnership _109___v45; + Defs._IOwnership _109___v46; Dafny.ISet> _110_enclosingIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_91_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out64, out _out65, out _out66); _108_onExpr = _out64; - _109___v45 = _out65; + _109___v46 = _out65; _110_enclosingIdents = _out66; readIdents = Dafny.Set>.Union(readIdents, _110_enclosingIdents); Dafny.ISequence _111_renderedName; @@ -2733,14 +2752,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _121_exprDafny = _source0.dtor_expr; { RAST._IExpr _122_expr; - Defs._IOwnership _123___v55; + Defs._IOwnership _123___v56; Dafny.ISet> _124_recIdents; RAST._IExpr _out68; Defs._IOwnership _out69; Dafny.ISet> _out70; (this).GenExpr(_121_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out68, out _out69, out _out70); _122_expr = _out68; - _123___v55 = _out69; + _123___v56 = _out69; _124_recIdents = _out70; readIdents = _124_recIdents; if (isLast) { @@ -2770,15 +2789,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv BigInteger _hi3 = new BigInteger((_125_rustIdents).Count); for (BigInteger _127_i = BigInteger.Zero; _127_i < _hi3; _127_i++) { RAST._IExpr _128_rIdent; - Defs._IOwnership _129___v56; - Dafny.ISet> _130___v57; + Defs._IOwnership _129___v57; + Dafny.ISet> _130___v58; RAST._IExpr _out71; Defs._IOwnership _out72; Dafny.ISet> _out73; (this).GenIdent((_125_rustIdents).Select(_127_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out71, out _out72, out _out73); _128_rIdent = _out71; - _129___v56 = _out72; - _130___v57 = _out73; + _129___v57 = _out72; + _130___v58 = _out73; _126_tupleArgs = Dafny.Sequence.Concat(_126_tupleArgs, Dafny.Sequence.FromElements(_128_rIdent)); } if ((new BigInteger((_126_tupleArgs).Count)) == (BigInteger.One)) { @@ -3185,24 +3204,24 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ _10_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); } RAST._IExpr _11_left; - Defs._IOwnership _12___v58; + Defs._IOwnership _12___v59; Dafny.ISet> _13_recIdentsL; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(_4_lExpr, selfIdent, env, _9_expectedLeftOwnership, out _out0, out _out1, out _out2); _11_left = _out0; - _12___v58 = _out1; + _12___v59 = _out1; _13_recIdentsL = _out2; RAST._IExpr _14_right; - Defs._IOwnership _15___v59; + Defs._IOwnership _15___v60; Dafny.ISet> _16_recIdentsR; RAST._IExpr _out3; Defs._IOwnership _out4; Dafny.ISet> _out5; (this).GenExpr(_5_rExpr, selfIdent, env, _10_expectedRightOwnership, out _out3, out _out4, out _out5); _14_right = _out3; - _15___v59 = _out4; + _15___v60 = _out4; _16_recIdentsR = _out5; DAST._IBinOp _source0 = _0_op; { @@ -4186,14 +4205,14 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v71; + Defs._IOwnership _5___v72; Dafny.ISet> _6_argIdents; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); _4_argExpr = _out1; - _5___v71 = _out2; + _5___v72 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -4395,14 +4414,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi1 = new BigInteger((_9_values).Count); for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13___v81; + Defs._IOwnership _13___v82; Dafny.ISet> _14_recIdents; RAST._IExpr _out16; Defs._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); _12_recursiveGen = _out16; - _13___v81 = _out17; + _13___v82 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -4451,14 +4470,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi3 = new BigInteger((_17_args).Count); for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { RAST._IExpr _23_recursiveGen; - Defs._IOwnership _24___v82; + Defs._IOwnership _24___v83; Dafny.ISet> _25_recIdents; RAST._IExpr _out23; Defs._IOwnership _out24; Dafny.ISet> _out25; (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); _23_recursiveGen = _out23; - _24___v82 = _out24; + _24___v83 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -4496,14 +4515,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi4 = new BigInteger((_26_dims).Count); for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { RAST._IExpr _31_recursiveGen; - Defs._IOwnership _32___v83; + Defs._IOwnership _32___v84; Dafny.ISet> _33_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr((_26_dims).Select(_30_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _31_recursiveGen = _out30; - _32___v83 = _out31; + _32___v84 = _out31; _33_recIdents = _out32; _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); @@ -4530,14 +4549,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _35_underlying = _source0.dtor_value; { RAST._IExpr _36_recursiveGen; - Defs._IOwnership _37___v84; + Defs._IOwnership _37___v85; Dafny.ISet> _38_recIdents; RAST._IExpr _out35; Defs._IOwnership _out36; Dafny.ISet> _out37; (this).GenExpr(_35_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out35, out _out36, out _out37); _36_recursiveGen = _out35; - _37___v84 = _out36; + _37___v85 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -4560,14 +4579,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out40 = (this).GenType(_40_typ, Defs.GenTypeContext.@default()); _41_tpe = _out40; RAST._IExpr _42_recursiveGen; - Defs._IOwnership _43___v85; + Defs._IOwnership _43___v86; Dafny.ISet> _44_recIdents; RAST._IExpr _out41; Defs._IOwnership _out42; Dafny.ISet> _out43; (this).GenExpr(_39_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); _42_recursiveGen = _out41; - _43___v85 = _out42; + _43___v86 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -4633,14 +4652,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; if (_50_isCo) { RAST._IExpr _59_recursiveGen; - Defs._IOwnership _60___v86; + Defs._IOwnership _60___v87; Dafny.ISet> _61_recIdents; RAST._IExpr _out50; Defs._IOwnership _out51; Dafny.ISet> _out52; (this).GenExpr(_58_value, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); _59_recursiveGen = _out50; - _60___v86 = _out51; + _60___v87 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -4663,14 +4682,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _64_wasAssigned))); } else { RAST._IExpr _65_recursiveGen; - Defs._IOwnership _66___v87; + Defs._IOwnership _66___v88; Dafny.ISet> _67_recIdents; RAST._IExpr _out53; Defs._IOwnership _out54; Dafny.ISet> _out55; (this).GenExpr(_58_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out53, out _out54, out _out55); _65_recursiveGen = _out53; - _66___v87 = _out54; + _66___v88 = _out54; _67_recIdents = _out55; _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _65_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); @@ -4710,24 +4729,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _69_expr = _source0.dtor_elem; { RAST._IExpr _70_recursiveGen; - Defs._IOwnership _71___v91; + Defs._IOwnership _71___v92; Dafny.ISet> _72_recIdents; RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; (this).GenExpr(_69_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); _70_recursiveGen = _out61; - _71___v91 = _out62; + _71___v92 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v92; + Defs._IOwnership _74___v93; Dafny.ISet> _75_lengthIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_68_length, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); _73_lengthGen = _out64; - _74___v92 = _out65; + _74___v93 = _out65; _75_lengthIdents = _out66; r = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("_initializer"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_70_recursiveGen)); RAST._IExpr _76_range; @@ -4766,14 +4785,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _82_args = Dafny.Sequence.FromElements(); while ((_81_i) < (new BigInteger((_78_exprs).Count))) { RAST._IExpr _83_recursiveGen; - Defs._IOwnership _84___v93; + Defs._IOwnership _84___v94; Dafny.ISet> _85_recIdents; RAST._IExpr _out70; Defs._IOwnership _out71; Dafny.ISet> _out72; (this).GenExpr((_78_exprs).Select(_81_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out70, out _out71, out _out72); _83_recursiveGen = _out70; - _84___v93 = _out71; + _84___v94 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -4804,14 +4823,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _88_i = BigInteger.Zero; while ((_88_i) < (new BigInteger((_86_exprs).Count))) { RAST._IExpr _89_recursiveGen; - Defs._IOwnership _90___v94; + Defs._IOwnership _90___v95; Dafny.ISet> _91_recIdents; RAST._IExpr _out75; Defs._IOwnership _out76; Dafny.ISet> _out77; (this).GenExpr((_86_exprs).Select(_88_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out75, out _out76, out _out77); _89_recursiveGen = _out75; - _90___v94 = _out76; + _90___v95 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -4839,14 +4858,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _94_i = BigInteger.Zero; while ((_94_i) < (new BigInteger((_92_exprs).Count))) { RAST._IExpr _95_recursiveGen; - Defs._IOwnership _96___v95; + Defs._IOwnership _96___v96; Dafny.ISet> _97_recIdents; RAST._IExpr _out80; Defs._IOwnership _out81; Dafny.ISet> _out82; (this).GenExpr((_92_exprs).Select(_94_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out80, out _out81, out _out82); _95_recursiveGen = _out80; - _96___v95 = _out81; + _96___v96 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -4868,14 +4887,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _98_expr = _source0.dtor_ToMultiset_a0; { RAST._IExpr _99_recursiveGen; - Defs._IOwnership _100___v96; + Defs._IOwnership _100___v97; Dafny.ISet> _101_recIdents; RAST._IExpr _out85; Defs._IOwnership _out86; Dafny.ISet> _out87; (this).GenExpr(_98_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out85, out _out86, out _out87); _99_recursiveGen = _out85; - _100___v96 = _out86; + _100___v97 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -4900,24 +4919,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _104_i = BigInteger.Zero; while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v97; + Defs._IOwnership _106___v98; Dafny.ISet> _107_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); _105_recursiveGenKey = _out90; - _106___v97 = _out91; + _106___v98 = _out91; _107_recIdentsKey = _out92; RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v98; + Defs._IOwnership _109___v99; Dafny.ISet> _110_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); _108_recursiveGenValue = _out93; - _109___v98 = _out94; + _109___v99 = _out94; _110_recIdentsValue = _out95; _103_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_103_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_105_recursiveGenKey, _108_recursiveGenValue))); readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _107_recIdentsKey), _110_recIdentsValue); @@ -4952,14 +4971,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _116_value = _source0.dtor_value; { RAST._IExpr _117_exprR; - Defs._IOwnership _118___v99; + Defs._IOwnership _118___v100; Dafny.ISet> _119_exprIdents; RAST._IExpr _out98; Defs._IOwnership _out99; Dafny.ISet> _out100; (this).GenExpr(_114_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out98, out _out99, out _out100); _117_exprR = _out98; - _118___v99 = _out99; + _118___v100 = _out99; _119_exprIdents = _out100; RAST._IExpr _120_indexR; Defs._IOwnership _121_indexOwnership; @@ -5000,14 +5019,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _128_value = _source0.dtor_value; { RAST._IExpr _129_exprR; - Defs._IOwnership _130___v100; + Defs._IOwnership _130___v101; Dafny.ISet> _131_exprIdents; RAST._IExpr _out109; Defs._IOwnership _out110; Dafny.ISet> _out111; (this).GenExpr(_126_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out109, out _out110, out _out111); _129_exprR = _out109; - _130___v100 = _out110; + _130___v101 = _out110; _131_exprIdents = _out111; RAST._IExpr _132_indexR; Defs._IOwnership _133_indexOwnership; @@ -5088,14 +5107,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _143_f = _source0.dtor_els; { RAST._IExpr _144_cond; - Defs._IOwnership _145___v101; + Defs._IOwnership _145___v102; Dafny.ISet> _146_recIdentsCond; RAST._IExpr _out126; Defs._IOwnership _out127; Dafny.ISet> _out128; (this).GenExpr(_141_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out126, out _out127, out _out128); _144_cond = _out126; - _145___v101 = _out127; + _145___v102 = _out127; _146_recIdentsCond = _out128; RAST._IExpr _147_fExpr; Defs._IOwnership _148_fOwned; @@ -5108,14 +5127,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _148_fOwned = _out130; _149_recIdentsF = _out131; RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v102; + Defs._IOwnership _151___v103; Dafny.ISet> _152_recIdentsT; RAST._IExpr _out132; Defs._IOwnership _out133; Dafny.ISet> _out134; (this).GenExpr(_142_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); _150_tExpr = _out132; - _151___v102 = _out133; + _151___v103 = _out133; _152_recIdentsT = _out134; r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); RAST._IExpr _out135; @@ -5137,14 +5156,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; { RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v103; + Defs._IOwnership _156___v104; Dafny.ISet> _157_recIdents; RAST._IExpr _out137; Defs._IOwnership _out138; Dafny.ISet> _out139; (this).GenExpr(_153_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out137, out _out138, out _out139); _155_recursiveGen = _out137; - _156___v103 = _out138; + _156___v104 = _out138; _157_recIdents = _out139; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); RAST._IExpr _out140; @@ -5167,14 +5186,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; { RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v104; + Defs._IOwnership _161___v105; Dafny.ISet> _162_recIdents; RAST._IExpr _out142; Defs._IOwnership _out143; Dafny.ISet> _out144; (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out142, out _out143, out _out144); _160_recursiveGen = _out142; - _161___v104 = _out143; + _161___v105 = _out143; _162_recIdents = _out144; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); RAST._IExpr _out145; @@ -5239,14 +5258,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _171_native = _source0.dtor_native; { RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v109; + Defs._IOwnership _173___v110; Dafny.ISet> _174_recIdents; RAST._IExpr _out155; Defs._IOwnership _out156; Dafny.ISet> _out157; (this).GenExpr(_168_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out155, out _out156, out _out157); _172_recursiveGen = _out155; - _173___v109 = _out156; + _173___v110 = _out156; _174_recIdents = _out157; RAST._IType _175_arrayType; RAST._IType _out158; @@ -5288,14 +5307,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _177_expr = _source0.dtor_expr; { RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v110; + Defs._IOwnership _179___v111; Dafny.ISet> _180_recIdents; RAST._IExpr _out162; Defs._IOwnership _out163; Dafny.ISet> _out164; (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); _178_recursiveGen = _out162; - _179___v110 = _out163; + _179___v111 = _out163; _180_recIdents = _out164; readIdents = _180_recIdents; r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); @@ -5314,14 +5333,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _181_expr = _source0.dtor_expr; { RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v111; + Defs._IOwnership _183___v112; Dafny.ISet> _184_recIdents; RAST._IExpr _out167; Defs._IOwnership _out168; Dafny.ISet> _out169; (this).GenExpr(_181_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); _182_recursiveGen = _out167; - _183___v111 = _out168; + _183___v112 = _out168; _184_recIdents = _out169; readIdents = _184_recIdents; r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); @@ -5340,14 +5359,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _185_expr = _source0.dtor_expr; { RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v112; + Defs._IOwnership _187___v113; Dafny.ISet> _188_recIdents; RAST._IExpr _out172; Defs._IOwnership _out173; Dafny.ISet> _out174; (this).GenExpr(_185_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out172, out _out173, out _out174); _186_recursiveGen = _out172; - _187___v112 = _out173; + _187___v113 = _out173; _188_recIdents = _out174; readIdents = _188_recIdents; r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); @@ -5419,15 +5438,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _209_name = _let_tmp_rhs1.dtor__0; RAST._IType _210_ty = _let_tmp_rhs1.dtor__1; RAST._IExpr _211_rIdent; - Defs._IOwnership _212___v113; - Dafny.ISet> _213___v114; + Defs._IOwnership _212___v114; + Dafny.ISet> _213___v115; RAST._IExpr _out181; Defs._IOwnership _out182; Dafny.ISet> _out183; (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((!(_193_isConstant)) && ((_210_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); _211_rIdent = _out181; - _212___v113 = _out182; - _213___v114 = _out183; + _212___v114 = _out182; + _213___v115 = _out183; _207_onExprArgs = Dafny.Sequence.Concat(_207_onExprArgs, Dafny.Sequence.FromElements(_211_rIdent)); } _206_body = (_206_body).Apply(_207_onExprArgs); @@ -5718,14 +5737,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _258_l = _source5.dtor_value; { RAST._IExpr _259_lExpr; - Defs._IOwnership _260___v117; + Defs._IOwnership _260___v118; Dafny.ISet> _261_recIdentsL; RAST._IExpr _out217; Defs._IOwnership _out218; Dafny.ISet> _out219; (this).GenExpr(_258_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out217, out _out218, out _out219); _259_lExpr = _out217; - _260___v117 = _out218; + _260___v118 = _out218; _261_recIdentsL = _out219; _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_259_lExpr)); readIdents = Dafny.Set>.Union(readIdents, _261_recIdentsL); @@ -5742,14 +5761,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _262_h = _source6.dtor_value; { RAST._IExpr _263_hExpr; - Defs._IOwnership _264___v118; + Defs._IOwnership _264___v119; Dafny.ISet> _265_recIdentsH; RAST._IExpr _out220; Defs._IOwnership _out221; Dafny.ISet> _out222; (this).GenExpr(_262_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out220, out _out221, out _out222); _263_hExpr = _out220; - _264___v118 = _out221; + _264___v119 = _out221; _265_recIdentsH = _out222; _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_263_hExpr)); readIdents = Dafny.Set>.Union(readIdents, _265_recIdentsH); @@ -5902,14 +5921,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { RAST._IExpr _291_onExpr; - Defs._IOwnership _292___v124; + Defs._IOwnership _292___v125; Dafny.ISet> _293_recIdents; RAST._IExpr _out244; Defs._IOwnership _out245; Dafny.ISet> _out246; (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out244, out _out245, out _out246); _291_onExpr = _out244; - _292___v124 = _out245; + _292___v125 = _out245; _293_recIdents = _out246; readIdents = Dafny.Set>.Union(readIdents, _293_recIdents); Dafny.ISequence _294_renderedName; @@ -5996,14 +6015,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _305_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_301_paramNames, _302_paramTypesMap)); RAST._IExpr _306_recursiveGen; Dafny.ISet> _307_recIdents; - Defs._IEnvironment _308___v134; + Defs._IEnvironment _308___v135; RAST._IExpr _out251; Dafny.ISet> _out252; Defs._IEnvironment _out253; (this).GenStmts(_299_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _305_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out251, out _out252, out _out253); _306_recursiveGen = _out251; _307_recIdents = _out252; - _308___v134 = _out253; + _308___v135 = _out253; readIdents = Dafny.Set>.FromElements(); _307_recIdents = Dafny.Set>.Difference(_307_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_309_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); @@ -6029,15 +6048,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir after__ASSIGN_SUCH_THAT_1: ; if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_312_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { RAST._IExpr _313_selfCloned; - Defs._IOwnership _314___v135; - Dafny.ISet> _315___v136; + Defs._IOwnership _314___v136; + Dafny.ISet> _315___v137; RAST._IExpr _out254; Defs._IOwnership _out255; Dafny.ISet> _out256; (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out254, out _out255, out _out256); _313_selfCloned = _out254; - _314___v135 = _out255; - _315___v136 = _out256; + _314___v136 = _out255; + _315___v137 = _out256; _311_allReadCloned = (_311_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_313_selfCloned))); } else if (!((_301_paramNames).Contains(_312_next))) { RAST._IExpr _316_copy; @@ -6099,14 +6118,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out261 = (this).GenType((((_318_values).Select(_329_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); _330_typeGen = _out261; RAST._IExpr _331_valueGen; - Defs._IOwnership _332___v137; + Defs._IOwnership _332___v138; Dafny.ISet> _333_recIdents; RAST._IExpr _out262; Defs._IOwnership _out263; Dafny.ISet> _out264; (this).GenExpr(((_318_values).Select(_329_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out262, out _out263, out _out264); _331_valueGen = _out262; - _332___v137 = _out263; + _332___v138 = _out263; _333_recIdents = _out264; r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_318_values).Select(_329_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_330_typeGen), Std.Wrappers.Option.create_Some(_331_valueGen))); readIdents = Dafny.Set>.Union(readIdents, _333_recIdents); @@ -6143,14 +6162,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _341_iifeBody = _source0.dtor_iifeBody; { RAST._IExpr _342_valueGen; - Defs._IOwnership _343___v138; + Defs._IOwnership _343___v139; Dafny.ISet> _344_recIdents; RAST._IExpr _out270; Defs._IOwnership _out271; Dafny.ISet> _out272; (this).GenExpr(_340_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out270, out _out271, out _out272); _342_valueGen = _out270; - _343___v138 = _out271; + _343___v139 = _out271; _344_recIdents = _out272; readIdents = _344_recIdents; RAST._IType _345_valueTypeGen; @@ -6160,14 +6179,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _346_iifeVar; _346_iifeVar = Defs.__default.escapeVar(_338_name); RAST._IExpr _347_bodyGen; - Defs._IOwnership _348___v139; + Defs._IOwnership _348___v140; Dafny.ISet> _349_bodyIdents; RAST._IExpr _out274; Defs._IOwnership _out275; Dafny.ISet> _out276; (this).GenExpr(_341_iifeBody, selfIdent, (env).AddAssigned(_346_iifeVar, _345_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out274, out _out275, out _out276); _347_bodyGen = _out274; - _348___v139 = _out275; + _348___v140 = _out275; _349_bodyIdents = _out276; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_349_bodyIdents, Dafny.Set>.FromElements(_346_iifeVar))); r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _346_iifeVar, Std.Wrappers.Option.create_Some(_345_valueTypeGen), Std.Wrappers.Option.create_Some(_342_valueGen))).Then(_347_bodyGen)); @@ -6187,14 +6206,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _351_args = _source0.dtor_args; { RAST._IExpr _352_funcExpr; - Defs._IOwnership _353___v140; + Defs._IOwnership _353___v141; Dafny.ISet> _354_recIdents; RAST._IExpr _out279; Defs._IOwnership _out280; Dafny.ISet> _out281; (this).GenExpr(_350_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out279, out _out280, out _out281); _352_funcExpr = _out279; - _353___v140 = _out280; + _353___v141 = _out280; _354_recIdents = _out281; readIdents = _354_recIdents; Dafny.ISequence _355_rArgs; @@ -6232,14 +6251,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _362_variant = _source0.dtor_variant; { RAST._IExpr _363_exprGen; - Defs._IOwnership _364___v141; + Defs._IOwnership _364___v142; Dafny.ISet> _365_recIdents; RAST._IExpr _out287; Defs._IOwnership _out288; Dafny.ISet> _out289; (this).GenExpr(_360_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out287, out _out288, out _out289); _363_exprGen = _out287; - _364___v141 = _out288; + _364___v142 = _out288; _365_recIdents = _out289; RAST._IExpr _366_variantExprPath; RAST._IExpr _out290; @@ -6320,14 +6339,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _375_of = _source0.dtor_of; { RAST._IExpr _376_exprGen; - Defs._IOwnership _377___v142; + Defs._IOwnership _377___v143; Dafny.ISet> _378_recIdents; RAST._IExpr _out303; Defs._IOwnership _out304; Dafny.ISet> _out305; (this).GenExpr(_375_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out303, out _out304, out _out305); _376_exprGen = _out303; - _377___v142 = _out304; + _377___v143 = _out304; _378_recIdents = _out305; r = ((_376_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out306; @@ -6347,14 +6366,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _380_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _381_exprGen; - Defs._IOwnership _382___v143; + Defs._IOwnership _382___v144; Dafny.ISet> _383_recIdents; RAST._IExpr _out308; Defs._IOwnership _out309; Dafny.ISet> _out310; (this).GenExpr(_379_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out308, out _out309, out _out310); _381_exprGen = _out308; - _382___v143 = _out309; + _382___v144 = _out309; _383_recIdents = _out310; r = ((_381_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_380_includeDuplicates)) { @@ -6377,14 +6396,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _385_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _386_exprGen; - Defs._IOwnership _387___v144; + Defs._IOwnership _387___v145; Dafny.ISet> _388_recIdents; RAST._IExpr _out313; Defs._IOwnership _out314; Dafny.ISet> _out315; (this).GenExpr(_384_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out313, out _out314, out _out315); _386_exprGen = _out313; - _387___v144 = _out314; + _387___v145 = _out314; _388_recIdents = _out315; r = ((_386_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_385_includeDuplicates)) { @@ -6406,14 +6425,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _389_of = _source0.dtor_of; { RAST._IExpr _390_exprGen; - Defs._IOwnership _391___v145; + Defs._IOwnership _391___v146; Dafny.ISet> _392_recIdents; RAST._IExpr _out318; Defs._IOwnership _out319; Dafny.ISet> _out320; (this).GenExpr(_389_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out318, out _out319, out _out320); _390_exprGen = _out318; - _391___v145 = _out319; + _391___v146 = _out319; _392_recIdents = _out320; r = ((((_390_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); readIdents = _392_recIdents; @@ -6431,14 +6450,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _393_of = _source0.dtor_of; { RAST._IExpr _394_exprGen; - Defs._IOwnership _395___v146; + Defs._IOwnership _395___v147; Dafny.ISet> _396_recIdents; RAST._IExpr _out323; Defs._IOwnership _out324; Dafny.ISet> _out325; (this).GenExpr(_393_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out323, out _out324, out _out325); _394_exprGen = _out323; - _395___v146 = _out324; + _395___v147 = _out324; _396_recIdents = _out325; r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_394_exprGen); readIdents = _396_recIdents; @@ -6459,24 +6478,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _400_up = _source0.dtor_up; { RAST._IExpr _401_lo; - Defs._IOwnership _402___v147; + Defs._IOwnership _402___v148; Dafny.ISet> _403_recIdentsLo; RAST._IExpr _out328; Defs._IOwnership _out329; Dafny.ISet> _out330; (this).GenExpr(_398_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out328, out _out329, out _out330); _401_lo = _out328; - _402___v147 = _out329; + _402___v148 = _out329; _403_recIdentsLo = _out330; RAST._IExpr _404_hi; - Defs._IOwnership _405___v148; + Defs._IOwnership _405___v149; Dafny.ISet> _406_recIdentsHi; RAST._IExpr _out331; Defs._IOwnership _out332; Dafny.ISet> _out333; (this).GenExpr(_399_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out331, out _out332, out _out333); _404_hi = _out331; - _405___v148 = _out332; + _405___v149 = _out332; _406_recIdentsHi = _out333; if (_400_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_401_lo, _404_hi)); @@ -6507,14 +6526,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _409_up = _source0.dtor_up; { RAST._IExpr _410_start; - Defs._IOwnership _411___v149; + Defs._IOwnership _411___v150; Dafny.ISet> _412_recIdentStart; RAST._IExpr _out337; Defs._IOwnership _out338; Dafny.ISet> _out339; (this).GenExpr(_408_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); _410_start = _out337; - _411___v149 = _out338; + _411___v150 = _out338; _412_recIdentStart = _out339; if (_409_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_410_start); @@ -6588,14 +6607,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out349 = (this).GenType(_419_elemType, Defs.GenTypeContext.@default()); _423_tpe = _out349; RAST._IExpr _424_collectionGen; - Defs._IOwnership _425___v150; + Defs._IOwnership _425___v151; Dafny.ISet> _426_recIdents; RAST._IExpr _out350; Defs._IOwnership _out351; Dafny.ISet> _out352; (this).GenExpr(_420_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out350, out _out351, out _out352); _424_collectionGen = _out350; - _425___v150 = _out351; + _425___v151 = _out351; _426_recIdents = _out352; Dafny.ISequence _427_extraAttributes; _427_extraAttributes = Dafny.Sequence.FromElements(); @@ -6618,14 +6637,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _435_dt__update_hparams_h0 = _429_newFormals; _433_newLambda = DAST.Expression.create_Lambda(_435_dt__update_hparams_h0, (_434_dt__update__tmp_h1).dtor_retType, (_434_dt__update__tmp_h1).dtor_body); RAST._IExpr _436_lambdaGen; - Defs._IOwnership _437___v151; + Defs._IOwnership _437___v152; Dafny.ISet> _438_recLambdaIdents; RAST._IExpr _out353; Defs._IOwnership _out354; Dafny.ISet> _out355; (this).GenExpr(_433_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out353, out _out354, out _out355); _436_lambdaGen = _out353; - _437___v151 = _out354; + _437___v152 = _out354; _438_recLambdaIdents = _out355; Dafny.ISequence _439_fn; if (_421_is__forall) { @@ -6732,15 +6751,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v152; - Dafny.ISet> _2___v153; + Defs._IOwnership _1___v153; + Dafny.ISet> _2___v154; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v152 = _out1; - _2___v153 = _out2; + _1___v153 = _out1; + _2___v154 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index dc2e4082403..a1ae7ab380d 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -3893,6 +3893,17 @@ pub fn upcast() -> Rc) -> Ptr> Rc::new(|x: Ptr| read!(x).upcast()) } +pub fn upcast_box() -> Rc Box> + where A: UpcastBox +{ + Rc::new(|x: A| UpcastBox::upcast(&x)) +} +pub fn upcast_box_box() -> Rc) -> Box> + where Box: UpcastBox +{ + Rc::new(|x: Box| UpcastBox::upcast(&x)) +} + pub fn upcast_id() -> Rc A> { Rc::new(|x: A| x) @@ -3923,7 +3934,6 @@ pub trait Upcast { pub trait UpcastObject { fn upcast(&self) -> Object; } - impl Upcast for T { fn upcast(&self) -> Ptr { Ptr::from_raw_nonnull(self as *const T as *mut T) @@ -3935,6 +3945,12 @@ impl UpcastObject for T { } } +// For general traits +pub trait UpcastBox { + fn upcast(&self) -> Box; +} + + #[macro_export] macro_rules! Extends { ($traitType: tt) => { diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index d287da43dde..417c191c73f 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -922,4 +922,99 @@ mod tests { let resulting_message = format!("{:?}", object_any); assert_eq!(resulting_message, message); } + + // Every general trait must declare how to clone a Box of itself + trait GeneralTraitSuper { + fn _clone(&self) -> Box; + fn _is_GeneralTrait(&self) -> bool; + fn _as_GeneralTrait(&self) -> Box; + fn _is_Datatype(&self) -> bool; + fn _as_Datatype(&self) -> ADatatype; + } + impl Clone for Box { + fn clone(&self) -> Self { + GeneralTraitSuper::_clone(self.as_ref()) + } + } + // Traits extending other traits also implement a direct way to upcast their Box of themselves + trait GeneralTrait: GeneralTraitSuper + UpcastBox { + fn _clone(&self) -> Box; + } + impl UpcastBox for Box { + fn upcast(&self) -> Box { + GeneralTraitSuper::_clone(self.as_ref()) + } + } + impl Clone for Box { + fn clone(&self) -> Self { + GeneralTrait::_clone(self.as_ref()) + } + } + + #[derive(Clone, PartialEq, Debug)] + struct ADatatype{i: i32} + impl GeneralTrait for ADatatype { + fn _clone(&self) -> Box { + Box::new(self.clone()) as Box + } + } + impl GeneralTraitSuper for ADatatype { + fn _clone(&self) -> Box { + Box::new(self.clone()) + } + + fn _is_GeneralTrait(&self) -> bool { + true + } + + fn _as_GeneralTrait(&self) -> Box { + GeneralTrait::_clone(self) + } + + fn _is_Datatype(&self) -> bool { + true + } + + fn _as_Datatype(&self) -> ADatatype { + self.clone() + } + } + impl UpcastBox for ADatatype { + fn upcast(&self) -> Box { + GeneralTrait::_clone(self) + } + } + impl UpcastBox for ADatatype { + fn upcast(&self) -> Box { + GeneralTraitSuper::_clone(self) + } + } + #[test] + fn test_general_traits() { + let x = ADatatype{i: 3}; + let gt = upcast_box::()(x.clone()); + let gts = upcast_box::()(x.clone()); + let gtgts = upcast_box_box::()(gt.clone()); + assert!(gt._is_Datatype()); + assert!(gts._is_Datatype()); + assert!(gtgts._is_Datatype()); + assert!(gts._is_GeneralTrait()); + assert!(gtgts._is_GeneralTrait()); + assert_eq!(gt._as_Datatype(), x); + assert_eq!(gts._as_Datatype(), x); + assert_eq!(gtgts._as_Datatype(), x); + let gtsgt = gts._as_GeneralTrait(); + let gtgtsgt = gtgts._as_GeneralTrait(); + assert!(gtsgt._is_Datatype()); + assert!(gtgtsgt._is_Datatype()); + assert_eq!(gtsgt._as_Datatype(), x); + assert_eq!(gtsgt._as_Datatype(), x); + } + /*impl GeneralTrait for Rc { + fn _clone(&self) -> Box { + Box::new(self.as_ref().clone()) + } + }*/ + + } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy new file mode 100644 index 00000000000..a821d081ae6 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy @@ -0,0 +1,40 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --type-system-refresh --general-traits=datatype "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait DatatypeOps { + function GetInt(): int + function GetBool(): bool { + GetInt() % 2 == 0 + } + function ChooseAmong(a: T, b: T): T { + if GetBool() then a else b + } +} + +datatype ADatatype extends DatatypeOps = ADatatype(i: int) { + function AsDatatypeOps(): DatatypeOps { + this as DatatypeOps + } + function GetInt(): int { i } +} + +method Main() { + var x := ADatatype(2); + expect x.GetInt() == 2; + expect x.GetBool() == true; + expect x.ChooseAmong(8, 9) == 8; + var y := ADatatype(3); + expect y.GetInt() == 3; + expect y.GetBool() == false; + expect x.ChooseAmong(8, 9) == 9; + var x1 := x.AsDatatypeOps(); // Dynamic dispatch now. + expect x1.GetInt() == 2; + expect x1.GetBool() == true; + expect x1.ChooseAmong(8, 9) == 8; + var y1 := y.AsDatatypeOps(); + expect y1.GetInt() == 3; + expect y1.GetBool() == false; + expect y1.ChooseAmong(8, 9) == 9; + print "Main passed all the tests"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect new file mode 100644 index 00000000000..2123d1f24c3 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 20 verified, 0 errors +Main passed all the tests From 56fe9f91847302b9713a1f74153f8c959b4ac12e Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 22 Nov 2024 08:43:56 -0600 Subject: [PATCH 02/69] WIP --- Source/DafnyCore/Backends/Dafny/AST.dfy | 16 ++++++- .../Rust/Dafny-compiler-rust-rast.dfy | 30 ++++++------- .../Backends/Rust/Dafny-compiler-rust.dfy | 45 ++++++++++++++----- .../DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 16 +++++++ .../DafnyRuntimeRust/src/tests/mod.rs | 12 ++--- 5 files changed, 82 insertions(+), 37 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 0e5f3c249c1..160c486ede7 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -124,6 +124,18 @@ module {:extern "DAST"} DAST { case _ => false } } + + predicat IsGeneralTrait() { + match this { + case UserDefined(ResolvedType(_, _, typeKind, _, _, _)) => + match typeKind { + case SynonymType(typ) => + typ.IsGeneralTrait() + case TraitType(GeneralTrait) => true + case _ => false + case _ => false + } + } } datatype Variance = @@ -206,7 +218,7 @@ module {:extern "DAST"} DAST { datatype Ident = Ident(id: Name) - datatype Class = Class(name: Name, enclosingModule: Ident, typeParams: seq, superClasses: seq, fields: seq, body: seq, attributes: seq) + datatype Class = Class(name: Name, enclosingModule: Ident, typeParams: seq, superTraitTypes: seq, fields: seq, body: seq, attributes: seq) datatype Trait = Trait( name: Name, @@ -216,7 +228,7 @@ module {:extern "DAST"} DAST { body: seq, attributes: seq) - datatype Datatype = Datatype(name: Name, enclosingModule: Ident, typeParams: seq, ctors: seq, body: seq, isCo: bool, attributes: seq) + datatype Datatype = Datatype(name: Name, enclosingModule: Ident, typeParams: seq, ctors: seq, body: seq, isCo: bool, attributes: seq, superTraitTypes: seq) datatype DatatypeDtor = DatatypeDtor(formal: Formal, callName: Option) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index 2f7b3f5e647..89ab9c645c8 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -631,21 +631,6 @@ module RAST function BoxNew(content: Expr): Expr { BoxPath.AsExpr().FSel("new").Apply([content]) } - predicate IsBox() { - match this { - case TypeApp(TypeFromPath(o), elems1) => - o == BoxPath && |elems1| == 1 - case _ => false - } - } - function BoxUnderlying(): Type - requires IsBox() - { - match this { - case TypeApp(TypeFromPath(o), elems1) => - elems1[0] - } - } datatype Path = | Global() // ::... to access other crates @@ -969,6 +954,21 @@ module RAST false else false + } + predicate IsBox() { + match this { + case TypeApp(TypeFromPath(o), elems1) => + o == BoxPath && |elems1| == 1 + case _ => false + } + } + function BoxUnderlying(): Type + requires IsBox() + { + match this { + case TypeApp(TypeFromPath(o), elems1) => + elems1[0] + } } predicate IsObject() { match this { diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index c3fcd3a7cda..78c2d3afc28 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -372,10 +372,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ) ]; } - var superClasses := if className == "_default" then [] else c.superClasses; - for i := 0 to |superClasses| { - var superClass := superClasses[i]; - match superClass { + var superTraitTypes := if className == "_default" then [] else c.superTraitTypes; + for i := 0 to |superTraitTypes| { + var superTraitType := superTraitTypes[i]; + match superTraitType { case UserDefined(ResolvedType(traitPath, typeArgs, Trait(traitType), _, properMethods, _)) => { var pathStr := GenPathType(traitPath); var typeArgs := GenTypeArgs(typeArgs, GenTypeContext.default()); @@ -468,7 +468,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var fullPath := containingPath + [Ident.Ident(t.name)]; - var traitFulltype := R.TypeApp(R.TIdentifier(escapeName(t.name)), typeParams); + var name := escapeName(t.name); + var traitFulltype := R.TypeApp(R.TIdentifier(name), typeParams); + var traitFullExpr := R.ApplyType(R.Identifier(name), typeParams); var implBody, _ := GenClassImplBody( t.body, true, UserDefined( @@ -486,13 +488,33 @@ module {:extern "DCOMP"} DafnyToRustCompiler { "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(traitFulltype))), "", None - )); + )) ]; } var parents := []; + var upcastImplemented := []; for i := 0 to |t.parents| { - var tpe := GenType(t.parents[i], GenTypeContext.ForTraitParents()); - parents := parents + [tpe] + [R.dafny_runtime.MSel(Upcast).AsType().Apply1(R.DynType(tpe))]; + var parentTpe := GenType(t.parents[i], GenTypeContext.ForTraitParents()); + parents := parents + [parentTpe]; + var upcastTrait := if parentTpe.IsGeneralTrait() then "UpcastBox" else Upcast; + parents := parents + [R.dafny_runtime.MSel(upcastTrait).AsType().Apply1(R.DynType(parentTpe))]; + if parentTpe.IsGeneralTrait() { + /*impl UpcastBox for Box { + UpcastBoxFn!(GeneralTraitSuper); + }*/ + upcastImplemented := upcastImplemented + [ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.dafny_runtime.MSel("UpcastBox").AsType().Apply1(R.DynType(parentTpe)), + R.Box(R.DynType(traitFulltype)), + "", + [ R.ImplMemberMacro( + R.dafny_runtime + .MSel("UpcastBoxFn").AsExpr() + .Apply1(R.ExprFromType(tpe)))])) + ]; + } } s := [ R.TraitDecl( @@ -504,7 +526,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if t.traitType.GeneralTrait? { /*impl Clone for Box { fn clone(&self) -> Box { - self._clone() + Test::_clone(self.as_ref()) } }*/ s := s + [ @@ -520,9 +542,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { [ R.Formal.selfBorrowed ], Some(R.SelfOwned), "", - Some(R.self.FSel("_clone").Apply0()) - )]))]; + Some(traitFullExpr.FSel("_clone").Apply1(R.self.Sel("as_ref").Apply0())) + ))]))]; } + s := s + upcastImplemented; } method GenNewtype(c: Newtype, path: seq) returns (s: seq) diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index a1ae7ab380d..6db6d689b4a 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -3977,6 +3977,22 @@ macro_rules! UpcastObjectFn { } +#[macro_export] +macro_rules! UpcastBoxFn { + ($B:ident) => { + fn upcast(&self) -> ::std::boxed::Box { + $B::_clone(self.as_ref()) + } + }; +} +#[macro_export] +macro_rules! UpcastStructBoxFn { + ($B:ident) => { + fn upcast(&self) -> ::std::boxed::Box { + $B::_clone(self) + } + }; +} // It works only when there is no type parameters for $A... #[macro_export] diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index 417c191c73f..bd850940788 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -941,9 +941,7 @@ mod tests { fn _clone(&self) -> Box; } impl UpcastBox for Box { - fn upcast(&self) -> Box { - GeneralTraitSuper::_clone(self.as_ref()) - } + UpcastBoxFn!(GeneralTraitSuper); } impl Clone for Box { fn clone(&self) -> Self { @@ -980,14 +978,10 @@ mod tests { } } impl UpcastBox for ADatatype { - fn upcast(&self) -> Box { - GeneralTrait::_clone(self) - } + UpcastStructBoxFn!(GeneralTrait); } impl UpcastBox for ADatatype { - fn upcast(&self) -> Box { - GeneralTraitSuper::_clone(self) - } + UpcastStructBoxFn!(GeneralTraitSuper); } #[test] fn test_general_traits() { From ab10000dd61e2a4998947ed6e2802bf4f2c85264 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 22 Nov 2024 08:44:48 -0600 Subject: [PATCH 03/69] WIP --- .../Backends/Rust/Dafny-compiler-rust.dfy | 79 ++++++++++++++++++- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 78c2d3afc28..1f675bceb53 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -875,9 +875,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ResolvedTypeBase.Datatype(variances), c.attributes, [], [])), typeParamsSeq); - if |traitBodies| > 0 { - error := Some("No support for trait in datatypes yet"); - } var implBody: seq := implBodyRaw; var emittedFields: set := {}; for i := 0 to |c.ctors| { @@ -1256,6 +1253,82 @@ module {:extern "DCOMP"} DafnyToRustCompiler { )] ))]; } + var superTraitTypes := c.superTraitTypes; + for i := 0 to |superTraitTypes| { + var superTraitType := superTraitTypes[i]; + match superTraitType { + case UserDefined(ResolvedType(traitPath, typeArgs, Trait(traitType), _, properMethods, _)) => { + var pathStr := GenPathType(traitPath); + var typeArgs := GenTypeArgs(typeArgs, GenTypeContext.default()); + var body: seq := []; + if traitPath in traitBodies { + body := traitBodies[traitPath]; + } + + var fullTraitPath := R.TypeApp(pathStr, typeArgs); + if !extern.NoExtern? { // An extern of some kind + // Either the Dafny code implements all the methods of the trait or none, + if |body| == 0 && |properMethods| != 0 { + continue; // We assume everything is implemented externally + } + if |body| != |properMethods| { + error := Some("Error: In the class " + R.SeqToString(path, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + + fullTraitPath.ToString("") + " are marked {:extern} and some are not." + + " For the Rust compiler, please make all methods (" + R.SeqToString(properMethods, (s: Name) => s.dafny_name, ", ") + + ") bodiless and mark as {:extern} and implement them in a Rust file, "+ + "or mark none of them as {:extern} and implement them in Dafny. " + + "Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible."); + } + } + if |body| == 0 { + // Extern type, we assume + } + if traitType.GeneralTrait? { + // One more method: Cloning when boxed + /*impl Test for Wrapper { + fn _clone(&self) -> Box { + Box::new(self.clone()) + } + }*/ + body := body + [ + R.FnDecl( + R.PRIV, + R.Fn( + "_clone", [], [R.Formal.selfBorrowed], R.Boxed(R.DynType(fullTraitPath)), + "", + Some(R.BoxNew(R.self.MSel("clone").Apply0())))) + ]; + } + var x := R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + fullTraitPath, + R.TypeApp(genSelfPath, rTypeParams), + whereConstraints, + body + )); + s := s + [x]; + + s := s + [ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.dafny_runtime.MSel(Upcast).AsType().Apply([R.DynType(fullTraitPath)]), + R.TypeApp(genSelfPath, rTypeParams), + whereConstraints, + [ + R.ImplMemberMacro( + R.dafny_runtime + .MSel(UpcastFnMacro).AsExpr() + .Apply1(R.ExprFromType(R.DynType(fullTraitPath)))) + ] + ) + ) + ]; + } + case _ => {} + } + } } method GenPath(p: seq, escape: bool := true) returns (r: R.Path) { From 01bd657d53efce81ac06a997afad106af5959f8a Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 25 Nov 2024 08:43:32 -0600 Subject: [PATCH 04/69] Support for calling trait methods on datatypes --- Source/DafnyCore/Backends/Dafny/AST.dfy | 5 +- Source/DafnyCore/Backends/Dafny/ASTBuilder.cs | 23 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 11 +- .../Rust/Dafny-compiler-rust-definitions.dfy | 19 +- .../Rust/Dafny-compiler-rust-rast.dfy | 13 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 422 ++-- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 118 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 1823 +++++++++-------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 13 +- Source/DafnyCore/GeneratedFromDafny/RAST.cs | 46 +- .../DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 26 +- .../DafnyRuntimeRust/src/tests/mod.rs | 28 +- .../LitTest/comp/rust/traits-datatypes.dfy | 2 +- 13 files changed, 1437 insertions(+), 1112 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 160c486ede7..8b6914c356c 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -125,14 +125,15 @@ module {:extern "DAST"} DAST { } } - predicat IsGeneralTrait() { + predicate IsGeneralTrait() { match this { case UserDefined(ResolvedType(_, _, typeKind, _, _, _)) => match typeKind { case SynonymType(typ) => typ.IsGeneralTrait() - case TraitType(GeneralTrait) => true + case Trait(GeneralTrait) => true case _ => false + } case _ => false } } diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index 11f319b4e04..23f15bd19b6 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -159,8 +159,9 @@ public object Finish() { interface TraitContainer : Container { void AddTrait(Trait item); - public TraitBuilder Trait(string name, List typeParams, List parents, ISequence<_IAttribute> attributes) { - return new TraitBuilder(this, name, typeParams, parents, attributes); + public TraitBuilder Trait(string name, List typeParams, List parents, + ISequence<_IAttribute> attributes, _ITraitType traitType) { + return new TraitBuilder(this, name, typeParams, parents, attributes, traitType); } } @@ -171,12 +172,14 @@ class TraitBuilder : ClassLike { private readonly List parents; readonly List body = new(); private ISequence<_IAttribute> attributes; + private _ITraitType traitType; - public TraitBuilder(TraitContainer parent, string name, List typeParams, List parents, ISequence<_IAttribute> attributes) { + public TraitBuilder(TraitContainer parent, string name, List typeParams, List parents, ISequence<_IAttribute> attributes, _ITraitType traitType) { this.parent = parent; this.name = name; this.typeParams = typeParams; this.attributes = attributes; + this.traitType = traitType; this.parents = parents; } @@ -200,6 +203,7 @@ public object Finish() { parent.AddTrait((Trait)Trait.create( Sequence.UnicodeFromString(this.name), Sequence.FromArray(typeParams.ToArray()), + traitType, Sequence.FromArray(parents.ToArray()), Sequence.FromArray(body.ToArray()), attributes) @@ -321,9 +325,9 @@ public object Finish() { interface DatatypeContainer : Container { void AddDatatype(Datatype item); - public DatatypeBuilder Datatype(string name, string enclosingModule, List typeParams, - List ctors, bool isCo, ISequence<_IAttribute> attributes) { - return new DatatypeBuilder(this, name, enclosingModule, typeParams, ctors, isCo, attributes); + public DatatypeBuilder Datatype(string name, string enclosingModule, List typeParams, + List ctors, bool isCo, ISequence<_IAttribute> attributes, List superTraitTypes) { + return new DatatypeBuilder(this, name, enclosingModule, typeParams, ctors, isCo, attributes, superTraitTypes); } } @@ -336,8 +340,9 @@ class DatatypeBuilder : ClassLike { readonly bool isCo; readonly List body = new(); private ISequence<_IAttribute> attributes; + private List superTraitTypes; - public DatatypeBuilder(DatatypeContainer parent, string name, string enclosingModule, List typeParams, List ctors, bool isCo, ISequence<_IAttribute> attributes) { + public DatatypeBuilder(DatatypeContainer parent, string name, string enclosingModule, List typeParams, List ctors, bool isCo, ISequence<_IAttribute> attributes, List superTraitTypes) { this.parent = parent; this.name = name; this.typeParams = typeParams; @@ -345,6 +350,7 @@ public DatatypeBuilder(DatatypeContainer parent, string name, string enclosingMo this.ctors = ctors; this.isCo = isCo; this.attributes = attributes; + this.superTraitTypes = superTraitTypes; } public void AddMethod(DAST.Method item) { @@ -362,7 +368,8 @@ public object Finish() { Sequence.FromArray(typeParams.ToArray()), Sequence.FromArray(ctors.ToArray()), Sequence.FromArray(body.ToArray()), - this.isCo, attributes + this.isCo, attributes, + Sequence.FromArray(superTraitTypes.ToArray()) )); return parent; } diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 6eea3632e92..894db1e6513 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -245,7 +245,11 @@ protected override IClassWriter CreateTrait(string name, bool isExtern, List.UnicodeFromString(ctor.GetCompileName(Options)), args, ctor.Formals.Count > 0); + var superClasses = dt.ParentTypeInformation.UniqueParentTraits(); + var superTraitTypes = superClasses.Select(GenType).ToList(); return new ClassWriter(this, typeParams.Count > 0, builder.Datatype( dt.GetCompileName(Options), @@ -297,7 +303,8 @@ from arg in ctor.Formals typeParams, ctors.ToList(), dt is CoDatatypeDecl, - ParseAttributes(dt.Attributes) + ParseAttributes(dt.Attributes), + superTraitTypes )); } else { throw new InvalidOperationException("Cannot declare datatype outside of a module: " + currentBuilder); diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index edc5e8aba3e..6561e133aa4 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -24,6 +24,13 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { "box","do","final","macro","override","priv","try","typeof","unsized", "virtual","yield"} + // Method names that would automatically resolve to trait methods instead of inherent methods + // Hence, full name is always required for these methods + const builtin_trait_preferred_methods := { + "le", "eq", "lt", "ge", "gt" + } + + const reserved_vars := { "None", "hash" } const reserved_rust_need_prefix := {"u8", "u16", "u32", "u64", "u128","i8", "i16", "i32", "i64", "i128"} @@ -127,6 +134,8 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { escapeIdent(f.dafny_name) } + // T, &T, &mut T, Box + // Rc, &Rc are counted in T and &T since the type itself is wrapped by Rc datatype Ownership = | OwnershipOwned | OwnershipOwnedBox @@ -164,6 +173,12 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { predicate IsBorrowedMut(name: string) { name in types && types[name].BorrowedMut? } + predicate IsBoxed(name: string) { + name in types && types[name].IsBox() + } + predicate NeedsAsRefForBorrow(name: string) { + name in types && types[name].NeedsAsRefForBorrow() + } function AddAssigned(name: string, tpe: R.Type): Environment // If we know for sure the type of name extends the Copy trait { @@ -421,8 +436,10 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { } predicate OwnershipGuarantee(expectedOwnership: Ownership, resultingOwnership: Ownership) { + && expectedOwnership != OwnershipOwnedBox // We don't ask for a box, but we might get one && (expectedOwnership != OwnershipAutoBorrowed ==> - resultingOwnership == expectedOwnership) + || resultingOwnership == expectedOwnership + || (expectedOwnership == OwnershipOwned && resultingOwnership == OwnershipOwnedBox)) && resultingOwnership != OwnershipAutoBorrowed // We know what's going on } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index 89ab9c645c8..25fa8065b30 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -594,7 +594,7 @@ module RAST const PtrPath: Path := dafny_runtime.MSel("Ptr") - const BoxPath := std.MSel("box").MSel("Box") + const BoxPath := std.MSel("boxed").MSel("Box") const Ptr := PtrPath.AsExpr() @@ -962,6 +962,13 @@ module RAST case _ => false } } + // Every type that needs to be .as_ref() to become purely borrowed + predicate NeedsAsRefForBorrow() { + if Borrowed? then + underlying.IsBox() || underlying.IsRc() + else + IsBox() || IsRc() + } function BoxUnderlying(): Type requires IsBox() { @@ -1819,6 +1826,10 @@ module RAST function Clone(): Expr { Select(this, "clone").Apply0() } + + predicate IsBorrow() { + UnaryOp? && op1 == "&" + } } function Unsafe(underlying: Expr): Expr { diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 1f675bceb53..1d321522062 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -138,7 +138,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case SynonymType(s) => generated := GenSynonymType(s); case Datatype(d) => - generated := GenDatatype(d); + generated := GenDatatype(d, containingPath + [Ident.Ident(d.name)]); } s := s + generated; } @@ -160,22 +160,20 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenTypeParameters(params: seq) returns ( typeParamsSeq: seq, - typeParams: seq, - constrainedTypeParams: seq, - whereConstraints: string) + rTypeParams: seq, + rTypeParamsDecls: seq) { typeParamsSeq := []; - typeParams := []; - constrainedTypeParams := []; - whereConstraints := ""; + rTypeParams := []; + rTypeParamsDecls := []; if |params| > 0 { for tpI := 0 to |params| { var tp := params[tpI]; var typeArg, typeParam := GenTypeParam(tp); var rType := GenType(typeArg, GenTypeContext.default()); typeParamsSeq := typeParamsSeq + [typeArg]; - typeParams := typeParams + [rType]; - constrainedTypeParams := constrainedTypeParams + [typeParam]; + rTypeParams := rTypeParams + [rType]; + rTypeParamsDecls := rTypeParamsDecls + [typeParam]; } } } @@ -236,10 +234,127 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } + method GetName(attributes: seq, name: Name, kind: string) returns (rName: string, extern: ExternAttribute) + modifies this + { + extern := ExtractExtern(attributes, name); + + if extern.SimpleExtern? { + rName := extern.overrideName; + } else { + rName := escapeName(name); + if extern.AdvancedExtern? { + error := Some("Multi-argument externs not supported for "+kind+" yet"); + } + } + } + + method GenTraitImplementations( + path: seq, + rTypeParams: seq, + rTypeParamsDecls: seq, + superTraitTypes: seq, + traitBodies: map, seq>, + extern: ExternAttribute, + kind: string) + returns (s: seq) + modifies this + { + s := []; + var genSelfPath := GenPathType(path); + for i := 0 to |superTraitTypes| { + var superTraitType := superTraitTypes[i]; + match superTraitType { + case UserDefined(ResolvedType(traitPath, typeArgs, Trait(traitType), _, properMethods, _)) => { + var pathStr := GenPathType(traitPath); + var typeArgs := GenTypeArgs(typeArgs, GenTypeContext.default()); + var body: seq := []; + if traitPath in traitBodies { + body := traitBodies[traitPath]; + } + + var fullTraitPath := R.TypeApp(pathStr, typeArgs); + if !extern.NoExtern? { // An extern of some kind + // Either the Dafny code implements all the methods of the trait or none, + if |body| == 0 && |properMethods| != 0 { + continue; // We assume everything is implemented externally + } + if |body| != |properMethods| { + error := Some("Error: In the "+kind+" " + R.SeqToString(path, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + + fullTraitPath.ToString("") + " are marked {:extern} and some are not." + + " For the Rust compiler, please make all methods (" + R.SeqToString(properMethods, (s: Name) => s.dafny_name, ", ") + + ") bodiless and mark as {:extern} and implement them in a Rust file, "+ + "or mark none of them as {:extern} and implement them in Dafny. " + + "Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible."); + } + } + if |body| == 0 { + // Extern type, we assume + } + if traitType.GeneralTrait? { + // One more method: Cloning when boxed + /*impl Test for Wrapper { + fn _clone(&self) -> Box { + Box::new(self.clone()) + } + }*/ + body := body + [ + R.FnDecl( + R.PRIV, + R.Fn( + "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(fullTraitPath))), + "", + Some(R.BoxNew(R.self.Sel("clone").Apply0())))) + ]; + } else { + if kind == "datatype" || kind == "newtype" { + var dummy := Error("Cannot extend non-general traits"); + } + } + + var x := R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + fullTraitPath, + R.TypeApp(genSelfPath, rTypeParams), + "", + body + )); + s := s + [x]; + + var upcastTraitToImplement, upcastTraitFn; + if traitType.GeneralTrait? { + upcastTraitToImplement, upcastTraitFn := "UpcastBox", "UpcastStructBoxFn!"; + } else { + upcastTraitToImplement, upcastTraitFn := Upcast, UpcastFnMacro; + } + s := s + [ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.dafny_runtime.MSel(upcastTraitToImplement).AsType().Apply([ + R.DynType(fullTraitPath)]), + R.TypeApp(genSelfPath, rTypeParams), + "", + [ + R.ImplMemberMacro( + R.dafny_runtime + .MSel(upcastTraitFn).AsExpr() + .Apply1(R.ExprFromType(R.DynType(fullTraitPath)))) + ] + ) + ) + ]; + } + case _ => {} + } + } + } + method GenClass(c: Class, path: seq) returns (s: seq) modifies this { - var typeParamsSeq, rTypeParams, rTypeParamsDecls, whereConstraints := GenTypeParameters(c.typeParams); + var typeParamsSeq, rTypeParams, rTypeParamsDecls := GenTypeParameters(c.typeParams); var constrainedTypeParams := R.TypeParamDecl.ToStringMultiple(rTypeParamsDecls, R.IND + R.IND); var fields: seq := []; @@ -271,17 +386,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.std.MSel("marker").MSel("PhantomData").AsExpr())]; } - var extern := ExtractExtern(c.attributes, c.name); - - var className; - if extern.SimpleExtern? { - className := extern.overrideName; - } else { - className := escapeName(c.name); - if extern.AdvancedExtern? { - error := Some("Multi-argument externs not supported for classes yet"); - } - } + var className, extern := GetName(c.attributes, c.name, "classes"); var struct := R.Struct([], className, rTypeParamsDecls, R.NamedFields(fields)); s := []; @@ -327,7 +432,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var i := R.Impl( rTypeParamsDecls, R.TypeApp(selfTypeForImpl, rTypeParams), - whereConstraints, + "", implBody ); s := s + [R.ImplDecl(i)]; @@ -361,7 +466,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.dafny_runtime.MSel(Upcast).AsType().Apply([R.DynType(R.AnyTrait)]), R.TypeApp(genSelfPath, rTypeParams), - whereConstraints, + "", [ R.ImplMemberMacro( R.dafny_runtime @@ -373,81 +478,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ]; } var superTraitTypes := if className == "_default" then [] else c.superTraitTypes; - for i := 0 to |superTraitTypes| { - var superTraitType := superTraitTypes[i]; - match superTraitType { - case UserDefined(ResolvedType(traitPath, typeArgs, Trait(traitType), _, properMethods, _)) => { - var pathStr := GenPathType(traitPath); - var typeArgs := GenTypeArgs(typeArgs, GenTypeContext.default()); - var body: seq := []; - if traitPath in traitBodies { - body := traitBodies[traitPath]; - } - - var fullTraitPath := R.TypeApp(pathStr, typeArgs); - if !extern.NoExtern? { // An extern of some kind - // Either the Dafny code implements all the methods of the trait or none, - if |body| == 0 && |properMethods| != 0 { - continue; // We assume everything is implemented externally - } - if |body| != |properMethods| { - error := Some("Error: In the class " + R.SeqToString(path, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + - fullTraitPath.ToString("") + " are marked {:extern} and some are not." + - " For the Rust compiler, please make all methods (" + R.SeqToString(properMethods, (s: Name) => s.dafny_name, ", ") + - ") bodiless and mark as {:extern} and implement them in a Rust file, "+ - "or mark none of them as {:extern} and implement them in Dafny. " + - "Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible."); - } - } - if |body| == 0 { - // Extern type, we assume - } - if traitType.GeneralTrait? { - // One more method: Cloning when boxed - /*impl Test for Wrapper { - fn _clone(&self) -> Box { - Box::new(self.clone()) - } - }*/ - body := body + [ - R.FnDecl( - R.PRIV, - R.Fn( - "_clone", [], [R.Formal.selfBorrowed], R.Boxed(R.DynType(fullTraitPath)), - "", - Some(R.BoxNew(R.self.MSel("clone").Apply0())))) - ]; - } - var x := R.ImplDecl( - R.ImplFor( - rTypeParamsDecls, - fullTraitPath, - R.TypeApp(genSelfPath, rTypeParams), - whereConstraints, - body - )); - s := s + [x]; - - s := s + [ - R.ImplDecl( - R.ImplFor( - rTypeParamsDecls, - R.dafny_runtime.MSel(Upcast).AsType().Apply([R.DynType(fullTraitPath)]), - R.TypeApp(genSelfPath, rTypeParams), - whereConstraints, - [ - R.ImplMemberMacro( - R.dafny_runtime - .MSel(UpcastFnMacro).AsExpr() - .Apply1(R.ExprFromType(R.DynType(fullTraitPath)))) - ] - ) - ) - ]; - } - case _ => {} - } - } + var superTraitImplementations := GenTraitImplementations( + path, + rTypeParams, + rTypeParamsDecls, + superTraitTypes, + traitBodies, + extern, + "class"); + s := s + superTraitImplementations; } method GenTrait(t: Trait, containingPath: seq) returns (s: seq) @@ -469,8 +508,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var fullPath := containingPath + [Ident.Ident(t.name)]; var name := escapeName(t.name); - var traitFulltype := R.TypeApp(R.TIdentifier(name), typeParams); - var traitFullExpr := R.ApplyType(R.Identifier(name), typeParams); + var traitFulltype := R.TIdentifier(name).Apply(typeParams); + var traitFullExpr := R.Identifier(name).ApplyType(typeParams); var implBody, _ := GenClassImplBody( t.body, true, UserDefined( @@ -494,11 +533,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var parents := []; var upcastImplemented := []; for i := 0 to |t.parents| { - var parentTpe := GenType(t.parents[i], GenTypeContext.ForTraitParents()); + var parentTyp := t.parents[i]; + var parentTpe := GenType(parentTyp, GenTypeContext.ForTraitParents()); parents := parents + [parentTpe]; - var upcastTrait := if parentTpe.IsGeneralTrait() then "UpcastBox" else Upcast; + var upcastTrait := if parentTyp.IsGeneralTrait() then "UpcastBox" else Upcast; parents := parents + [R.dafny_runtime.MSel(upcastTrait).AsType().Apply1(R.DynType(parentTpe))]; - if parentTpe.IsGeneralTrait() { + if parentTyp.IsGeneralTrait() { /*impl UpcastBox for Box { UpcastBoxFn!(GeneralTraitSuper); }*/ @@ -512,7 +552,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { [ R.ImplMemberMacro( R.dafny_runtime .MSel("UpcastBoxFn").AsExpr() - .Apply1(R.ExprFromType(tpe)))])) + .Apply1(R.ExprFromType(parentTpe)))])) ]; } } @@ -533,7 +573,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplDecl( R.ImplFor( rTypeParamsDecls, - R.std.MSel("clone").MSel("Clone"), + R.std.MSel("clone").MSel("Clone").AsType(), R.Box(R.DynType(traitFulltype)), "", [R.FnDecl( @@ -551,7 +591,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenNewtype(c: Newtype, path: seq) returns (s: seq) modifies this { - var typeParamsSeq, rTypeParams, rTypeParamsDecls, whereConstraints := GenTypeParameters(c.typeParams); + var typeParamsSeq, rTypeParams, rTypeParamsDecls := GenTypeParameters(c.typeParams); var constrainedTypeParams := R.TypeParamDecl.ToStringMultiple(rTypeParamsDecls, R.IND + R.IND); var wrappedType; @@ -619,7 +659,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Impl( rTypeParamsDecls, resultingType, - whereConstraints, + "", [ R.FnDecl( R.PUB, @@ -638,7 +678,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.DefaultTrait, resultingType, - whereConstraints, + "", [body]))]; s := s + [ R.ImplDecl( @@ -727,7 +767,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Impl( rTypeParamsDecls, R.TypeApp(R.TIdentifier(newtypeName), rTypeParams), - whereConstraints, + "", implementation ) )]; @@ -737,7 +777,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenSynonymType(c: SynonymType) returns (s: seq) modifies this { - var typeParamsSeq, rTypeParams, rTypeParamsDecls, whereConstraints := GenTypeParameters(c.typeParams); + var typeParamsSeq, rTypeParams, rTypeParamsDecls := GenTypeParameters(c.typeParams); var synonymTypeName := escapeName(c.name); var resultingType := GenType(c.base, GenTypeContext.default()); @@ -811,11 +851,11 @@ module {:extern "DCOMP"} DafnyToRustCompiler { write(R.LiteralString(s, binary := false, verbatim := false)) } - method GenDatatype(c: Datatype) returns (s: seq) + method GenDatatype(c: Datatype, path: seq) returns (s: seq) modifies this { - var typeParamsSeq, rTypeParams, rTypeParamsDecls, whereConstraints := GenTypeParameters(c.typeParams); - var datatypeName := escapeName(c.name); + var typeParamsSeq, rTypeParams, rTypeParamsDecls := GenTypeParameters(c.typeParams); + var datatypeName, extern := GetName(c.attributes, c.name, "datatypes"); var ctors: seq := []; var variances := Std.Collections.Seq.Map((typeParamDecl: TypeArgDecl) => typeParamDecl.variance, c.typeParams); var singletonConstructors := []; @@ -1019,7 +1059,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Impl( rTypeParamsDecls, R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), - whereConstraints, + "", implBody ))]; @@ -1253,82 +1293,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { )] ))]; } - var superTraitTypes := c.superTraitTypes; - for i := 0 to |superTraitTypes| { - var superTraitType := superTraitTypes[i]; - match superTraitType { - case UserDefined(ResolvedType(traitPath, typeArgs, Trait(traitType), _, properMethods, _)) => { - var pathStr := GenPathType(traitPath); - var typeArgs := GenTypeArgs(typeArgs, GenTypeContext.default()); - var body: seq := []; - if traitPath in traitBodies { - body := traitBodies[traitPath]; - } - - var fullTraitPath := R.TypeApp(pathStr, typeArgs); - if !extern.NoExtern? { // An extern of some kind - // Either the Dafny code implements all the methods of the trait or none, - if |body| == 0 && |properMethods| != 0 { - continue; // We assume everything is implemented externally - } - if |body| != |properMethods| { - error := Some("Error: In the class " + R.SeqToString(path, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + - fullTraitPath.ToString("") + " are marked {:extern} and some are not." + - " For the Rust compiler, please make all methods (" + R.SeqToString(properMethods, (s: Name) => s.dafny_name, ", ") + - ") bodiless and mark as {:extern} and implement them in a Rust file, "+ - "or mark none of them as {:extern} and implement them in Dafny. " + - "Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible."); - } - } - if |body| == 0 { - // Extern type, we assume - } - if traitType.GeneralTrait? { - // One more method: Cloning when boxed - /*impl Test for Wrapper { - fn _clone(&self) -> Box { - Box::new(self.clone()) - } - }*/ - body := body + [ - R.FnDecl( - R.PRIV, - R.Fn( - "_clone", [], [R.Formal.selfBorrowed], R.Boxed(R.DynType(fullTraitPath)), - "", - Some(R.BoxNew(R.self.MSel("clone").Apply0())))) - ]; - } - var x := R.ImplDecl( - R.ImplFor( - rTypeParamsDecls, - fullTraitPath, - R.TypeApp(genSelfPath, rTypeParams), - whereConstraints, - body - )); - s := s + [x]; - - s := s + [ - R.ImplDecl( - R.ImplFor( - rTypeParamsDecls, - R.dafny_runtime.MSel(Upcast).AsType().Apply([R.DynType(fullTraitPath)]), - R.TypeApp(genSelfPath, rTypeParams), - whereConstraints, - [ - R.ImplMemberMacro( - R.dafny_runtime - .MSel(UpcastFnMacro).AsExpr() - .Apply1(R.ExprFromType(R.DynType(fullTraitPath)))) - ] - ) - ) - ]; - } - case _ => {} - } - } + var superTraitImplementations := GenTraitImplementations( + path, + rTypeParams, + rTypeParamsDecls, + c.superTraitTypes, + traitBodies, + extern, + "datatype"); + s := s + superTraitImplementations; } method GenPath(p: seq, escape: bool := true) returns (r: R.Path) { @@ -2191,9 +2164,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method FromOwned(r: R.Expr, expectedOwnership: Ownership) returns (out: R.Expr, resultingOwnership: Ownership) modifies this - ensures resultingOwnership != OwnershipAutoBorrowed - ensures expectedOwnership != OwnershipAutoBorrowed - ==> resultingOwnership == expectedOwnership + requires expectedOwnership != OwnershipOwnedBox ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) { if expectedOwnership == OwnershipOwnedBox { @@ -2216,6 +2187,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method FromOwnership(r: R.Expr, ownership: Ownership, expectedOwnership: Ownership) returns (out: R.Expr, resultingOwnership: Ownership) requires ownership != OwnershipAutoBorrowed + requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) { @@ -2228,7 +2200,20 @@ module {:extern "DCOMP"} DafnyToRustCompiler { out, resultingOwnership := FromOwned(r, expectedOwnership); return; } else if ownership == OwnershipOwnedBox { - out, resultingOwnership := FromOwned(R.UnaryOp("*", r, Format.UnaryOpFormat.NoFormat), expectedOwnership); + if expectedOwnership == OwnershipBorrowed { + out := r.Sel("as_ref").Apply0(); + resultingOwnership := OwnershipBorrowed; + } else if expectedOwnership == OwnershipAutoBorrowed { + resultingOwnership := OwnershipOwnedBox; + out := r; + } else if expectedOwnership == OwnershipBorrowedMut { + out := r.Sel("as_mut").Apply0(); // For completeness, not sure we can ever reach that case + resultingOwnership := OwnershipBorrowedMut; + } else if expectedOwnership == OwnershipOwned { + resultingOwnership := OwnershipOwnedBox; + out := r; + } + return; } else if ownership == OwnershipBorrowed || ownership == OwnershipBorrowedMut { if expectedOwnership == OwnershipOwned{ resultingOwnership := OwnershipOwned; @@ -2249,6 +2234,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { resultingOwnership := OwnershipBorrowedMut; out := R.BorrowMut(r); // Not sure if it will ever happen } + return; } else { assert false; } @@ -2261,6 +2247,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.Literal? + requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0 @@ -2412,6 +2399,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.BinOp? + requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0 @@ -2602,6 +2590,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership) requires exprOwnership != OwnershipAutoBorrowed + requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases fromTpe, toTpe // We unwrap newtypes @@ -2877,6 +2866,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { toTpe: Type, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership) + requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) { @@ -2915,6 +2905,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.Convert? + requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0 @@ -2939,6 +2930,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) + requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) { @@ -2947,6 +2939,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var placeboOpt := if tpe.Some? then tpe.value.ExtractMaybePlacebo() else None; var currentlyBorrowed := env.IsBorrowed(rName); // Otherwise names are owned var noNeedOfClone := env.CanReadWithoutClone(rName); + var isSelf := selfIdent.ThisTyped? && selfIdent.IsSelf() && selfIdent.rSelfName == rName; if placeboOpt.Some? { r := r.Sel("read").Apply0(); currentlyBorrowed := false; @@ -2969,10 +2962,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { resultingOwnership := OwnershipBorrowedMut; } else if expectedOwnership == OwnershipOwned { var needObjectFromRef := - selfIdent.ThisTyped? && selfIdent.IsSelf() && selfIdent.rSelfName == rName && + isSelf && match selfIdent.dafnyType { case UserDefined(ResolvedType(_, _, base, attributes, _, _)) => - base.Class? || base.Trait? + base.Class? || (base.Trait? && base.traitType.ObjectTrait?) case _ => false }; if needObjectFromRef { @@ -2994,6 +2987,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { resultingOwnership := OwnershipBorrowed; } else { assert expectedOwnership == OwnershipBorrowed; + var selfIsGeneralTrait := + isSelf && + match selfIdent.dafnyType { + case UserDefined(ResolvedType(_, _, base, attributes, _, _)) => + base.Trait? && base.traitType.GeneralTrait? + case _ => false + }; if rName != "self" { // It's currently owned. If it's a pointer, we need to convert it to a borrow if tpe.Some? && tpe.value.IsPointer() { @@ -3059,7 +3059,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // Calls on traits should be fully specified as we can't guarantee traits will be in context // Calls on non-traits should be also fully specified if the method is not found in the definition of that type case CallName(nameIdent, Some(UserDefined(resolvedType)), _, _, _) => - if resolvedType.kind.Trait? || forall m <- resolvedType.properMethods :: m != nameIdent { + if resolvedType.kind.Trait? || + nameIdent.dafny_name in builtin_trait_preferred_methods || + forall m <- resolvedType.properMethods :: m != nameIdent { fullNameQualifier := Some(TraitTypeContainingMethod(resolvedType, nameIdent.dafny_name).GetOr(resolvedType)); } else { fullNameQualifier := None; @@ -3095,8 +3097,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) - ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) + requires expectedOwnership != OwnershipOwnedBox modifies this + ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 1 { match e { case Literal(_) => @@ -3754,11 +3757,32 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var fullPath := GenPathExpr(path); var onTypeExprs := GenTypeArgs(onTypeArgs, GenTypeContext.default()); var onExpr, recOwnership, recIdents; - if base.Trait? || base.Class? { + if (base.Trait? && base.traitType.ObjectTrait?) || base.Class? { + // First we own a pointer, then we read it onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); onExpr := read_macro.Apply1(onExpr); readIdents := readIdents + recIdents; + } else if base.Trait? && base.traitType.GeneralTrait? { + // General traits borrow their self, from a Box + // The underlying type is a Box, self: Datatype or Rc + // 'on' is going to return an owned version of this box. + onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); + if onExpr.Identifier? && env.NeedsAsRefForBorrow(onExpr.name) { + onExpr := onExpr.Sel("as_ref").Apply0(); + } else if onExpr.IsBorrow() { + // If the resulting expression is a borrow, e.g. &something(), it means the trait was owned. + // In our case we want dynamic dispatch, so we need to get the bare reference. + // Because "on" is a general trait, we need to call as_ref() instead to get the bare expression + // If the onExpr is an identifier but not "self", we apply the same treatment + onExpr := onExpr.underlying.Sel("as_ref").Apply0(); + } + readIdents := readIdents + recIdents; + } else if base.Newtype? && IsNewtypeCopy(base.range) { + // The self type of a newtype that is copy is also copy + onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); + readIdents := readIdents + recIdents; } else { + // The self type of any other type is borrowed onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); readIdents := readIdents + recIdents; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 566db364bee..43a70d575a8 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -559,6 +559,7 @@ public interface _IType { _IType DowncastClone(); DAST._IType Replace(Dafny.IMap mapping); bool IsPrimitiveInt(); + bool IsGeneralTrait(); } public abstract class Type : _IType { public Type() { @@ -807,6 +808,41 @@ public bool IsPrimitiveInt() { return false; } } + public bool IsGeneralTrait() { + _IType _this = this; + TAIL_CALL_START: ; + DAST._IType _source0 = _this; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase _0_typeKind = resolved0.dtor_kind; + DAST._IResolvedTypeBase _source1 = _0_typeKind; + { + if (_source1.is_SynonymType) { + DAST._IType _1_typ = _source1.dtor_baseType; + DAST._IType _in0 = _1_typ; + _this = _in0; + ; + goto TAIL_CALL_START; + } + } + { + if (_source1.is_Trait) { + DAST._ITraitType traitType0 = _source1.dtor_traitType; + if (traitType0.is_GeneralTrait) { + return true; + } + } + } + { + return false; + } + } + } + { + return false; + } + } } public class Type_UserDefined : Type { public readonly DAST._IResolvedType _resolved; @@ -2717,7 +2753,7 @@ public interface _IClass { Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_enclosingModule { get; } Dafny.ISequence dtor_typeParams { get; } - Dafny.ISequence dtor_superClasses { get; } + Dafny.ISequence dtor_superTraitTypes { get; } Dafny.ISequence dtor_fields { get; } Dafny.ISequence dtor_body { get; } Dafny.ISequence dtor_attributes { get; } @@ -2727,26 +2763,26 @@ public class Class : _IClass { public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _enclosingModule; public readonly Dafny.ISequence _typeParams; - public readonly Dafny.ISequence _superClasses; + public readonly Dafny.ISequence _superTraitTypes; public readonly Dafny.ISequence _fields; public readonly 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) { + public Class(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence superTraitTypes, Dafny.ISequence fields, Dafny.ISequence body, Dafny.ISequence attributes) { this._name = name; this._enclosingModule = enclosingModule; this._typeParams = typeParams; - this._superClasses = superClasses; + this._superTraitTypes = superTraitTypes; 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, _attributes); + return new Class(_name, _enclosingModule, _typeParams, _superTraitTypes, _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) && object.Equals(this._attributes, oth._attributes); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._superTraitTypes, oth._superTraitTypes) && 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; @@ -2754,7 +2790,7 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._enclosingModule)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParams)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._superClasses)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._superTraitTypes)); 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)); @@ -2769,7 +2805,7 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._typeParams); s += ", "; - s += Dafny.Helpers.ToString(this._superClasses); + s += Dafny.Helpers.ToString(this._superTraitTypes); s += ", "; s += Dafny.Helpers.ToString(this._fields); s += ", "; @@ -2787,11 +2823,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, Dafny.ISequence attributes) { - return new Class(name, enclosingModule, typeParams, superClasses, fields, body, attributes); + public static _IClass create(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence superTraitTypes, Dafny.ISequence fields, Dafny.ISequence body, Dafny.ISequence attributes) { + return new Class(name, enclosingModule, typeParams, superTraitTypes, 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, Dafny.ISequence attributes) { - return create(name, enclosingModule, typeParams, superClasses, fields, body, attributes); + public static _IClass create_Class(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence superTraitTypes, Dafny.ISequence fields, Dafny.ISequence body, Dafny.ISequence attributes) { + return create(name, enclosingModule, typeParams, superTraitTypes, fields, body, attributes); } public bool is_Class { get { return true; } } public Dafny.ISequence dtor_name { @@ -2809,9 +2845,9 @@ public Dafny.ISequence dtor_typeParams { return this._typeParams; } } - public Dafny.ISequence dtor_superClasses { + public Dafny.ISequence dtor_superTraitTypes { get { - return this._superClasses; + return this._superTraitTypes; } } public Dafny.ISequence dtor_fields { @@ -2835,6 +2871,7 @@ public interface _ITrait { bool is_Trait { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } + DAST._ITraitType dtor_traitType { get; } Dafny.ISequence dtor_parents { get; } Dafny.ISequence dtor_body { get; } Dafny.ISequence dtor_attributes { get; } @@ -2843,29 +2880,32 @@ public interface _ITrait { public class Trait : _ITrait { public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _typeParams; + public readonly DAST._ITraitType _traitType; public readonly Dafny.ISequence _parents; public readonly Dafny.ISequence _body; public readonly Dafny.ISequence _attributes; - public Trait(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence parents, Dafny.ISequence body, Dafny.ISequence attributes) { + public Trait(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence body, Dafny.ISequence attributes) { this._name = name; this._typeParams = typeParams; + this._traitType = traitType; this._parents = parents; this._body = body; this._attributes = attributes; } public _ITrait DowncastClone() { if (this is _ITrait dt) { return dt; } - return new Trait(_name, _typeParams, _parents, _body, _attributes); + return new Trait(_name, _typeParams, _traitType, _parents, _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._parents, oth._parents) && object.Equals(this._body, oth._body) && object.Equals(this._attributes, oth._attributes); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._traitType, oth._traitType) && object.Equals(this._parents, oth._parents) && object.Equals(this._body, oth._body) && object.Equals(this._attributes, oth._attributes); } 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._typeParams)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._traitType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._parents)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); @@ -2878,6 +2918,8 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._typeParams); s += ", "; + s += Dafny.Helpers.ToString(this._traitType); + s += ", "; s += Dafny.Helpers.ToString(this._parents); s += ", "; s += Dafny.Helpers.ToString(this._body); @@ -2886,7 +2928,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly DAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly DAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.TraitType.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static DAST._ITrait Default() { return theDefault; } @@ -2894,11 +2936,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 parents, Dafny.ISequence body, Dafny.ISequence attributes) { - return new Trait(name, typeParams, parents, body, attributes); + public static _ITrait create(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence body, Dafny.ISequence attributes) { + return new Trait(name, typeParams, traitType, parents, body, attributes); } - public static _ITrait create_Trait(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence parents, Dafny.ISequence body, Dafny.ISequence attributes) { - return create(name, typeParams, parents, body, attributes); + public static _ITrait create_Trait(Dafny.ISequence name, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence body, Dafny.ISequence attributes) { + return create(name, typeParams, traitType, parents, body, attributes); } public bool is_Trait { get { return true; } } public Dafny.ISequence dtor_name { @@ -2911,6 +2953,11 @@ public Dafny.ISequence dtor_typeParams { return this._typeParams; } } + public DAST._ITraitType dtor_traitType { + get { + return this._traitType; + } + } public Dafny.ISequence dtor_parents { get { return this._parents; @@ -2937,6 +2984,7 @@ public interface _IDatatype { Dafny.ISequence dtor_body { get; } bool dtor_isCo { get; } Dafny.ISequence dtor_attributes { get; } + Dafny.ISequence dtor_superTraitTypes { get; } _IDatatype DowncastClone(); } public class Datatype : _IDatatype { @@ -2947,7 +2995,8 @@ public class Datatype : _IDatatype { public readonly Dafny.ISequence _body; public readonly 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) { + public readonly Dafny.ISequence _superTraitTypes; + public Datatype(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes) { this._name = name; this._enclosingModule = enclosingModule; this._typeParams = typeParams; @@ -2955,14 +3004,15 @@ public Datatype(Dafny.ISequence name, Dafny.ISequence en this._body = body; this._isCo = isCo; this._attributes = attributes; + this._superTraitTypes = superTraitTypes; } public _IDatatype DowncastClone() { if (this is _IDatatype dt) { return dt; } - return new Datatype(_name, _enclosingModule, _typeParams, _ctors, _body, _isCo, _attributes); + return new Datatype(_name, _enclosingModule, _typeParams, _ctors, _body, _isCo, _attributes, _superTraitTypes); } 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 && object.Equals(this._attributes, oth._attributes); + 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) && object.Equals(this._superTraitTypes, oth._superTraitTypes); } public override int GetHashCode() { ulong hash = 5381; @@ -2974,6 +3024,7 @@ public override int GetHashCode() { 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)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._superTraitTypes)); return (int) hash; } public override string ToString() { @@ -2992,10 +3043,12 @@ public override string ToString() { s += Dafny.Helpers.ToString(this._isCo); s += ", "; s += Dafny.Helpers.ToString(this._attributes); + s += ", "; + s += Dafny.Helpers.ToString(this._superTraitTypes); 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, Dafny.Sequence.Empty); + private static readonly DAST._IDatatype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, false, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static DAST._IDatatype Default() { return theDefault; } @@ -3003,11 +3056,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, Dafny.ISequence attributes) { - return new Datatype(name, enclosingModule, typeParams, ctors, body, isCo, attributes); + public static _IDatatype create(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes) { + return new Datatype(name, enclosingModule, typeParams, ctors, body, isCo, attributes, superTraitTypes); } - 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 static _IDatatype create_Datatype(Dafny.ISequence name, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes) { + return create(name, enclosingModule, typeParams, ctors, body, isCo, attributes, superTraitTypes); } public bool is_Datatype { get { return true; } } public Dafny.ISequence dtor_name { @@ -3045,6 +3098,11 @@ public Dafny.ISequence dtor_attributes { return this._attributes; } } + public Dafny.ISequence dtor_superTraitTypes { + get { + return this._superTraitTypes; + } + } } public interface _IDatatypeDtor { diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 5085b997b7c..25624a5cdb6 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -148,7 +148,7 @@ public void GenModuleBody(Dafny.ISequence body, Dafny.ISequen { DAST._IDatatype _8_d = _source0.dtor_Datatype_a0; Dafny.ISequence _out5; - _out5 = (this).GenDatatype(_8_d); + _out5 = (this).GenDatatype(_8_d, Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((_8_d).dtor_name))); _1_generated = _out5; } after_match0: ; @@ -171,16 +171,14 @@ public void GenTypeParam(DAST._ITypeArgDecl tp, out DAST._IType typeArg, out RAS } typeParam = RAST.TypeParamDecl.create(Defs.__default.escapeName(((tp).dtor_name)), _0_genTpConstraint); } - public void GenTypeParameters(Dafny.ISequence @params, out Dafny.ISequence typeParamsSeq, out Dafny.ISequence typeParams, out Dafny.ISequence constrainedTypeParams, out Dafny.ISequence whereConstraints) + public void GenTypeParameters(Dafny.ISequence @params, out Dafny.ISequence typeParamsSeq, out Dafny.ISequence rTypeParams, out Dafny.ISequence rTypeParamsDecls) { typeParamsSeq = Dafny.Sequence.Empty; - typeParams = Dafny.Sequence.Empty; - constrainedTypeParams = Dafny.Sequence.Empty; - whereConstraints = Dafny.Sequence.Empty; + rTypeParams = Dafny.Sequence.Empty; + rTypeParamsDecls = Dafny.Sequence.Empty; typeParamsSeq = Dafny.Sequence.FromElements(); - typeParams = Dafny.Sequence.FromElements(); - constrainedTypeParams = Dafny.Sequence.FromElements(); - whereConstraints = Dafny.Sequence.UnicodeFromString(""); + rTypeParams = Dafny.Sequence.FromElements(); + rTypeParamsDecls = Dafny.Sequence.FromElements(); if ((new BigInteger((@params).Count)).Sign == 1) { BigInteger _hi0 = new BigInteger((@params).Count); for (BigInteger _0_tpI = BigInteger.Zero; _0_tpI < _hi0; _0_tpI++) { @@ -198,8 +196,8 @@ public void GenTypeParameters(Dafny.ISequence @params, out D _out2 = (this).GenType(_2_typeArg, Defs.GenTypeContext.@default()); _4_rType = _out2; typeParamsSeq = Dafny.Sequence.Concat(typeParamsSeq, Dafny.Sequence.FromElements(_2_typeArg)); - typeParams = Dafny.Sequence.Concat(typeParams, Dafny.Sequence.FromElements(_4_rType)); - constrainedTypeParams = Dafny.Sequence.Concat(constrainedTypeParams, Dafny.Sequence.FromElements(_3_typeParam)); + rTypeParams = Dafny.Sequence.Concat(rTypeParams, Dafny.Sequence.FromElements(_4_rType)); + rTypeParamsDecls = Dafny.Sequence.Concat(rTypeParamsDecls, Dafny.Sequence.FromElements(_3_typeParam)); } } } @@ -266,198 +264,244 @@ public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAss } after_match0: ; } + public void GetName(Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence kind, out Dafny.ISequence rName, out Defs._IExternAttribute @extern) + { + rName = Dafny.Sequence.Empty; + @extern = Defs.ExternAttribute.Default(); + @extern = Defs.__default.ExtractExtern(attributes, name); + if ((@extern).is_SimpleExtern) { + rName = (@extern).dtor_overrideName; + } else { + rName = Defs.__default.escapeName(name); + if ((@extern).is_AdvancedExtern) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Multi-argument externs not supported for "), kind), Dafny.Sequence.UnicodeFromString(" yet"))); + } + } + } + public Dafny.ISequence GenTraitImplementations(Dafny.ISequence> path, Dafny.ISequence rTypeParams, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence superTraitTypes, Dafny.IMap>,Dafny.ISequence> traitBodies, Defs._IExternAttribute @extern, Dafny.ISequence kind) + { + Dafny.ISequence s = Dafny.Sequence.Empty; + s = Dafny.Sequence.FromElements(); + RAST._IType _0_genSelfPath; + RAST._IType _out0; + _out0 = (this).GenPathType(path); + _0_genSelfPath = _out0; + BigInteger _hi0 = new BigInteger((superTraitTypes).Count); + for (BigInteger _1_i = BigInteger.Zero; _1_i < _hi0; _1_i++) { + DAST._IType _2_superTraitType; + _2_superTraitType = (superTraitTypes).Select(_1_i); + DAST._IType _source0 = _2_superTraitType; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + Dafny.ISequence> _3_traitPath = resolved0.dtor_path; + Dafny.ISequence _4_typeArgs = resolved0.dtor_typeArgs; + DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; + if (kind0.is_Trait) { + DAST._ITraitType _5_traitType = kind0.dtor_traitType; + Dafny.ISequence> _6_properMethods = resolved0.dtor_properMethods; + { + RAST._IType _7_pathStr; + RAST._IType _out1; + _out1 = (this).GenPathType(_3_traitPath); + _7_pathStr = _out1; + Dafny.ISequence _8_typeArgs; + Dafny.ISequence _out2; + _out2 = (this).GenTypeArgs(_4_typeArgs, Defs.GenTypeContext.@default()); + _8_typeArgs = _out2; + Dafny.ISequence _9_body; + _9_body = Dafny.Sequence.FromElements(); + if ((traitBodies).Contains(_3_traitPath)) { + _9_body = Dafny.Map>, Dafny.ISequence>.Select(traitBodies,_3_traitPath); + } + RAST._IType _10_fullTraitPath; + _10_fullTraitPath = RAST.Type.create_TypeApp(_7_pathStr, _8_typeArgs); + if (!((@extern).is_NoExtern)) { + if (((new BigInteger((_9_body).Count)).Sign == 0) && ((new BigInteger((_6_properMethods).Count)).Sign != 0)) { + goto continue_0; + } + if ((new BigInteger((_9_body).Count)) != (new BigInteger((_6_properMethods).Count))) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the "), kind), Dafny.Sequence.UnicodeFromString(" ")), RAST.__default.SeqToString>(path, ((System.Func, Dafny.ISequence>)((_11_s) => { + return ((_11_s)); +})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_10_fullTraitPath)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" are marked {:extern} and some are not.")), Dafny.Sequence.UnicodeFromString(" For the Rust compiler, please make all methods (")), RAST.__default.SeqToString>(_6_properMethods, ((System.Func, Dafny.ISequence>)((_12_s) => { + return (_12_s); +})), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(") bodiless and mark as {:extern} and implement them in a Rust file, ")), Dafny.Sequence.UnicodeFromString("or mark none of them as {:extern} and implement them in Dafny. ")), Dafny.Sequence.UnicodeFromString("Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible."))); + } + } + if ((_5_traitType).is_GeneralTrait) { + _9_body = Dafny.Sequence.Concat(_9_body, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))))); + } else { + if (((kind).Equals(Dafny.Sequence.UnicodeFromString("datatype"))) || ((kind).Equals(Dafny.Sequence.UnicodeFromString("newtype")))) { + RAST._IExpr _13_dummy; + RAST._IExpr _out3; + _out3 = (this).Error(Dafny.Sequence.UnicodeFromString("Cannot extend non-general traits"), (this).InitEmptyExpr()); + _13_dummy = _out3; + } + } + RAST._IModDecl _14_x; + _14_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _10_fullTraitPath, RAST.Type.create_TypeApp(_0_genSelfPath, rTypeParams), Dafny.Sequence.UnicodeFromString(""), _9_body)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_14_x)); + Dafny.ISequence _15_upcastTraitToImplement = Dafny.Sequence.Empty; + Dafny.ISequence _16_upcastTraitFn = Dafny.Sequence.Empty; + if ((_5_traitType).is_GeneralTrait) { + Dafny.ISequence _rhs0 = Dafny.Sequence.UnicodeFromString("UpcastBox"); + Dafny.ISequence _rhs1 = Dafny.Sequence.UnicodeFromString("UpcastStructBoxFn!"); + _15_upcastTraitToImplement = _rhs0; + _16_upcastTraitFn = _rhs1; + } else { + Dafny.ISequence _rhs2 = (this).Upcast; + Dafny.ISequence _rhs3 = (this).UpcastFnMacro; + _15_upcastTraitToImplement = _rhs2; + _16_upcastTraitFn = _rhs3; + } + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(_15_upcastTraitToImplement)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_10_fullTraitPath))), RAST.Type.create_TypeApp(_0_genSelfPath, rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel(_16_upcastTraitFn)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_10_fullTraitPath))))))))); + } + goto after_match0; + } + } + } + { + } + after_match0: ; + continue_0: ; + } + after_0: ; + return s; + } public Dafny.ISequence GenClass(DAST._IClass c, Dafny.ISequence> path) { Dafny.ISequence s = Dafny.Sequence.Empty; Dafny.ISequence _0_typeParamsSeq; Dafny.ISequence _1_rTypeParams; Dafny.ISequence _2_rTypeParamsDecls; - Dafny.ISequence _3_whereConstraints; Dafny.ISequence _out0; Dafny.ISequence _out1; Dafny.ISequence _out2; - Dafny.ISequence _out3; - (this).GenTypeParameters((c).dtor_typeParams, out _out0, out _out1, out _out2, out _out3); + (this).GenTypeParameters((c).dtor_typeParams, out _out0, out _out1, out _out2); _0_typeParamsSeq = _out0; _1_rTypeParams = _out1; _2_rTypeParamsDecls = _out2; - _3_whereConstraints = _out3; - Dafny.ISequence _4_constrainedTypeParams; - _4_constrainedTypeParams = RAST.TypeParamDecl.ToStringMultiple(_2_rTypeParamsDecls, Dafny.Sequence.Concat(RAST.__default.IND, RAST.__default.IND)); - Dafny.ISequence _5_fields; - _5_fields = Dafny.Sequence.FromElements(); - Dafny.ISequence _6_fieldInits; - _6_fieldInits = Dafny.Sequence.FromElements(); - Dafny.ISet> _7_usedTypeParams; - _7_usedTypeParams = Dafny.Set>.FromElements(); + Dafny.ISequence _3_constrainedTypeParams; + _3_constrainedTypeParams = RAST.TypeParamDecl.ToStringMultiple(_2_rTypeParamsDecls, Dafny.Sequence.Concat(RAST.__default.IND, RAST.__default.IND)); + Dafny.ISequence _4_fields; + _4_fields = Dafny.Sequence.FromElements(); + Dafny.ISequence _5_fieldInits; + _5_fieldInits = Dafny.Sequence.FromElements(); + Dafny.ISet> _6_usedTypeParams; + _6_usedTypeParams = Dafny.Set>.FromElements(); BigInteger _hi0 = new BigInteger(((c).dtor_fields).Count); - for (BigInteger _8_fieldI = BigInteger.Zero; _8_fieldI < _hi0; _8_fieldI++) { - DAST._IField _9_field; - _9_field = ((c).dtor_fields).Select(_8_fieldI); - RAST._IField _10_rfield; - RAST._IAssignIdentifier _11_fieldInit; - Dafny.ISet> _12_fieldUsedTypeParams; - RAST._IField _out4; - RAST._IAssignIdentifier _out5; - Dafny.ISet> _out6; - (this).GenField(_9_field, out _out4, out _out5, out _out6); - _10_rfield = _out4; - _11_fieldInit = _out5; - _12_fieldUsedTypeParams = _out6; - _5_fields = Dafny.Sequence.Concat(_5_fields, Dafny.Sequence.FromElements(_10_rfield)); - _6_fieldInits = Dafny.Sequence.Concat(_6_fieldInits, Dafny.Sequence.FromElements(_11_fieldInit)); - _7_usedTypeParams = Dafny.Set>.Union(_7_usedTypeParams, _12_fieldUsedTypeParams); + for (BigInteger _7_fieldI = BigInteger.Zero; _7_fieldI < _hi0; _7_fieldI++) { + DAST._IField _8_field; + _8_field = ((c).dtor_fields).Select(_7_fieldI); + RAST._IField _9_rfield; + RAST._IAssignIdentifier _10_fieldInit; + Dafny.ISet> _11_fieldUsedTypeParams; + RAST._IField _out3; + RAST._IAssignIdentifier _out4; + Dafny.ISet> _out5; + (this).GenField(_8_field, out _out3, out _out4, out _out5); + _9_rfield = _out3; + _10_fieldInit = _out4; + _11_fieldUsedTypeParams = _out5; + _4_fields = Dafny.Sequence.Concat(_4_fields, Dafny.Sequence.FromElements(_9_rfield)); + _5_fieldInits = Dafny.Sequence.Concat(_5_fieldInits, Dafny.Sequence.FromElements(_10_fieldInit)); + _6_usedTypeParams = Dafny.Set>.Union(_6_usedTypeParams, _11_fieldUsedTypeParams); } BigInteger _hi1 = new BigInteger(((c).dtor_typeParams).Count); - for (BigInteger _13_typeParamI = BigInteger.Zero; _13_typeParamI < _hi1; _13_typeParamI++) { - DAST._IType _14_typeArg; - RAST._ITypeParamDecl _15_typeParam; - DAST._IType _out7; - RAST._ITypeParamDecl _out8; - (this).GenTypeParam(((c).dtor_typeParams).Select(_13_typeParamI), out _out7, out _out8); - _14_typeArg = _out7; - _15_typeParam = _out8; - RAST._IType _16_rTypeArg; - RAST._IType _out9; - _out9 = (this).GenType(_14_typeArg, Defs.GenTypeContext.@default()); - _16_rTypeArg = _out9; - if ((_7_usedTypeParams).Contains((_15_typeParam).dtor_name)) { + for (BigInteger _12_typeParamI = BigInteger.Zero; _12_typeParamI < _hi1; _12_typeParamI++) { + DAST._IType _13_typeArg; + RAST._ITypeParamDecl _14_typeParam; + DAST._IType _out6; + RAST._ITypeParamDecl _out7; + (this).GenTypeParam(((c).dtor_typeParams).Select(_12_typeParamI), out _out6, out _out7); + _13_typeArg = _out6; + _14_typeParam = _out7; + RAST._IType _15_rTypeArg; + RAST._IType _out8; + _out8 = (this).GenType(_13_typeArg, Defs.GenTypeContext.@default()); + _15_rTypeArg = _out8; + if ((_6_usedTypeParams).Contains((_14_typeParam).dtor_name)) { goto continue_0; } - _5_fields = Dafny.Sequence.Concat(_5_fields, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_13_typeParamI)), RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_16_rTypeArg)))))); - _6_fieldInits = Dafny.Sequence.Concat(_6_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_13_typeParamI)), (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsExpr()))); + _4_fields = Dafny.Sequence.Concat(_4_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(_12_typeParamI)), RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_15_rTypeArg)))))); + _5_fieldInits = Dafny.Sequence.Concat(_5_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_12_typeParamI)), (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsExpr()))); continue_0: ; } after_0: ; + Dafny.ISequence _16_className; Defs._IExternAttribute _17_extern; - _17_extern = Defs.__default.ExtractExtern((c).dtor_attributes, (c).dtor_name); - Dafny.ISequence _18_className = Dafny.Sequence.Empty; - if ((_17_extern).is_SimpleExtern) { - _18_className = (_17_extern).dtor_overrideName; - } else { - _18_className = Defs.__default.escapeName((c).dtor_name); - if ((_17_extern).is_AdvancedExtern) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("Multi-argument externs not supported for classes yet")); - } - } - RAST._IStruct _19_struct; - _19_struct = RAST.Struct.create(Dafny.Sequence>.FromElements(), _18_className, _2_rTypeParamsDecls, RAST.Fields.create_NamedFields(_5_fields)); + Dafny.ISequence _out9; + Defs._IExternAttribute _out10; + (this).GetName((c).dtor_attributes, (c).dtor_name, Dafny.Sequence.UnicodeFromString("classes"), out _out9, out _out10); + _16_className = _out9; + _17_extern = _out10; + RAST._IStruct _18_struct; + _18_struct = RAST.Struct.create(Dafny.Sequence>.FromElements(), _16_className, _2_rTypeParamsDecls, RAST.Fields.create_NamedFields(_4_fields)); s = Dafny.Sequence.FromElements(); if ((_17_extern).is_NoExtern) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(_19_struct))); - } - Dafny.ISequence _20_implBody; - Dafny.IMap>,Dafny.ISequence> _21_traitBodies; - Dafny.ISequence _out10; - Dafny.IMap>,Dafny.ISequence> _out11; - (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(path, Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Class(), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out10, out _out11); - _20_implBody = _out10; - _21_traitBodies = _out11; - if (((_17_extern).is_NoExtern) && (!(_18_className).Equals(Dafny.Sequence.UnicodeFromString("_default")))) { - _20_implBody = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create((this).allocate__fn, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((this).Object(RAST.__default.SelfOwned)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel((this).allocate)).AsExpr()).ApplyType1(RAST.__default.SelfOwned)).Apply0())))), _20_implBody); - } - RAST._IType _22_selfTypeForImpl = RAST.Type.Default(); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(_18_struct))); + } + Dafny.ISequence _19_implBody; + Dafny.IMap>,Dafny.ISequence> _20_traitBodies; + Dafny.ISequence _out11; + Dafny.IMap>,Dafny.ISequence> _out12; + (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(path, Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Class(), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out11, out _out12); + _19_implBody = _out11; + _20_traitBodies = _out12; + if (((_17_extern).is_NoExtern) && (!(_16_className).Equals(Dafny.Sequence.UnicodeFromString("_default")))) { + _19_implBody = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create((this).allocate__fn, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((this).Object(RAST.__default.SelfOwned)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel((this).allocate)).AsExpr()).ApplyType1(RAST.__default.SelfOwned)).Apply0())))), _19_implBody); + } + RAST._IType _21_selfTypeForImpl = RAST.Type.Default(); if (((_17_extern).is_NoExtern) || ((_17_extern).is_UnsupportedExtern)) { - _22_selfTypeForImpl = RAST.Type.create_TIdentifier(_18_className); + _21_selfTypeForImpl = RAST.Type.create_TIdentifier(_16_className); } else if ((_17_extern).is_AdvancedExtern) { - _22_selfTypeForImpl = (((RAST.__default.crate).MSels((_17_extern).dtor_enclosingModule)).MSel((_17_extern).dtor_overrideName)).AsType(); + _21_selfTypeForImpl = (((RAST.__default.crate).MSels((_17_extern).dtor_enclosingModule)).MSel((_17_extern).dtor_overrideName)).AsType(); } else if ((_17_extern).is_SimpleExtern) { - _22_selfTypeForImpl = RAST.Type.create_TIdentifier((_17_extern).dtor_overrideName); + _21_selfTypeForImpl = RAST.Type.create_TIdentifier((_17_extern).dtor_overrideName); } - if ((new BigInteger((_20_implBody).Count)).Sign == 1) { - RAST._IImpl _23_i; - _23_i = RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(_22_selfTypeForImpl, _1_rTypeParams), _3_whereConstraints, _20_implBody); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_23_i))); + if ((new BigInteger((_19_implBody).Count)).Sign == 1) { + RAST._IImpl _22_i; + _22_i = RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(_21_selfTypeForImpl, _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), _19_implBody); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_22_i))); } - Dafny.ISequence _24_testMethods; - _24_testMethods = Dafny.Sequence.FromElements(); - if ((_18_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { + Dafny.ISequence _23_testMethods; + _23_testMethods = Dafny.Sequence.FromElements(); + if ((_16_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { BigInteger _hi2 = new BigInteger(((c).dtor_body).Count); - for (BigInteger _25_i = BigInteger.Zero; _25_i < _hi2; _25_i++) { - DAST._IMethod _26_m; - DAST._IMethod _source0 = ((c).dtor_body).Select(_25_i); + for (BigInteger _24_i = BigInteger.Zero; _24_i < _hi2; _24_i++) { + DAST._IMethod _25_m; + DAST._IMethod _source0 = ((c).dtor_body).Select(_24_i); { - DAST._IMethod _27_m = _source0; - _26_m = _27_m; + DAST._IMethod _26_m = _source0; + _25_m = _26_m; } after_match0: ; - if (((this).HasAttribute((_26_m).dtor_attributes, Dafny.Sequence.UnicodeFromString("test"))) && ((new BigInteger(((_26_m).dtor_params).Count)).Sign == 0)) { - Dafny.ISequence _28_fnName; - _28_fnName = Defs.__default.escapeName((_26_m).dtor_name); - _24_testMethods = Dafny.Sequence.Concat(_24_testMethods, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[test]")), RAST.Visibility.create_PUB(), RAST.Fn.create(_28_fnName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_default"))).FSel(_28_fnName)).Apply(Dafny.Sequence.FromElements()))))))); + if (((this).HasAttribute((_25_m).dtor_attributes, Dafny.Sequence.UnicodeFromString("test"))) && ((new BigInteger(((_25_m).dtor_params).Count)).Sign == 0)) { + Dafny.ISequence _27_fnName; + _27_fnName = Defs.__default.escapeName((_25_m).dtor_name); + _23_testMethods = Dafny.Sequence.Concat(_23_testMethods, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[test]")), RAST.Visibility.create_PUB(), RAST.Fn.create(_27_fnName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_default"))).FSel(_27_fnName)).Apply(Dafny.Sequence.FromElements()))))))); } } - s = Dafny.Sequence.Concat(s, _24_testMethods); + s = Dafny.Sequence.Concat(s, _23_testMethods); } - RAST._IType _29_genSelfPath; - RAST._IType _out12; - _out12 = (this).GenPathType(path); - _29_genSelfPath = _out12; - if (!(_18_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(RAST.__default.AnyTrait))), RAST.Type.create_TypeApp(_29_genSelfPath, _1_rTypeParams), _3_whereConstraints, Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(RAST.__default.AnyTrait))))))))); + RAST._IType _28_genSelfPath; + RAST._IType _out13; + _out13 = (this).GenPathType(path); + _28_genSelfPath = _out13; + if (!(_16_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(RAST.__default.AnyTrait))), RAST.Type.create_TypeApp(_28_genSelfPath, _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(RAST.__default.AnyTrait))))))))); } - Dafny.ISequence _30_superClasses; - if ((_18_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { - _30_superClasses = Dafny.Sequence.FromElements(); + Dafny.ISequence _29_superTraitTypes; + if ((_16_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { + _29_superTraitTypes = Dafny.Sequence.FromElements(); } else { - _30_superClasses = (c).dtor_superClasses; + _29_superTraitTypes = (c).dtor_superTraitTypes; } - BigInteger _hi3 = new BigInteger((_30_superClasses).Count); - for (BigInteger _31_i = BigInteger.Zero; _31_i < _hi3; _31_i++) { - DAST._IType _32_superClass; - _32_superClass = (_30_superClasses).Select(_31_i); - DAST._IType _source1 = _32_superClass; - { - if (_source1.is_UserDefined) { - DAST._IResolvedType resolved0 = _source1.dtor_resolved; - Dafny.ISequence> _33_traitPath = resolved0.dtor_path; - Dafny.ISequence _34_typeArgs = resolved0.dtor_typeArgs; - DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; - if (kind0.is_Trait) { - Dafny.ISequence> _35_properMethods = resolved0.dtor_properMethods; - { - RAST._IType _36_pathStr; - RAST._IType _out13; - _out13 = (this).GenPathType(_33_traitPath); - _36_pathStr = _out13; - Dafny.ISequence _37_typeArgs; - Dafny.ISequence _out14; - _out14 = (this).GenTypeArgs(_34_typeArgs, Defs.GenTypeContext.@default()); - _37_typeArgs = _out14; - Dafny.ISequence _38_body; - _38_body = Dafny.Sequence.FromElements(); - if ((_21_traitBodies).Contains(_33_traitPath)) { - _38_body = Dafny.Map>, Dafny.ISequence>.Select(_21_traitBodies,_33_traitPath); - } - RAST._IType _39_traitType; - _39_traitType = RAST.Type.create_TypeApp(_36_pathStr, _37_typeArgs); - if (!((_17_extern).is_NoExtern)) { - if (((new BigInteger((_38_body).Count)).Sign == 0) && ((new BigInteger((_35_properMethods).Count)).Sign != 0)) { - goto continue_1; - } - if ((new BigInteger((_38_body).Count)) != (new BigInteger((_35_properMethods).Count))) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the class "), RAST.__default.SeqToString>(path, ((System.Func, Dafny.ISequence>)((_40_s) => { - return ((_40_s)); -})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_39_traitType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" are marked {:extern} and some are not.")), Dafny.Sequence.UnicodeFromString(" For the Rust compiler, please make all methods (")), RAST.__default.SeqToString>(_35_properMethods, ((System.Func, Dafny.ISequence>)((_41_s) => { - return (_41_s); -})), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(") bodiless and mark as {:extern} and implement them in a Rust file, ")), Dafny.Sequence.UnicodeFromString("or mark none of them as {:extern} and implement them in Dafny. ")), Dafny.Sequence.UnicodeFromString("Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible."))); - } - } - RAST._IModDecl _42_x; - _42_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, _39_traitType, RAST.Type.create_TypeApp(_29_genSelfPath, _1_rTypeParams), _3_whereConstraints, _38_body)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_42_x)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_39_traitType))), RAST.Type.create_TypeApp(_29_genSelfPath, _1_rTypeParams), _3_whereConstraints, Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_39_traitType))))))))); - } - goto after_match1; - } - } - } - { - } - after_match1: ; - continue_1: ; - } - after_1: ; + Dafny.ISequence _30_superTraitImplementations; + Dafny.ISequence _out14; + _out14 = (this).GenTraitImplementations(path, _1_rTypeParams, _2_rTypeParamsDecls, _29_superTraitTypes, _20_traitBodies, _17_extern, Dafny.Sequence.UnicodeFromString("class")); + _30_superTraitImplementations = _out14; + s = Dafny.Sequence.Concat(s, _30_superTraitImplementations); return s; } public Dafny.ISequence GenTrait(DAST._ITrait t, Dafny.ISequence> containingPath) @@ -465,8 +509,8 @@ public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAss Dafny.ISequence s = Dafny.Sequence.Empty; Dafny.ISequence _0_typeParamsSeq; _0_typeParamsSeq = Dafny.Sequence.FromElements(); - Dafny.ISequence _1_typeParamDecls; - _1_typeParamDecls = Dafny.Sequence.FromElements(); + Dafny.ISequence _1_rTypeParamsDecls; + _1_rTypeParamsDecls = Dafny.Sequence.FromElements(); Dafny.ISequence _2_typeParams; _2_typeParams = Dafny.Sequence.FromElements(); if ((new BigInteger(((t).dtor_typeParams).Count)).Sign == 1) { @@ -482,7 +526,7 @@ public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAss _5_typeArg = _out0; _6_typeParamDecl = _out1; _0_typeParamsSeq = Dafny.Sequence.Concat(_0_typeParamsSeq, Dafny.Sequence.FromElements(_5_typeArg)); - _1_typeParamDecls = Dafny.Sequence.Concat(_1_typeParamDecls, Dafny.Sequence.FromElements(_6_typeParamDecl)); + _1_rTypeParamsDecls = Dafny.Sequence.Concat(_1_rTypeParamsDecls, Dafny.Sequence.FromElements(_6_typeParamDecl)); RAST._IType _7_typeParam; RAST._IType _out2; _out2 = (this).GenType(_5_typeArg, Defs.GenTypeContext.@default()); @@ -492,24 +536,51 @@ public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAss } Dafny.ISequence> _8_fullPath; _8_fullPath = Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((t).dtor_name)); - Dafny.ISequence _9_implBody; - Dafny.IMap>,Dafny.ISequence> _10___v6; + Dafny.ISequence _9_name; + _9_name = Defs.__default.escapeName((t).dtor_name); + RAST._IType _10_traitFulltype; + _10_traitFulltype = (RAST.Type.create_TIdentifier(_9_name)).Apply(_2_typeParams); + RAST._IExpr _11_traitFullExpr; + _11_traitFullExpr = (RAST.Expr.create_Identifier(_9_name)).ApplyType(_2_typeParams); + Dafny.ISequence _12_implBody; + Dafny.IMap>,Dafny.ISequence> _13___v5; Dafny.ISequence _out3; Dafny.IMap>,Dafny.ISequence> _out4; - (this).GenClassImplBody((t).dtor_body, true, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_8_fullPath, Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Trait(DAST.TraitType.create_ObjectTrait()), (t).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out3, out _out4); - _9_implBody = _out3; - _10___v6 = _out4; - Dafny.ISequence _11_parents; - _11_parents = Dafny.Sequence.FromElements(); + (this).GenClassImplBody((t).dtor_body, true, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_8_fullPath, Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Trait((t).dtor_traitType), (t).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out3, out _out4); + _12_implBody = _out3; + _13___v5 = _out4; + if (((t).dtor_traitType).is_GeneralTrait) { + _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())))); + } + Dafny.ISequence _14_parents; + _14_parents = Dafny.Sequence.FromElements(); + Dafny.ISequence _15_upcastImplemented; + _15_upcastImplemented = Dafny.Sequence.FromElements(); BigInteger _hi1 = new BigInteger(((t).dtor_parents).Count); - for (BigInteger _12_i = BigInteger.Zero; _12_i < _hi1; _12_i++) { - RAST._IType _13_tpe; + for (BigInteger _16_i = BigInteger.Zero; _16_i < _hi1; _16_i++) { + DAST._IType _17_parentTyp; + _17_parentTyp = ((t).dtor_parents).Select(_16_i); + RAST._IType _18_parentTpe; RAST._IType _out5; - _out5 = (this).GenType(((t).dtor_parents).Select(_12_i), Defs.GenTypeContext.ForTraitParents()); - _13_tpe = _out5; - _11_parents = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_11_parents, Dafny.Sequence.FromElements(_13_tpe)), Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply1(RAST.Type.create_DynType(_13_tpe)))); + _out5 = (this).GenType(_17_parentTyp, Defs.GenTypeContext.ForTraitParents()); + _18_parentTpe = _out5; + _14_parents = Dafny.Sequence.Concat(_14_parents, Dafny.Sequence.FromElements(_18_parentTpe)); + Dafny.ISequence _19_upcastTrait; + if ((_17_parentTyp).IsGeneralTrait()) { + _19_upcastTrait = Dafny.Sequence.UnicodeFromString("UpcastBox"); + } else { + _19_upcastTrait = (this).Upcast; + } + _14_parents = Dafny.Sequence.Concat(_14_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_19_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)))); + if ((_17_parentTyp).IsGeneralTrait()) { + _15_upcastImplemented = Dafny.Sequence.Concat(_15_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBoxFn"))).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(_18_parentTpe)))))))); + } + } + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_rTypeParamsDecls, _10_traitFulltype, _14_parents, _12_implBody))); + if (((t).dtor_traitType).is_GeneralTrait) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_typeParamDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(Defs.__default.escapeName((t).dtor_name)), _2_typeParams), _11_parents, _9_implBody))); + s = Dafny.Sequence.Concat(s, _15_upcastImplemented); return s; } public Dafny.ISequence GenNewtype(DAST._INewtype c, Dafny.ISequence> path) @@ -518,72 +589,69 @@ public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAss Dafny.ISequence _0_typeParamsSeq; Dafny.ISequence _1_rTypeParams; Dafny.ISequence _2_rTypeParamsDecls; - Dafny.ISequence _3_whereConstraints; Dafny.ISequence _out0; Dafny.ISequence _out1; Dafny.ISequence _out2; - Dafny.ISequence _out3; - (this).GenTypeParameters((c).dtor_typeParams, out _out0, out _out1, out _out2, out _out3); + (this).GenTypeParameters((c).dtor_typeParams, out _out0, out _out1, out _out2); _0_typeParamsSeq = _out0; _1_rTypeParams = _out1; _2_rTypeParamsDecls = _out2; - _3_whereConstraints = _out3; - Dafny.ISequence _4_constrainedTypeParams; - _4_constrainedTypeParams = RAST.TypeParamDecl.ToStringMultiple(_2_rTypeParamsDecls, Dafny.Sequence.Concat(RAST.__default.IND, RAST.__default.IND)); - RAST._IType _5_wrappedType = RAST.Type.Default(); - Std.Wrappers._IOption _6_rustType; - _6_rustType = Defs.__default.NewtypeRangeToUnwrappedBoundedRustType((c).dtor_base, (c).dtor_range); - if ((_6_rustType).is_Some) { - _5_wrappedType = (_6_rustType).dtor_value; + Dafny.ISequence _3_constrainedTypeParams; + _3_constrainedTypeParams = RAST.TypeParamDecl.ToStringMultiple(_2_rTypeParamsDecls, Dafny.Sequence.Concat(RAST.__default.IND, RAST.__default.IND)); + RAST._IType _4_wrappedType = RAST.Type.Default(); + Std.Wrappers._IOption _5_rustType; + _5_rustType = Defs.__default.NewtypeRangeToUnwrappedBoundedRustType((c).dtor_base, (c).dtor_range); + if ((_5_rustType).is_Some) { + _4_wrappedType = (_5_rustType).dtor_value; } else { - RAST._IType _out4; - _out4 = (this).GenType((c).dtor_base, Defs.GenTypeContext.@default()); - _5_wrappedType = _out4; - } - DAST._IType _7_newtypeType; - _7_newtypeType = DAST.Type.create_UserDefined(DAST.ResolvedType.create(path, _0_typeParamsSeq, DAST.ResolvedTypeBase.create_Newtype((c).dtor_base, (c).dtor_range, false), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())); - Dafny.ISequence _8_newtypeName; - _8_newtypeName = Defs.__default.escapeName((c).dtor_name); - RAST._IType _9_resultingType; - _9_resultingType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_8_newtypeName), _1_rTypeParams); - Dafny.ISequence _10_attributes = Dafny.Sequence.Empty; + RAST._IType _out3; + _out3 = (this).GenType((c).dtor_base, Defs.GenTypeContext.@default()); + _4_wrappedType = _out3; + } + DAST._IType _6_newtypeType; + _6_newtypeType = DAST.Type.create_UserDefined(DAST.ResolvedType.create(path, _0_typeParamsSeq, DAST.ResolvedTypeBase.create_Newtype((c).dtor_base, (c).dtor_range, false), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())); + Dafny.ISequence _7_newtypeName; + _7_newtypeName = Defs.__default.escapeName((c).dtor_name); + RAST._IType _8_resultingType; + _8_resultingType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams); + Dafny.ISequence _9_attributes = Dafny.Sequence.Empty; if (Defs.__default.IsNewtypeCopy((c).dtor_range)) { - _10_attributes = Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq, Copy)]"); + _9_attributes = Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq, Copy)]"); } else { - _10_attributes = Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq)]"); + _9_attributes = Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq)]"); } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(_10_attributes, Dafny.Sequence.UnicodeFromString("#[repr(transparent)]")), _8_newtypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _5_wrappedType)))))); - RAST._IExpr _11_fnBody = RAST.Expr.Default(); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(_9_attributes, Dafny.Sequence.UnicodeFromString("#[repr(transparent)]")), _7_newtypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _4_wrappedType)))))); + RAST._IExpr _10_fnBody = RAST.Expr.Default(); Std.Wrappers._IOption _source0 = (c).dtor_witnessExpr; { if (_source0.is_Some) { - DAST._IExpression _12_e = _source0.dtor_value; + DAST._IExpression _11_e = _source0.dtor_value; { - DAST._IExpression _13_e; - _13_e = DAST.Expression.create_Convert(_12_e, (c).dtor_base, _7_newtypeType); - RAST._IExpr _14_r; - Defs._IOwnership _15___v7; - Dafny.ISet> _16___v8; - RAST._IExpr _out5; - Defs._IOwnership _out6; - Dafny.ISet> _out7; - (this).GenExpr(_13_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); - _14_r = _out5; + DAST._IExpression _12_e; + _12_e = DAST.Expression.create_Convert(_11_e, (c).dtor_base, _6_newtypeType); + RAST._IExpr _13_r; + Defs._IOwnership _14___v6; + Dafny.ISet> _15___v7; + RAST._IExpr _out4; + Defs._IOwnership _out5; + Dafny.ISet> _out6; + (this).GenExpr(_12_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out4, out _out5, out _out6); + _13_r = _out4; + _14___v6 = _out5; _15___v7 = _out6; - _16___v8 = _out7; - _11_fnBody = _14_r; + _10_fnBody = _13_r; } goto after_match0; } } { { - _11_fnBody = (RAST.Expr.create_Identifier(_8_newtypeName)).Apply1(RAST.__default.std__default__Default__default); + _10_fnBody = (RAST.Expr.create_Identifier(_7_newtypeName)).Apply1(RAST.__default.std__default__Default__default); } } after_match0: ; - RAST._IImplMember _17_body; - _17_body = RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("default"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_11_fnBody))); + RAST._IImplMember _16_body; + _16_body = RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("default"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_10_fnBody))); Std.Wrappers._IOption _source1 = (c).dtor_constraint; { if (_source1.is_None) { @@ -592,50 +660,50 @@ public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAss } { DAST._INewtypeConstraint value0 = _source1.dtor_value; - DAST._IFormal _18_formal = value0.dtor_variable; - Dafny.ISequence _19_constraintStmts = value0.dtor_constraintStmts; - RAST._IExpr _20_rStmts; - Dafny.ISet> _21___v9; - Defs._IEnvironment _22_newEnv; - RAST._IExpr _out8; - Dafny.ISet> _out9; - Defs._IEnvironment _out10; - (this).GenStmts(_19_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out8, out _out9, out _out10); - _20_rStmts = _out8; - _21___v9 = _out9; - _22_newEnv = _out10; - Dafny.ISequence _23_rFormals; - Dafny.ISequence _out11; - _out11 = (this).GenParams(Dafny.Sequence.FromElements(_18_formal), false); - _23_rFormals = _out11; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _9_resultingType, _3_whereConstraints, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _23_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_20_rStmts)))))))); + DAST._IFormal _17_formal = value0.dtor_variable; + Dafny.ISequence _18_constraintStmts = value0.dtor_constraintStmts; + RAST._IExpr _19_rStmts; + Dafny.ISet> _20___v8; + Defs._IEnvironment _21_newEnv; + RAST._IExpr _out7; + Dafny.ISet> _out8; + Defs._IEnvironment _out9; + (this).GenStmts(_18_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out7, out _out8, out _out9); + _19_rStmts = _out7; + _20___v8 = _out8; + _21_newEnv = _out9; + Dafny.ISequence _22_rFormals; + Dafny.ISequence _out10; + _out10 = (this).GenParams(Dafny.Sequence.FromElements(_17_formal), false); + _22_rFormals = _out10; + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _22_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_19_rStmts)))))))); } after_match1: ; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _9_resultingType, _3_whereConstraints, Dafny.Sequence.FromElements(_17_body))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _9_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsType(), _9_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Target"), _5_wrappedType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("deref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(((RAST.Path.create_Self()).MSel(Dafny.Sequence.UnicodeFromString("Target"))).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _9_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_from_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("o"), RAST.Type.create_Borrowed(_5_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("transmute"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("o"))))))))))))); - Dafny.ISequence _24_rTypeParamsDeclsWithHash; - _24_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_24_rTypeParamsDeclsWithHash, _9_resultingType, (((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))).Sel(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _8_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(_16_body))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _8_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsType(), _8_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Target"), _4_wrappedType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("deref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(((RAST.Path.create_Self()).MSel(Dafny.Sequence.UnicodeFromString("Target"))).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_from_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("o"), RAST.Type.create_Borrowed(_4_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("transmute"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("o"))))))))))))); + Dafny.ISequence _23_rTypeParamsDeclsWithHash; + _23_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_23_rTypeParamsDeclsWithHash, _8_resultingType, (((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))).Sel(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))); if (((c).dtor_range).HasArithmeticOperations()) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.OpsImpl(new Dafny.Rune('+'), _2_rTypeParamsDecls, _9_resultingType, _8_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('-'), _2_rTypeParamsDecls, _9_resultingType, _8_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('*'), _2_rTypeParamsDecls, _9_resultingType, _8_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('/'), _2_rTypeParamsDecls, _9_resultingType, _8_newtypeName), Defs.__default.PartialOrdImpl(_2_rTypeParamsDecls, _9_resultingType, _8_newtypeName))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.OpsImpl(new Dafny.Rune('+'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('-'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('*'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('/'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.PartialOrdImpl(_2_rTypeParamsDecls, _8_resultingType, _7_newtypeName))); } if (((c).dtor_range).is_Bool) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.UnaryOpsImpl(new Dafny.Rune('!'), _2_rTypeParamsDecls, _9_resultingType, _8_newtypeName))); - } - Dafny.ISequence _25_implementation; - Dafny.IMap>,Dafny.ISequence> _26_traitBodies; - Dafny.ISequence _out12; - Dafny.IMap>,Dafny.ISequence> _out13; - (this).GenClassImplBody((c).dtor_classItems, false, _7_newtypeType, _0_typeParamsSeq, out _out12, out _out13); - _25_implementation = _out12; - _26_traitBodies = _out13; - if ((new BigInteger((_26_traitBodies).Count)).Sign == 1) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.UnaryOpsImpl(new Dafny.Rune('!'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName))); + } + Dafny.ISequence _24_implementation; + Dafny.IMap>,Dafny.ISequence> _25_traitBodies; + Dafny.ISequence _out11; + Dafny.IMap>,Dafny.ISequence> _out12; + (this).GenClassImplBody((c).dtor_classItems, false, _6_newtypeType, _0_typeParamsSeq, out _out11, out _out12); + _24_implementation = _out11; + _25_traitBodies = _out12; + if ((new BigInteger((_25_traitBodies).Count)).Sign == 1) { (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("No support for trait in newtypes yet")); } - if ((new BigInteger((_25_implementation).Count)).Sign == 1) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_8_newtypeName), _1_rTypeParams), _3_whereConstraints, _25_implementation)))); + if ((new BigInteger((_24_implementation).Count)).Sign == 1) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), _24_implementation)))); } return s; } @@ -645,53 +713,50 @@ public void GenField(DAST._IField field, out RAST._IField rfield, out RAST._IAss Dafny.ISequence _0_typeParamsSeq; Dafny.ISequence _1_rTypeParams; Dafny.ISequence _2_rTypeParamsDecls; - Dafny.ISequence _3_whereConstraints; Dafny.ISequence _out0; Dafny.ISequence _out1; Dafny.ISequence _out2; - Dafny.ISequence _out3; - (this).GenTypeParameters((c).dtor_typeParams, out _out0, out _out1, out _out2, out _out3); + (this).GenTypeParameters((c).dtor_typeParams, out _out0, out _out1, out _out2); _0_typeParamsSeq = _out0; _1_rTypeParams = _out1; _2_rTypeParamsDecls = _out2; - _3_whereConstraints = _out3; - Dafny.ISequence _4_synonymTypeName; - _4_synonymTypeName = Defs.__default.escapeName((c).dtor_name); - RAST._IType _5_resultingType; - RAST._IType _out4; - _out4 = (this).GenType((c).dtor_base, Defs.GenTypeContext.@default()); - _5_resultingType = _out4; - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TypeDecl(RAST.TypeSynonym.create(Dafny.Sequence>.FromElements(), _4_synonymTypeName, _2_rTypeParamsDecls, _5_resultingType))); - Dafny.ISequence _6_defaultConstrainedTypeParams; - _6_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + Dafny.ISequence _3_synonymTypeName; + _3_synonymTypeName = Defs.__default.escapeName((c).dtor_name); + RAST._IType _4_resultingType; + RAST._IType _out3; + _out3 = (this).GenType((c).dtor_base, Defs.GenTypeContext.@default()); + _4_resultingType = _out3; + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TypeDecl(RAST.TypeSynonym.create(Dafny.Sequence>.FromElements(), _3_synonymTypeName, _2_rTypeParamsDecls, _4_resultingType))); + Dafny.ISequence _5_defaultConstrainedTypeParams; + _5_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); Std.Wrappers._IOption _source0 = (c).dtor_witnessExpr; { if (_source0.is_Some) { - DAST._IExpression _7_e = _source0.dtor_value; + DAST._IExpression _6_e = _source0.dtor_value; { - RAST._IExpr _8_rStmts; - Dafny.ISet> _9___v10; - Defs._IEnvironment _10_newEnv; - RAST._IExpr _out5; - Dafny.ISet> _out6; - Defs._IEnvironment _out7; - (this).GenStmts((c).dtor_witnessStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out5, out _out6, out _out7); - _8_rStmts = _out5; - _9___v10 = _out6; - _10_newEnv = _out7; - RAST._IExpr _11_rExpr; - Defs._IOwnership _12___v11; - Dafny.ISet> _13___v12; - RAST._IExpr _out8; - Defs._IOwnership _out9; - Dafny.ISet> _out10; - (this).GenExpr(_7_e, Defs.SelfInfo.create_NoSelf(), _10_newEnv, Defs.Ownership.create_OwnershipOwned(), out _out8, out _out9, out _out10); - _11_rExpr = _out8; + RAST._IExpr _7_rStmts; + Dafny.ISet> _8___v9; + Defs._IEnvironment _9_newEnv; + RAST._IExpr _out4; + Dafny.ISet> _out5; + Defs._IEnvironment _out6; + (this).GenStmts((c).dtor_witnessStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out4, out _out5, out _out6); + _7_rStmts = _out4; + _8___v9 = _out5; + _9_newEnv = _out6; + RAST._IExpr _10_rExpr; + Defs._IOwnership _11___v10; + Dafny.ISet> _12___v11; + RAST._IExpr _out7; + Defs._IOwnership _out8; + Dafny.ISet> _out9; + (this).GenExpr(_6_e, Defs.SelfInfo.create_NoSelf(), _9_newEnv, Defs.Ownership.create_OwnershipOwned(), out _out7, out _out8, out _out9); + _10_rExpr = _out7; + _11___v10 = _out8; _12___v11 = _out9; - _13___v12 = _out10; - Dafny.ISequence _14_constantName; - _14_constantName = Defs.__default.escapeName(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_init_"), ((c).dtor_name))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_14_constantName, _6_defaultConstrainedTypeParams, Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_5_resultingType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((_8_rStmts).Then(_11_rExpr))))))); + Dafny.ISequence _13_constantName; + _13_constantName = Defs.__default.escapeName(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_init_"), ((c).dtor_name))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_13_constantName, _5_defaultConstrainedTypeParams, Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_4_resultingType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((_7_rStmts).Then(_10_rExpr))))))); } goto after_match0; } @@ -808,24 +873,26 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) { return (this).write(RAST.Expr.create_LiteralString(s, false, false), false); } - public Dafny.ISequence GenDatatype(DAST._IDatatype c) + public Dafny.ISequence GenDatatype(DAST._IDatatype c, Dafny.ISequence> path) { Dafny.ISequence s = Dafny.Sequence.Empty; Dafny.ISequence _0_typeParamsSeq; Dafny.ISequence _1_rTypeParams; Dafny.ISequence _2_rTypeParamsDecls; - Dafny.ISequence _3_whereConstraints; Dafny.ISequence _out0; Dafny.ISequence _out1; Dafny.ISequence _out2; - Dafny.ISequence _out3; - (this).GenTypeParameters((c).dtor_typeParams, out _out0, out _out1, out _out2, out _out3); + (this).GenTypeParameters((c).dtor_typeParams, out _out0, out _out1, out _out2); _0_typeParamsSeq = _out0; _1_rTypeParams = _out1; _2_rTypeParamsDecls = _out2; - _3_whereConstraints = _out3; - Dafny.ISequence _4_datatypeName; - _4_datatypeName = Defs.__default.escapeName((c).dtor_name); + Dafny.ISequence _3_datatypeName; + Defs._IExternAttribute _4_extern; + Dafny.ISequence _out3; + Defs._IExternAttribute _out4; + (this).GetName((c).dtor_attributes, (c).dtor_name, Dafny.Sequence.UnicodeFromString("datatypes"), out _out3, out _out4); + _3_datatypeName = _out3; + _4_extern = _out4; Dafny.ISequence _5_ctors; _5_ctors = Dafny.Sequence.FromElements(); Dafny.ISequence _6_variances; @@ -846,7 +913,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _13_isNumeric = false; if ((new BigInteger(((_11_ctor).dtor_args).Count)).Sign == 0) { RAST._IExpr _14_instantiation; - _14_instantiation = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_11_ctor).dtor_name)), Dafny.Sequence.FromElements()); + _14_instantiation = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_3_datatypeName)).FSel(Defs.__default.escapeName((_11_ctor).dtor_name)), Dafny.Sequence.FromElements()); if ((this).IsRcWrapped((c).dtor_attributes)) { _14_instantiation = RAST.__default.RcNew(_14_instantiation); } @@ -857,9 +924,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) DAST._IDatatypeDtor _16_dtor; _16_dtor = ((_11_ctor).dtor_args).Select(_15_j); RAST._IType _17_formalType; - RAST._IType _out4; - _out4 = (this).GenType(((_16_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); - _17_formalType = _out4; + RAST._IType _out5; + _out5 = (this).GenType(((_16_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); + _17_formalType = _out5; _9_usedTypeParams = (this).GatherTypeParamNames(_9_usedTypeParams, _17_formalType); Dafny.ISequence _18_formalName; _18_formalName = Defs.__default.escapeVar(((_16_dtor).dtor_formal).dtor_name); @@ -898,14 +965,11 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _23_selfPath = Dafny.Sequence>.FromElements((c).dtor_name); Dafny.ISequence _24_implBodyRaw; Dafny.IMap>,Dafny.ISequence> _25_traitBodies; - Dafny.ISequence _out5; - Dafny.IMap>,Dafny.ISequence> _out6; - (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_23_selfPath, _0_typeParamsSeq, DAST.ResolvedTypeBase.create_Datatype(_6_variances), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out5, out _out6); - _24_implBodyRaw = _out5; - _25_traitBodies = _out6; - if ((new BigInteger((_25_traitBodies).Count)).Sign == 1) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("No support for trait in datatypes yet")); - } + Dafny.ISequence _out6; + Dafny.IMap>,Dafny.ISequence> _out7; + (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_23_selfPath, _0_typeParamsSeq, DAST.ResolvedTypeBase.create_Datatype(_6_variances), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out6, out _out7); + _24_implBodyRaw = _out6; + _25_traitBodies = _out7; Dafny.ISequence _26_implBody; _26_implBody = _24_implBodyRaw; Dafny.ISet> _27_emittedFields; @@ -923,9 +987,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) if (!((_27_emittedFields).Contains(_32_callName))) { _27_emittedFields = Dafny.Set>.Union(_27_emittedFields, Dafny.Set>.FromElements(_32_callName)); RAST._IType _33_formalType; - RAST._IType _out7; - _out7 = (this).GenType(((_31_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); - _33_formalType = _out7; + RAST._IType _out8; + _out8 = (this).GenType(((_31_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); + _33_formalType = _out8; Dafny.ISequence _34_cases; _34_cases = Dafny.Sequence.FromElements(); BigInteger _hi4 = new BigInteger(((c).dtor_ctors).Count); @@ -933,7 +997,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) DAST._IDatatypeCtor _36_ctor2; _36_ctor2 = ((c).dtor_ctors).Select(_35_k); Dafny.ISequence _37_pattern; - _37_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), Defs.__default.escapeName((_36_ctor2).dtor_name)); + _37_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), Defs.__default.escapeName((_36_ctor2).dtor_name)); RAST._IExpr _38_rhs = RAST.Expr.Default(); Std.Wrappers._IOption> _39_hasMatchingField; _39_hasMatchingField = Std.Wrappers.Option>.create_None(); @@ -977,7 +1041,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _34_cases = Dafny.Sequence.Concat(_34_cases, Dafny.Sequence.FromElements(_45_ctorMatch)); } if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_20_unusedTypeParams).Count)).Sign == 1)) { - _34_cases = Dafny.Sequence.Concat(_34_cases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + _34_cases = Dafny.Sequence.Concat(_34_cases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); } RAST._IExpr _46_methodBody; _46_methodBody = RAST.Expr.create_Match(RAST.__default.self, _34_cases); @@ -1006,19 +1070,19 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _55_typeParam = ((c).dtor_typeParams).Select(_54_typeI); DAST._IType _56_typeArg; RAST._ITypeParamDecl _57_rTypeParamDecl; - DAST._IType _out8; - RAST._ITypeParamDecl _out9; - (this).GenTypeParam(_55_typeParam, out _out8, out _out9); - _56_typeArg = _out8; - _57_rTypeParamDecl = _out9; + DAST._IType _out9; + RAST._ITypeParamDecl _out10; + (this).GenTypeParam(_55_typeParam, out _out9, out _out10); + _56_typeArg = _out9; + _57_rTypeParamDecl = _out10; RAST._IType _58_rTypeArg; - RAST._IType _out10; - _out10 = (this).GenType(_56_typeArg, Defs.GenTypeContext.@default()); - _58_rTypeArg = _out10; + RAST._IType _out11; + _out11 = (this).GenType(_56_typeArg, Defs.GenTypeContext.@default()); + _58_rTypeArg = _out11; _53_types = Dafny.Sequence.Concat(_53_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_58_rTypeArg)))); if (((_54_typeI) < (new BigInteger((_6_variances).Count))) && (((_6_variances).Select(_54_typeI)).is_Nonvariant)) { _47_coerceTypes = Dafny.Sequence.Concat(_47_coerceTypes, Dafny.Sequence.FromElements(_58_rTypeArg)); - goto continue_3_0; + goto continue_2_0; } DAST._ITypeArgDecl _59_coerceTypeParam; DAST._ITypeArgDecl _60_dt__update__tmp_h0 = _55_typeParam; @@ -1026,16 +1090,16 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _59_coerceTypeParam = DAST.TypeArgDecl.create(_61_dt__update_hname_h0, (_60_dt__update__tmp_h0).dtor_bounds, (_60_dt__update__tmp_h0).dtor_variance); DAST._IType _62_coerceTypeArg; RAST._ITypeParamDecl _63_rCoerceTypeParamDecl; - DAST._IType _out11; - RAST._ITypeParamDecl _out12; - (this).GenTypeParam(_59_coerceTypeParam, out _out11, out _out12); - _62_coerceTypeArg = _out11; - _63_rCoerceTypeParamDecl = _out12; + DAST._IType _out12; + RAST._ITypeParamDecl _out13; + (this).GenTypeParam(_59_coerceTypeParam, out _out12, out _out13); + _62_coerceTypeArg = _out12; + _63_rCoerceTypeParamDecl = _out13; _50_coerceMap = Dafny.Map.Merge(_50_coerceMap, Dafny.Map.FromElements(new Dafny.Pair(_56_typeArg, _62_coerceTypeArg))); RAST._IType _64_rCoerceType; - RAST._IType _out13; - _out13 = (this).GenType(_62_coerceTypeArg, Defs.GenTypeContext.@default()); - _64_rCoerceType = _out13; + RAST._IType _out14; + _out14 = (this).GenType(_62_coerceTypeArg, Defs.GenTypeContext.@default()); + _64_rCoerceType = _out14; _51_rCoerceMap = Dafny.Map.Merge(_51_rCoerceMap, Dafny.Map.FromElements(new Dafny.Pair(_58_rTypeArg, _64_rCoerceType))); _47_coerceTypes = Dafny.Sequence.Concat(_47_coerceTypes, Dafny.Sequence.FromElements(_64_rCoerceType)); _48_rCoerceTypeParams = Dafny.Sequence.Concat(_48_rCoerceTypeParams, Dafny.Sequence.FromElements(_63_rCoerceTypeParamDecl)); @@ -1043,9 +1107,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _65_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_54_typeI)); _52_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_52_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_58_rTypeArg, _64_rCoerceType), (RAST.Expr.create_Identifier(_65_coerceFormal)).Clone()))); _49_coerceArguments = Dafny.Sequence.Concat(_49_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_65_coerceFormal, RAST.__default.Rc(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_58_rTypeArg), _64_rCoerceType)), RAST.__default.StaticTrait))))); - continue_3_0: ; + continue_2_0: ; } - after_3_0: ; + after_2_0: ; if ((new BigInteger((_20_unusedTypeParams).Count)).Sign == 1) { _5_ctors = Dafny.Sequence.Concat(_5_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_66_tpe) => { return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _66_tpe); @@ -1054,7 +1118,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } bool _67_cIsEq; _67_cIsEq = (this).DatatypeIsEq(c); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create(((_67_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _4_datatypeName, _2_rTypeParamsDecls, _5_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams), _3_whereConstraints, _26_implBody))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create(((_67_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _3_datatypeName, _2_rTypeParamsDecls, _5_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), _26_implBody))); Dafny.ISequence _68_printImplBodyCases; _68_printImplBodyCases = Dafny.Sequence.FromElements(); Dafny.ISequence _69_hashImplBodyCases; @@ -1114,9 +1178,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _76_printRhs = (_76_printRhs).Then((((_84_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_83_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); RAST._IExpr _85_coerceRhsArg = RAST.Expr.Default(); RAST._IType _86_formalTpe; - RAST._IType _out14; - _out14 = (this).GenType(_84_formalType, Defs.GenTypeContext.@default()); - _86_formalTpe = _out14; + RAST._IType _out15; + _out15 = (this).GenType(_84_formalType, Defs.GenTypeContext.@default()); + _86_formalTpe = _out15; DAST._IType _87_newFormalType; _87_newFormalType = (_84_formalType).Replace(_50_coerceMap); RAST._IType _88_newFormalTpe; @@ -1128,13 +1192,13 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _90_coercionFunction = (_89_upcastConverter).dtor_value; _85_coerceRhsArg = (_90_coercionFunction).Apply1(RAST.Expr.create_Identifier(_83_patternName)); } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_81_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_81_j)), Dafny.Sequence.UnicodeFromString(" of ")), _3_datatypeName)); _85_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); } _78_coerceRhsArgs = Dafny.Sequence.Concat(_78_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_83_patternName, _85_coerceRhsArg))); } RAST._IExpr _91_coerceRhs; - _91_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_72_ctor).dtor_name)), _78_coerceRhsArgs); + _91_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_3_datatypeName)).FSel(Defs.__default.escapeName((_72_ctor).dtor_name)), _78_coerceRhsArgs); if (_79_isNumeric) { _73_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_73_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _80_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); } else { @@ -1144,13 +1208,13 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _76_printRhs = (_76_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); } _76_printRhs = (_76_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); - _68_printImplBodyCases = Dafny.Sequence.Concat(_68_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_76_printRhs)))); - _69_hashImplBodyCases = Dafny.Sequence.Concat(_69_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_77_hashRhs)))); - _70_coerceImplBodyCases = Dafny.Sequence.Concat(_70_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_91_coerceRhs)))); + _68_printImplBodyCases = Dafny.Sequence.Concat(_68_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_76_printRhs)))); + _69_hashImplBodyCases = Dafny.Sequence.Concat(_69_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_77_hashRhs)))); + _70_coerceImplBodyCases = Dafny.Sequence.Concat(_70_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_91_coerceRhs)))); } if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_20_unusedTypeParams).Count)).Sign == 1)) { Dafny.ISequence _92_extraCases; - _92_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + _92_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); _68_printImplBodyCases = Dafny.Sequence.Concat(_68_printImplBodyCases, _92_extraCases); _69_hashImplBodyCases = Dafny.Sequence.Concat(_69_hashImplBodyCases, _92_extraCases); _70_coerceImplBodyCases = Dafny.Sequence.Concat(_70_coerceImplBodyCases, _92_extraCases); @@ -1166,12 +1230,12 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) RAST._IExpr _97_hashImplBody; _97_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _69_hashImplBodyCases); RAST._IType _98_datatypeType; - _98_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams); + _98_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_2_rTypeParamsDecls, _98_datatypeType, _1_rTypeParams), Defs.__default.PrintImpl(_2_rTypeParamsDecls, _98_datatypeType, _1_rTypeParams, _96_printImplBody))); if ((new BigInteger((_48_rCoerceTypeParams).Count)).Sign == 1) { RAST._IExpr _99_coerceImplBody; _99_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _70_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_2_rTypeParamsDecls, _4_datatypeName, _98_datatypeType, _48_rCoerceTypeParams, _49_coerceArguments, _47_coerceTypes, _99_coerceImplBody))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_2_rTypeParamsDecls, _3_datatypeName, _98_datatypeType, _48_rCoerceTypeParams, _49_coerceArguments, _47_coerceTypes, _99_coerceImplBody))); } if ((new BigInteger((_8_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { RAST._IType _100_instantiationType; @@ -1183,12 +1247,12 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_2_rTypeParamsDecls, _98_datatypeType, _100_instantiationType, _8_singletonConstructors))); } if (_67_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_94_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements())))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_94_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements())))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_95_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams), _97_hashImplBody))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_95_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), _97_hashImplBody))); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { RAST._IExpr _101_structName; - _101_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + _101_structName = (RAST.Expr.create_Identifier(_3_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); Dafny.ISequence _102_structAssignments; _102_structAssignments = Dafny.Sequence.FromElements(); BigInteger _hi9 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); @@ -1200,12 +1264,17 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) Dafny.ISequence _105_defaultConstrainedTypeParams; _105_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); RAST._IType _106_fullType; - _106_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _1_rTypeParams); + _106_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams); if (_67_cIsEq) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_105_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, _106_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(_106_fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_101_structName, _102_structAssignments))))))))); } s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsType()).Apply1(_106_fullType), RAST.Type.create_Borrowed(_106_fullType), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self)))))))); } + Dafny.ISequence _107_superTraitImplementations; + Dafny.ISequence _out16; + _out16 = (this).GenTraitImplementations(path, _1_rTypeParams, _2_rTypeParamsDecls, (c).dtor_superTraitTypes, _25_traitBodies, _4_extern, Dafny.Sequence.UnicodeFromString("datatype")); + _107_superTraitImplementations = _out16; + s = Dafny.Sequence.Concat(s, _107_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -1895,15 +1964,15 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e after_match1: ; _32_env = Defs.Environment.create(Dafny.Sequence>.Concat(_34_preAssignNames, _1_paramNames), Dafny.Map, RAST._IType>.Merge(_35_preAssignTypes, _2_paramTypes)); RAST._IExpr _48_body; - Dafny.ISet> _49___v21; - Defs._IEnvironment _50___v22; + Dafny.ISet> _49___v20; + Defs._IEnvironment _50___v21; RAST._IExpr _out6; Dafny.ISet> _out7; Defs._IEnvironment _out8; (this).GenStmts((m).dtor_body, _8_selfIdent, _32_env, true, _36_earlyReturn, out _out6, out _out7, out _out8); _48_body = _out6; - _49___v21 = _out7; - _50___v22 = _out8; + _49___v20 = _out7; + _50___v21 = _out8; _31_fBody = Std.Wrappers.Option.create_Some((_33_preBody).Then(_48_body)); } else { _32_env = Defs.Environment.create(_1_paramNames, _2_paramTypes); @@ -2130,14 +2199,14 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Defs._ISelfInfo BigInteger _hi0 = new BigInteger((_12_indices).Count); for (BigInteger _18_i = BigInteger.Zero; _18_i < _hi0; _18_i++) { RAST._IExpr _19_idx; - Defs._IOwnership _20___v31; + Defs._IOwnership _20___v30; Dafny.ISet> _21_recIdentsIdx; RAST._IExpr _out6; Defs._IOwnership _out7; Dafny.ISet> _out8; (this).GenExpr((_12_indices).Select(_18_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out6, out _out7, out _out8); _19_idx = _out6; - _20___v31 = _out7; + _20___v30 = _out7; _21_recIdentsIdx = _out8; Dafny.ISequence _22_varName; _22_varName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("__idx"), Std.Strings.__default.OfNat(_18_i)); @@ -2181,15 +2250,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _5_isAssignedVar = Defs.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { RAST._IExpr _6_rhs; - Defs._IOwnership _7___v32; - Dafny.ISet> _8___v33; + Defs._IOwnership _7___v31; + Dafny.ISet> _8___v32; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr(DAST.Expression.create_InitializationValue(((_2_field).dtor_formal).dtor_typ), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); _6_rhs = _out1; - _7___v32 = _out2; - _8___v33 = _out3; + _7___v31 = _out2; + _8___v32 = _out3; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); Dafny.ISequence _9_update__if__uninit; if ((_2_field).dtor_isConstant) { @@ -2282,14 +2351,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _23_expression = _source0.dtor_value; { RAST._IExpr _24_exprGen; - Defs._IOwnership _25___v34; + Defs._IOwnership _25___v33; Dafny.ISet> _26_exprIdents; RAST._IExpr _out11; Defs._IOwnership _out12; Dafny.ISet> _out13; (this).GenExpr(_23_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out11, out _out12, out _out13); _24_exprGen = _out11; - _25___v34 = _out12; + _25___v33 = _out12; _26_exprIdents = _out13; if ((_22_lhs).is_Ident) { Dafny.ISequence _27_rustId; @@ -2339,14 +2408,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _37_elsDafny = _source0.dtor_els; { RAST._IExpr _38_cond; - Defs._IOwnership _39___v35; + Defs._IOwnership _39___v34; Dafny.ISet> _40_recIdents; RAST._IExpr _out18; Defs._IOwnership _out19; Dafny.ISet> _out20; (this).GenExpr(_35_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out18, out _out19, out _out20); _38_cond = _out18; - _39___v35 = _out19; + _39___v34 = _out19; _40_recIdents = _out20; Dafny.ISequence _41_condString; _41_condString = (_38_cond)._ToString(Defs.__default.IND); @@ -2407,14 +2476,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _54_body = _source0.dtor_body; { RAST._IExpr _55_cond; - Defs._IOwnership _56___v36; + Defs._IOwnership _56___v35; Dafny.ISet> _57_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr(_53_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _55_cond = _out30; - _56___v36 = _out31; + _56___v35 = _out31; _57_recIdents = _out32; readIdents = _57_recIdents; RAST._IExpr _58_bodyExpr; @@ -2442,14 +2511,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _64_body = _source0.dtor_body; { RAST._IExpr _65_over; - Defs._IOwnership _66___v37; + Defs._IOwnership _66___v36; Dafny.ISet> _67_recIdents; RAST._IExpr _out36; Defs._IOwnership _out37; Dafny.ISet> _out38; (this).GenExpr(_63_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out36, out _out37, out _out38); _65_over = _out36; - _66___v37 = _out37; + _66___v36 = _out37; _67_recIdents = _out38; if (((_63_overExpr).is_MapBoundedPool) || ((_63_overExpr).is_SetBoundedPool)) { _65_over = ((_65_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); @@ -2513,15 +2582,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _76_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { RAST._IExpr _77_selfClone; - Defs._IOwnership _78___v38; - Dafny.ISet> _79___v39; + Defs._IOwnership _78___v37; + Dafny.ISet> _79___v38; RAST._IExpr _out43; Defs._IOwnership _out44; Dafny.ISet> _out45; (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out43, out _out44, out _out45); _77_selfClone = _out43; - _78___v38 = _out44; - _79___v39 = _out45; + _78___v37 = _out44; + _79___v38 = _out45; generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_77_selfClone))); if (((_76_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { _76_oldEnv = (_76_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); @@ -2541,15 +2610,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv goto continue_4_0; } RAST._IExpr _83_paramInit; - Defs._IOwnership _84___v40; - Dafny.ISet> _85___v41; + Defs._IOwnership _84___v39; + Dafny.ISet> _85___v40; RAST._IExpr _out46; Defs._IOwnership _out47; Dafny.ISet> _out48; (this).GenIdent(_82_param, selfIdent, _76_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out46, out _out47, out _out48); _83_paramInit = _out46; - _84___v40 = _out47; - _85___v41 = _out48; + _84___v39 = _out47; + _85___v40 = _out48; Dafny.ISequence _86_recVar; _86_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_81_paramI)); generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _86_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_83_paramInit))); @@ -2655,14 +2724,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { RAST._IExpr _108_onExpr; - Defs._IOwnership _109___v46; + Defs._IOwnership _109___v45; Dafny.ISet> _110_enclosingIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_91_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out64, out _out65, out _out66); _108_onExpr = _out64; - _109___v46 = _out65; + _109___v45 = _out65; _110_enclosingIdents = _out66; readIdents = Dafny.Set>.Union(readIdents, _110_enclosingIdents); Dafny.ISequence _111_renderedName; @@ -2752,14 +2821,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _121_exprDafny = _source0.dtor_expr; { RAST._IExpr _122_expr; - Defs._IOwnership _123___v56; + Defs._IOwnership _123___v55; Dafny.ISet> _124_recIdents; RAST._IExpr _out68; Defs._IOwnership _out69; Dafny.ISet> _out70; (this).GenExpr(_121_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out68, out _out69, out _out70); _122_expr = _out68; - _123___v56 = _out69; + _123___v55 = _out69; _124_recIdents = _out70; readIdents = _124_recIdents; if (isLast) { @@ -2789,15 +2858,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv BigInteger _hi3 = new BigInteger((_125_rustIdents).Count); for (BigInteger _127_i = BigInteger.Zero; _127_i < _hi3; _127_i++) { RAST._IExpr _128_rIdent; - Defs._IOwnership _129___v57; - Dafny.ISet> _130___v58; + Defs._IOwnership _129___v56; + Dafny.ISet> _130___v57; RAST._IExpr _out71; Defs._IOwnership _out72; Dafny.ISet> _out73; (this).GenIdent((_125_rustIdents).Select(_127_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out71, out _out72, out _out73); _128_rIdent = _out71; - _129___v57 = _out72; - _130___v58 = _out73; + _129___v56 = _out72; + _130___v57 = _out73; _126_tupleArgs = Dafny.Sequence.Concat(_126_tupleArgs, Dafny.Sequence.FromElements(_128_rIdent)); } if ((new BigInteger((_126_tupleArgs).Count)) == (BigInteger.One)) { @@ -2881,11 +2950,20 @@ public void FromOwnership(RAST._IExpr r, Defs._IOwnership ownership, Defs._IOwne resultingOwnership = _out1; return ; } else if (object.Equals(ownership, Defs.Ownership.create_OwnershipOwnedBox())) { - RAST._IExpr _out2; - Defs._IOwnership _out3; - (this).FromOwned(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("*"), r, DAST.Format.UnaryOpFormat.create_NoFormat()), expectedOwnership, out _out2, out _out3); - @out = _out2; - resultingOwnership = _out3; + if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipBorrowed())) { + @out = ((r).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); + resultingOwnership = Defs.Ownership.create_OwnershipBorrowed(); + } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())) { + resultingOwnership = Defs.Ownership.create_OwnershipOwnedBox(); + @out = r; + } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipBorrowedMut())) { + @out = ((r).Sel(Dafny.Sequence.UnicodeFromString("as_mut"))).Apply0(); + resultingOwnership = Defs.Ownership.create_OwnershipBorrowedMut(); + } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) { + resultingOwnership = Defs.Ownership.create_OwnershipOwnedBox(); + @out = r; + } + return ; } else if ((object.Equals(ownership, Defs.Ownership.create_OwnershipBorrowed())) || (object.Equals(ownership, Defs.Ownership.create_OwnershipBorrowedMut()))) { if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) { resultingOwnership = Defs.Ownership.create_OwnershipOwned(); @@ -2903,6 +2981,7 @@ public void FromOwnership(RAST._IExpr r, Defs._IOwnership ownership, Defs._IOwne resultingOwnership = Defs.Ownership.create_OwnershipBorrowedMut(); @out = RAST.__default.BorrowMut(r); } + return ; } else { } } @@ -2914,9 +2993,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. DAST._IExpression _source0 = e; { if (_source0.is_Literal) { - DAST._ILiteral _h230 = _source0.dtor_Literal_a0; - if (_h230.is_BoolLiteral) { - bool _0_b = _h230.dtor_BoolLiteral_a0; + DAST._ILiteral _h300 = _source0.dtor_Literal_a0; + if (_h300.is_BoolLiteral) { + bool _0_b = _h300.dtor_BoolLiteral_a0; { RAST._IExpr _out0; Defs._IOwnership _out1; @@ -2932,10 +3011,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h231 = _source0.dtor_Literal_a0; - if (_h231.is_IntLiteral) { - Dafny.ISequence _1_i = _h231.dtor_IntLiteral_a0; - DAST._IType _2_t = _h231.dtor_IntLiteral_a1; + DAST._ILiteral _h301 = _source0.dtor_Literal_a0; + if (_h301.is_IntLiteral) { + Dafny.ISequence _1_i = _h301.dtor_IntLiteral_a0; + DAST._IType _2_t = _h301.dtor_IntLiteral_a1; { DAST._IType _source1 = _2_t; { @@ -2978,11 +3057,11 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h232 = _source0.dtor_Literal_a0; - if (_h232.is_DecLiteral) { - Dafny.ISequence _5_n = _h232.dtor_DecLiteral_a0; - Dafny.ISequence _6_d = _h232.dtor_DecLiteral_a1; - DAST._IType _7_t = _h232.dtor_DecLiteral_a2; + DAST._ILiteral _h302 = _source0.dtor_Literal_a0; + if (_h302.is_DecLiteral) { + Dafny.ISequence _5_n = _h302.dtor_DecLiteral_a0; + Dafny.ISequence _6_d = _h302.dtor_DecLiteral_a1; + DAST._IType _7_t = _h302.dtor_DecLiteral_a2; { DAST._IType _source2 = _7_t; { @@ -3021,10 +3100,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h233 = _source0.dtor_Literal_a0; - if (_h233.is_StringLiteral) { - Dafny.ISequence _10_l = _h233.dtor_StringLiteral_a0; - bool _11_verbatim = _h233.dtor_verbatim; + DAST._ILiteral _h303 = _source0.dtor_Literal_a0; + if (_h303.is_StringLiteral) { + Dafny.ISequence _10_l = _h303.dtor_StringLiteral_a0; + bool _11_verbatim = _h303.dtor_verbatim; { r = (((RAST.__default.dafny__runtime).MSel((this).string__of)).AsExpr()).Apply1(RAST.Expr.create_LiteralString(_10_l, false, _11_verbatim)); RAST._IExpr _out8; @@ -3041,9 +3120,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h234 = _source0.dtor_Literal_a0; - if (_h234.is_CharLiteralUTF16) { - BigInteger _12_c = _h234.dtor_CharLiteralUTF16_a0; + DAST._ILiteral _h304 = _source0.dtor_Literal_a0; + if (_h304.is_CharLiteralUTF16) { + BigInteger _12_c = _h304.dtor_CharLiteralUTF16_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(_12_c)); r = RAST.Expr.create_TypeAscription(r, RAST.Type.create_U16()); @@ -3062,9 +3141,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h235 = _source0.dtor_Literal_a0; - if (_h235.is_CharLiteral) { - Dafny.Rune _13_c = _h235.dtor_CharLiteral_a0; + DAST._ILiteral _h305 = _source0.dtor_Literal_a0; + if (_h305.is_CharLiteral) { + Dafny.Rune _13_c = _h305.dtor_CharLiteral_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(new BigInteger((_13_c).Value))); if (!(((this).charType).is_UTF32)) { @@ -3086,8 +3165,8 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } } { - DAST._ILiteral _h236 = _source0.dtor_Literal_a0; - DAST._IType _14_tpe = _h236.dtor_Null_a0; + DAST._ILiteral _h306 = _source0.dtor_Literal_a0; + DAST._IType _14_tpe = _h306.dtor_Null_a0; { RAST._IType _15_tpeGen; RAST._IType _out14; @@ -3204,24 +3283,24 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ _10_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); } RAST._IExpr _11_left; - Defs._IOwnership _12___v59; + Defs._IOwnership _12___v58; Dafny.ISet> _13_recIdentsL; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(_4_lExpr, selfIdent, env, _9_expectedLeftOwnership, out _out0, out _out1, out _out2); _11_left = _out0; - _12___v59 = _out1; + _12___v58 = _out1; _13_recIdentsL = _out2; RAST._IExpr _14_right; - Defs._IOwnership _15___v60; + Defs._IOwnership _15___v59; Dafny.ISet> _16_recIdentsR; RAST._IExpr _out3; Defs._IOwnership _out4; Dafny.ISet> _out5; (this).GenExpr(_5_rExpr, selfIdent, env, _10_expectedRightOwnership, out _out3, out _out4, out _out5); _14_right = _out3; - _15___v60 = _out4; + _15___v59 = _out4; _16_recIdentsR = _out5; DAST._IBinOp _source0 = _0_op; { @@ -3882,92 +3961,106 @@ public bool SameTypesButDifferentTypeParameters(DAST._IType fromType, RAST._ITyp var _pat_let_tv4 = typeParams; if (object.Equals(fromTpe, toTpe)) { return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("upcast_id"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(fromTpe))).Apply0()); + } else if ((toTpe).IsBox()) { + RAST._IType _0_toTpeUnderlying = (toTpe).BoxUnderlying(); + if (!((_0_toTpeUnderlying).is_DynType)) { + return Std.Wrappers.Result,RAST._IExpr>>>.create_Failure(_System.Tuple5,RAST._IExpr>>.create(fromType, fromTpe, toType, toTpe, typeParams)); + } else if ((fromTpe).IsBox()) { + RAST._IType _1_fromTpeUnderlying = (fromTpe).BoxUnderlying(); + if (!((_1_fromTpeUnderlying).is_DynType)) { + return Std.Wrappers.Result,RAST._IExpr>>>.create_Failure(_System.Tuple5,RAST._IExpr>>.create(fromType, fromTpe, toType, toTpe, typeParams)); + } else { + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("upcast_box_box"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_1_fromTpeUnderlying, _0_toTpeUnderlying))).Apply0()); + } + } else { + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("upcast_box"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(fromTpe, _0_toTpeUnderlying))).Apply0()); + } } else if (((fromTpe).IsObjectOrPointer()) && ((toTpe).IsObjectOrPointer())) { - if (!(((toTpe).ObjectOrPointerUnderlying()).is_DynType)) { + RAST._IType _2_toTpeUnderlying = (toTpe).ObjectOrPointerUnderlying(); + if (!((_2_toTpeUnderlying).is_DynType)) { return Std.Wrappers.Result,RAST._IExpr>>>.create_Failure(_System.Tuple5,RAST._IExpr>>.create(fromType, fromTpe, toType, toTpe, typeParams)); } else { - RAST._IType _0_fromTpeUnderlying = (fromTpe).ObjectOrPointerUnderlying(); - RAST._IType _1_toTpeUnderlying = (toTpe).ObjectOrPointerUnderlying(); - return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((((RAST.__default.dafny__runtime).MSel((this).upcast)).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_0_fromTpeUnderlying, _1_toTpeUnderlying))).Apply0()); + RAST._IType _3_fromTpeUnderlying = (fromTpe).ObjectOrPointerUnderlying(); + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((((RAST.__default.dafny__runtime).MSel((this).upcast)).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_3_fromTpeUnderlying, _2_toTpeUnderlying))).Apply0()); } } else if ((typeParams).Contains(_System.Tuple2.create(fromTpe, toTpe))) { return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(Dafny.Map<_System._ITuple2, RAST._IExpr>.Select(typeParams,_System.Tuple2.create(fromTpe, toTpe))); } else if (((fromTpe).IsRc()) && ((toTpe).IsRc())) { - Std.Wrappers._IResult,RAST._IExpr>>> _2_valueOrError0 = (this).UpcastConversionLambda(fromType, (fromTpe).RcUnderlying(), toType, (toTpe).RcUnderlying(), typeParams); - if ((_2_valueOrError0).IsFailure()) { - return (_2_valueOrError0).PropagateFailure(); + Std.Wrappers._IResult,RAST._IExpr>>> _4_valueOrError0 = (this).UpcastConversionLambda(fromType, (fromTpe).RcUnderlying(), toType, (toTpe).RcUnderlying(), typeParams); + if ((_4_valueOrError0).IsFailure()) { + return (_4_valueOrError0).PropagateFailure(); } else { - RAST._IExpr _3_lambda = (_2_valueOrError0).Extract(); + RAST._IExpr _5_lambda = (_4_valueOrError0).Extract(); if ((fromType).is_Arrow) { - return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(_3_lambda); + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(_5_lambda); } else { - return Std.Wrappers.Result,RAST._IExpr>>>.create_Success((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("rc_coerce"))).AsExpr()).Apply1(_3_lambda)); + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("rc_coerce"))).AsExpr()).Apply1(_5_lambda)); } } } else if ((this).SameTypesButDifferentTypeParameters(fromType, fromTpe, toType, toTpe)) { - Dafny.ISequence _4_indices = ((((fromType).is_UserDefined) && ((((fromType).dtor_resolved).dtor_kind).is_Datatype)) ? (Std.Collections.Seq.__default.Filter(Dafny.Helpers.Id>>((_5_fromTpe, _6_fromType) => ((System.Func)((_7_i) => { - return ((((_7_i).Sign != -1) && ((_7_i) < (new BigInteger(((_5_fromTpe).dtor_arguments).Count)))) ? (!(((_7_i).Sign != -1) && ((_7_i) < (new BigInteger(((((_6_fromType).dtor_resolved).dtor_kind).dtor_variances).Count)))) || (!((((((_6_fromType).dtor_resolved).dtor_kind).dtor_variances).Select(_7_i)).is_Nonvariant))) : (false)); + Dafny.ISequence _6_indices = ((((fromType).is_UserDefined) && ((((fromType).dtor_resolved).dtor_kind).is_Datatype)) ? (Std.Collections.Seq.__default.Filter(Dafny.Helpers.Id>>((_7_fromTpe, _8_fromType) => ((System.Func)((_9_i) => { + return ((((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((_7_fromTpe).dtor_arguments).Count)))) ? (!(((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((((_8_fromType).dtor_resolved).dtor_kind).dtor_variances).Count)))) || (!((((((_8_fromType).dtor_resolved).dtor_kind).dtor_variances).Select(_9_i)).is_Nonvariant))) : (false)); })))(fromTpe, fromType), ((System.Func>) (() => { BigInteger dim14 = new BigInteger(((fromTpe).dtor_arguments).Count); var arr14 = new BigInteger[Dafny.Helpers.ToIntChecked(dim14, "array size exceeds memory limit")]; for (int i14 = 0; i14 < dim14; i14++) { - var _8_i = (BigInteger) i14; - arr14[(int)(_8_i)] = _8_i; + var _10_i = (BigInteger) i14; + arr14[(int)(_10_i)] = _10_i; } return Dafny.Sequence.FromArray(arr14); }))())) : (((System.Func>) (() => { BigInteger dim15 = new BigInteger(((fromTpe).dtor_arguments).Count); var arr15 = new BigInteger[Dafny.Helpers.ToIntChecked(dim15, "array size exceeds memory limit")]; for (int i15 = 0; i15 < dim15; i15++) { - var _9_i = (BigInteger) i15; - arr15[(int)(_9_i)] = _9_i; + var _11_i = (BigInteger) i15; + arr15[(int)(_11_i)] = _11_i; } return Dafny.Sequence.FromArray(arr15); }))())); - Std.Wrappers._IResult, _System._ITuple5,RAST._IExpr>>> _10_valueOrError1 = (this).SeqResultToResultSeq,RAST._IExpr>>>(((System.Func,RAST._IExpr>>>>>) (() => { - BigInteger dim16 = new BigInteger((_4_indices).Count); + Std.Wrappers._IResult, _System._ITuple5,RAST._IExpr>>> _12_valueOrError1 = (this).SeqResultToResultSeq,RAST._IExpr>>>(((System.Func,RAST._IExpr>>>>>) (() => { + BigInteger dim16 = new BigInteger((_6_indices).Count); var arr16 = new Std.Wrappers._IResult,RAST._IExpr>>>[Dafny.Helpers.ToIntChecked(dim16, "array size exceeds memory limit")]; for (int i16 = 0; i16 < dim16; i16++) { - var _11_j = (BigInteger) i16; - arr16[(int)(_11_j)] = Dafny.Helpers.Let,RAST._IExpr>>>>((_4_indices).Select(_11_j), _pat_let27_0 => Dafny.Helpers.Let,RAST._IExpr>>>>(_pat_let27_0, _12_i => (this).UpcastConversionLambda((((_pat_let_tv0).dtor_resolved).dtor_typeArgs).Select(_12_i), ((_pat_let_tv1).dtor_arguments).Select(_12_i), (((_pat_let_tv2).dtor_resolved).dtor_typeArgs).Select(_12_i), ((_pat_let_tv3).dtor_arguments).Select(_12_i), _pat_let_tv4))); + var _13_j = (BigInteger) i16; + arr16[(int)(_13_j)] = Dafny.Helpers.Let,RAST._IExpr>>>>((_6_indices).Select(_13_j), _pat_let27_0 => Dafny.Helpers.Let,RAST._IExpr>>>>(_pat_let27_0, _14_i => (this).UpcastConversionLambda((((_pat_let_tv0).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv1).dtor_arguments).Select(_14_i), (((_pat_let_tv2).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv3).dtor_arguments).Select(_14_i), _pat_let_tv4))); } return Dafny.Sequence,RAST._IExpr>>>>.FromArray(arr16); }))()); - if ((_10_valueOrError1).IsFailure()) { - return (_10_valueOrError1).PropagateFailure(); + if ((_12_valueOrError1).IsFailure()) { + return (_12_valueOrError1).PropagateFailure(); } else { - Dafny.ISequence _13_lambdas = (_10_valueOrError1).Extract(); + Dafny.ISequence _15_lambdas = (_12_valueOrError1).Extract(); return Std.Wrappers.Result,RAST._IExpr>>>.create_Success((((RAST.Expr.create_ExprFromType((fromTpe).dtor_baseName)).ApplyType(((System.Func>) (() => { BigInteger dim17 = new BigInteger(((fromTpe).dtor_arguments).Count); var arr17 = new RAST._IType[Dafny.Helpers.ToIntChecked(dim17, "array size exceeds memory limit")]; for (int i17 = 0; i17 < dim17; i17++) { - var _14_i = (BigInteger) i17; - arr17[(int)(_14_i)] = ((fromTpe).dtor_arguments).Select(_14_i); + var _16_i = (BigInteger) i17; + arr17[(int)(_16_i)] = ((fromTpe).dtor_arguments).Select(_16_i); } return Dafny.Sequence.FromArray(arr17); -}))())).FSel(Dafny.Sequence.UnicodeFromString("coerce"))).Apply(_13_lambdas)); +}))())).FSel(Dafny.Sequence.UnicodeFromString("coerce"))).Apply(_15_lambdas)); } } else if (((((fromTpe).IsBuiltinCollection()) && ((toTpe).IsBuiltinCollection())) && ((this).IsBuiltinCollection(fromType))) && ((this).IsBuiltinCollection(toType))) { - RAST._IType _15_newFromTpe = (fromTpe).GetBuiltinCollectionElement(); - RAST._IType _16_newToTpe = (toTpe).GetBuiltinCollectionElement(); - DAST._IType _17_newFromType = (this).GetBuiltinCollectionElement(fromType); - DAST._IType _18_newToType = (this).GetBuiltinCollectionElement(toType); - Std.Wrappers._IResult,RAST._IExpr>>> _19_valueOrError2 = (this).UpcastConversionLambda(_17_newFromType, _15_newFromTpe, _18_newToType, _16_newToTpe, typeParams); - if ((_19_valueOrError2).IsFailure()) { - return (_19_valueOrError2).PropagateFailure(); + RAST._IType _17_newFromTpe = (fromTpe).GetBuiltinCollectionElement(); + RAST._IType _18_newToTpe = (toTpe).GetBuiltinCollectionElement(); + DAST._IType _19_newFromType = (this).GetBuiltinCollectionElement(fromType); + DAST._IType _20_newToType = (this).GetBuiltinCollectionElement(toType); + Std.Wrappers._IResult,RAST._IExpr>>> _21_valueOrError2 = (this).UpcastConversionLambda(_19_newFromType, _17_newFromTpe, _20_newToType, _18_newToTpe, typeParams); + if ((_21_valueOrError2).IsFailure()) { + return (_21_valueOrError2).PropagateFailure(); } else { - RAST._IExpr _20_coerceArg = (_19_valueOrError2).Extract(); - RAST._IPath _21_collectionType = (RAST.__default.dafny__runtime).MSel(((((fromTpe).Expand()).dtor_baseName).dtor_path).dtor_name); - RAST._IExpr _22_baseType = (((((((fromTpe).Expand()).dtor_baseName).dtor_path).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("Map"))) ? (((_21_collectionType).AsExpr()).ApplyType(Dafny.Sequence.FromElements((((fromTpe).Expand()).dtor_arguments).Select(BigInteger.Zero), _15_newFromTpe))) : (((_21_collectionType).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_15_newFromTpe)))); - return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((_22_baseType).FSel(Dafny.Sequence.UnicodeFromString("coerce"))).Apply1(_20_coerceArg)); + RAST._IExpr _22_coerceArg = (_21_valueOrError2).Extract(); + RAST._IPath _23_collectionType = (RAST.__default.dafny__runtime).MSel(((((fromTpe).Expand()).dtor_baseName).dtor_path).dtor_name); + RAST._IExpr _24_baseType = (((((((fromTpe).Expand()).dtor_baseName).dtor_path).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("Map"))) ? (((_23_collectionType).AsExpr()).ApplyType(Dafny.Sequence.FromElements((((fromTpe).Expand()).dtor_arguments).Select(BigInteger.Zero), _17_newFromTpe))) : (((_23_collectionType).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_17_newFromTpe)))); + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((_24_baseType).FSel(Dafny.Sequence.UnicodeFromString("coerce"))).Apply1(_22_coerceArg)); } } else if ((((((((((fromTpe).is_DynType) && (((fromTpe).dtor_underlying).is_FnType)) && ((toTpe).is_DynType)) && (((toTpe).dtor_underlying).is_FnType)) && ((((fromTpe).dtor_underlying).dtor_arguments).Equals(((toTpe).dtor_underlying).dtor_arguments))) && ((fromType).is_Arrow)) && ((toType).is_Arrow)) && ((new BigInteger((((fromTpe).dtor_underlying).dtor_arguments).Count)) == (BigInteger.One))) && (((((fromTpe).dtor_underlying).dtor_arguments).Select(BigInteger.Zero)).is_Borrowed)) { - Std.Wrappers._IResult,RAST._IExpr>>> _23_valueOrError3 = (this).UpcastConversionLambda((fromType).dtor_result, ((fromTpe).dtor_underlying).dtor_returnType, (toType).dtor_result, ((toTpe).dtor_underlying).dtor_returnType, typeParams); - if ((_23_valueOrError3).IsFailure()) { - return (_23_valueOrError3).PropagateFailure(); + Std.Wrappers._IResult,RAST._IExpr>>> _25_valueOrError3 = (this).UpcastConversionLambda((fromType).dtor_result, ((fromTpe).dtor_underlying).dtor_returnType, (toType).dtor_result, ((toTpe).dtor_underlying).dtor_returnType, typeParams); + if ((_25_valueOrError3).IsFailure()) { + return (_25_valueOrError3).PropagateFailure(); } else { - RAST._IExpr _24_lambda = (_23_valueOrError3).Extract(); - return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("fn1_coerce"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(((((fromTpe).dtor_underlying).dtor_arguments).Select(BigInteger.Zero)).dtor_underlying, ((fromTpe).dtor_underlying).dtor_returnType, ((toTpe).dtor_underlying).dtor_returnType))).Apply1(_24_lambda)); + RAST._IExpr _26_lambda = (_25_valueOrError3).Extract(); + return Std.Wrappers.Result,RAST._IExpr>>>.create_Success(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("fn1_coerce"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(((((fromTpe).dtor_underlying).dtor_arguments).Select(BigInteger.Zero)).dtor_underlying, ((fromTpe).dtor_underlying).dtor_returnType, ((toTpe).dtor_underlying).dtor_returnType))).Apply1(_26_lambda)); } } else { return Std.Wrappers.Result,RAST._IExpr>>>.create_Failure(_System.Tuple5,RAST._IExpr>>.create(fromType, fromTpe, toType, toTpe, typeParams)); @@ -4099,6 +4192,8 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden _2_currentlyBorrowed = (env).IsBorrowed(rName); bool _3_noNeedOfClone; _3_noNeedOfClone = (env).CanReadWithoutClone(rName); + bool _4_isSelf; + _4_isSelf = (((selfIdent).is_ThisTyped) && ((selfIdent).IsSelf())) && (((selfIdent).dtor_rSelfName).Equals(rName)); if ((_1_placeboOpt).is_Some) { r = ((r).Sel(Dafny.Sequence.UnicodeFromString("read"))).Apply0(); _2_currentlyBorrowed = false; @@ -4123,22 +4218,22 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden } resultingOwnership = Defs.Ownership.create_OwnershipBorrowedMut(); } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) { - bool _4_needObjectFromRef; - _4_needObjectFromRef = ((((selfIdent).is_ThisTyped) && ((selfIdent).IsSelf())) && (((selfIdent).dtor_rSelfName).Equals(rName))) && (((System.Func)(() => { + bool _5_needObjectFromRef; + _5_needObjectFromRef = (_4_isSelf) && (((System.Func)(() => { DAST._IType _source0 = (selfIdent).dtor_dafnyType; { if (_source0.is_UserDefined) { DAST._IResolvedType resolved0 = _source0.dtor_resolved; - DAST._IResolvedTypeBase _5_base = resolved0.dtor_kind; - Dafny.ISequence _6_attributes = resolved0.dtor_attributes; - return ((_5_base).is_Class) || ((_5_base).is_Trait); + DAST._IResolvedTypeBase _6_base = resolved0.dtor_kind; + Dafny.ISequence _7_attributes = resolved0.dtor_attributes; + return ((_6_base).is_Class) || (((_6_base).is_Trait) && (((_6_base).dtor_traitType).is_ObjectTrait)); } } { return false; } }))()); - if (_4_needObjectFromRef) { + if (_5_needObjectFromRef) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Object"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))).FSel(Dafny.Sequence.UnicodeFromString("from_ref"))).Apply(Dafny.Sequence.FromElements(r)); } else { if (!(_3_noNeedOfClone)) { @@ -4155,6 +4250,21 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden } else if (_2_currentlyBorrowed) { resultingOwnership = Defs.Ownership.create_OwnershipBorrowed(); } else { + bool _8_selfIsGeneralTrait; + _8_selfIsGeneralTrait = (_4_isSelf) && (((System.Func)(() => { + DAST._IType _source1 = (selfIdent).dtor_dafnyType; + { + if (_source1.is_UserDefined) { + DAST._IResolvedType resolved1 = _source1.dtor_resolved; + DAST._IResolvedTypeBase _9_base = resolved1.dtor_kind; + Dafny.ISequence _10_attributes = resolved1.dtor_attributes; + return ((_9_base).is_Trait) && (((_9_base).dtor_traitType).is_GeneralTrait); + } + } + { + return false; + } + }))()); if (!(rName).Equals(Dafny.Sequence.UnicodeFromString("self"))) { if (((_0_tpe).is_Some) && (((_0_tpe).dtor_value).IsPointer())) { r = ((this).read__macro).Apply1(r); @@ -4205,14 +4315,14 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v72; + Defs._IOwnership _5___v76; Dafny.ISet> _6_argIdents; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); _4_argExpr = _out1; - _5___v72 = _out2; + _5___v76 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -4235,7 +4345,7 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ DAST._IType value0 = onType0.dtor_value; if (value0.is_UserDefined) { DAST._IResolvedType _10_resolvedType = value0.dtor_resolved; - if ((((_10_resolvedType).dtor_kind).is_Trait) || (Dafny.Helpers.Id, bool>>((_11_resolvedType, _12_nameIdent) => Dafny.Helpers.Quantifier>(Dafny.Helpers.SingleValue>(_12_nameIdent), true, (((_forall_var_0) => { + if (((((_10_resolvedType).dtor_kind).is_Trait) || ((Defs.__default.builtin__trait__preferred__methods).Contains((_9_nameIdent)))) || (Dafny.Helpers.Id, bool>>((_11_resolvedType, _12_nameIdent) => Dafny.Helpers.Quantifier>(Dafny.Helpers.SingleValue>(_12_nameIdent), true, (((_forall_var_0) => { Dafny.ISequence _13_m = (Dafny.ISequence)_forall_var_0; return !(((_11_resolvedType).dtor_properMethods).Contains(_13_m)) || (!object.Equals(_13_m, _12_nameIdent)); }))))(_10_resolvedType, _9_nameIdent))) { @@ -4414,14 +4524,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi1 = new BigInteger((_9_values).Count); for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13___v82; + Defs._IOwnership _13___v86; Dafny.ISet> _14_recIdents; RAST._IExpr _out16; Defs._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); _12_recursiveGen = _out16; - _13___v82 = _out17; + _13___v86 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -4470,14 +4580,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi3 = new BigInteger((_17_args).Count); for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { RAST._IExpr _23_recursiveGen; - Defs._IOwnership _24___v83; + Defs._IOwnership _24___v87; Dafny.ISet> _25_recIdents; RAST._IExpr _out23; Defs._IOwnership _out24; Dafny.ISet> _out25; (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); _23_recursiveGen = _out23; - _24___v83 = _out24; + _24___v87 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -4515,14 +4625,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi4 = new BigInteger((_26_dims).Count); for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { RAST._IExpr _31_recursiveGen; - Defs._IOwnership _32___v84; + Defs._IOwnership _32___v88; Dafny.ISet> _33_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr((_26_dims).Select(_30_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _31_recursiveGen = _out30; - _32___v84 = _out31; + _32___v88 = _out31; _33_recIdents = _out32; _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); @@ -4549,14 +4659,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _35_underlying = _source0.dtor_value; { RAST._IExpr _36_recursiveGen; - Defs._IOwnership _37___v85; + Defs._IOwnership _37___v89; Dafny.ISet> _38_recIdents; RAST._IExpr _out35; Defs._IOwnership _out36; Dafny.ISet> _out37; (this).GenExpr(_35_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out35, out _out36, out _out37); _36_recursiveGen = _out35; - _37___v85 = _out36; + _37___v89 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -4579,14 +4689,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out40 = (this).GenType(_40_typ, Defs.GenTypeContext.@default()); _41_tpe = _out40; RAST._IExpr _42_recursiveGen; - Defs._IOwnership _43___v86; + Defs._IOwnership _43___v90; Dafny.ISet> _44_recIdents; RAST._IExpr _out41; Defs._IOwnership _out42; Dafny.ISet> _out43; (this).GenExpr(_39_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); _42_recursiveGen = _out41; - _43___v86 = _out42; + _43___v90 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -4652,14 +4762,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; if (_50_isCo) { RAST._IExpr _59_recursiveGen; - Defs._IOwnership _60___v87; + Defs._IOwnership _60___v91; Dafny.ISet> _61_recIdents; RAST._IExpr _out50; Defs._IOwnership _out51; Dafny.ISet> _out52; (this).GenExpr(_58_value, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); _59_recursiveGen = _out50; - _60___v87 = _out51; + _60___v91 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -4682,14 +4792,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _64_wasAssigned))); } else { RAST._IExpr _65_recursiveGen; - Defs._IOwnership _66___v88; + Defs._IOwnership _66___v92; Dafny.ISet> _67_recIdents; RAST._IExpr _out53; Defs._IOwnership _out54; Dafny.ISet> _out55; (this).GenExpr(_58_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out53, out _out54, out _out55); _65_recursiveGen = _out53; - _66___v88 = _out54; + _66___v92 = _out54; _67_recIdents = _out55; _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _65_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); @@ -4729,24 +4839,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _69_expr = _source0.dtor_elem; { RAST._IExpr _70_recursiveGen; - Defs._IOwnership _71___v92; + Defs._IOwnership _71___v96; Dafny.ISet> _72_recIdents; RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; (this).GenExpr(_69_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); _70_recursiveGen = _out61; - _71___v92 = _out62; + _71___v96 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v93; + Defs._IOwnership _74___v97; Dafny.ISet> _75_lengthIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_68_length, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); _73_lengthGen = _out64; - _74___v93 = _out65; + _74___v97 = _out65; _75_lengthIdents = _out66; r = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("_initializer"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_70_recursiveGen)); RAST._IExpr _76_range; @@ -4785,14 +4895,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _82_args = Dafny.Sequence.FromElements(); while ((_81_i) < (new BigInteger((_78_exprs).Count))) { RAST._IExpr _83_recursiveGen; - Defs._IOwnership _84___v94; + Defs._IOwnership _84___v98; Dafny.ISet> _85_recIdents; RAST._IExpr _out70; Defs._IOwnership _out71; Dafny.ISet> _out72; (this).GenExpr((_78_exprs).Select(_81_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out70, out _out71, out _out72); _83_recursiveGen = _out70; - _84___v94 = _out71; + _84___v98 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -4823,14 +4933,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _88_i = BigInteger.Zero; while ((_88_i) < (new BigInteger((_86_exprs).Count))) { RAST._IExpr _89_recursiveGen; - Defs._IOwnership _90___v95; + Defs._IOwnership _90___v99; Dafny.ISet> _91_recIdents; RAST._IExpr _out75; Defs._IOwnership _out76; Dafny.ISet> _out77; (this).GenExpr((_86_exprs).Select(_88_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out75, out _out76, out _out77); _89_recursiveGen = _out75; - _90___v95 = _out76; + _90___v99 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -4858,14 +4968,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _94_i = BigInteger.Zero; while ((_94_i) < (new BigInteger((_92_exprs).Count))) { RAST._IExpr _95_recursiveGen; - Defs._IOwnership _96___v96; + Defs._IOwnership _96___v100; Dafny.ISet> _97_recIdents; RAST._IExpr _out80; Defs._IOwnership _out81; Dafny.ISet> _out82; (this).GenExpr((_92_exprs).Select(_94_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out80, out _out81, out _out82); _95_recursiveGen = _out80; - _96___v96 = _out81; + _96___v100 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -4887,14 +4997,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _98_expr = _source0.dtor_ToMultiset_a0; { RAST._IExpr _99_recursiveGen; - Defs._IOwnership _100___v97; + Defs._IOwnership _100___v101; Dafny.ISet> _101_recIdents; RAST._IExpr _out85; Defs._IOwnership _out86; Dafny.ISet> _out87; (this).GenExpr(_98_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out85, out _out86, out _out87); _99_recursiveGen = _out85; - _100___v97 = _out86; + _100___v101 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -4919,24 +5029,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _104_i = BigInteger.Zero; while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v98; + Defs._IOwnership _106___v102; Dafny.ISet> _107_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); _105_recursiveGenKey = _out90; - _106___v98 = _out91; + _106___v102 = _out91; _107_recIdentsKey = _out92; RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v99; + Defs._IOwnership _109___v103; Dafny.ISet> _110_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); _108_recursiveGenValue = _out93; - _109___v99 = _out94; + _109___v103 = _out94; _110_recIdentsValue = _out95; _103_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_103_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_105_recursiveGenKey, _108_recursiveGenValue))); readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _107_recIdentsKey), _110_recIdentsValue); @@ -4971,14 +5081,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _116_value = _source0.dtor_value; { RAST._IExpr _117_exprR; - Defs._IOwnership _118___v100; + Defs._IOwnership _118___v104; Dafny.ISet> _119_exprIdents; RAST._IExpr _out98; Defs._IOwnership _out99; Dafny.ISet> _out100; (this).GenExpr(_114_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out98, out _out99, out _out100); _117_exprR = _out98; - _118___v100 = _out99; + _118___v104 = _out99; _119_exprIdents = _out100; RAST._IExpr _120_indexR; Defs._IOwnership _121_indexOwnership; @@ -5019,14 +5129,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _128_value = _source0.dtor_value; { RAST._IExpr _129_exprR; - Defs._IOwnership _130___v101; + Defs._IOwnership _130___v105; Dafny.ISet> _131_exprIdents; RAST._IExpr _out109; Defs._IOwnership _out110; Dafny.ISet> _out111; (this).GenExpr(_126_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out109, out _out110, out _out111); _129_exprR = _out109; - _130___v101 = _out110; + _130___v105 = _out110; _131_exprIdents = _out111; RAST._IExpr _132_indexR; Defs._IOwnership _133_indexOwnership; @@ -5107,14 +5217,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _143_f = _source0.dtor_els; { RAST._IExpr _144_cond; - Defs._IOwnership _145___v102; + Defs._IOwnership _145___v106; Dafny.ISet> _146_recIdentsCond; RAST._IExpr _out126; Defs._IOwnership _out127; Dafny.ISet> _out128; (this).GenExpr(_141_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out126, out _out127, out _out128); _144_cond = _out126; - _145___v102 = _out127; + _145___v106 = _out127; _146_recIdentsCond = _out128; RAST._IExpr _147_fExpr; Defs._IOwnership _148_fOwned; @@ -5127,14 +5237,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _148_fOwned = _out130; _149_recIdentsF = _out131; RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v103; + Defs._IOwnership _151___v107; Dafny.ISet> _152_recIdentsT; RAST._IExpr _out132; Defs._IOwnership _out133; Dafny.ISet> _out134; (this).GenExpr(_142_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); _150_tExpr = _out132; - _151___v103 = _out133; + _151___v107 = _out133; _152_recIdentsT = _out134; r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); RAST._IExpr _out135; @@ -5156,14 +5266,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; { RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v104; + Defs._IOwnership _156___v108; Dafny.ISet> _157_recIdents; RAST._IExpr _out137; Defs._IOwnership _out138; Dafny.ISet> _out139; (this).GenExpr(_153_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out137, out _out138, out _out139); _155_recursiveGen = _out137; - _156___v104 = _out138; + _156___v108 = _out138; _157_recIdents = _out139; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); RAST._IExpr _out140; @@ -5186,14 +5296,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; { RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v105; + Defs._IOwnership _161___v109; Dafny.ISet> _162_recIdents; RAST._IExpr _out142; Defs._IOwnership _out143; Dafny.ISet> _out144; (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out142, out _out143, out _out144); _160_recursiveGen = _out142; - _161___v105 = _out143; + _161___v109 = _out143; _162_recIdents = _out144; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); RAST._IExpr _out145; @@ -5258,14 +5368,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _171_native = _source0.dtor_native; { RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v110; + Defs._IOwnership _173___v114; Dafny.ISet> _174_recIdents; RAST._IExpr _out155; Defs._IOwnership _out156; Dafny.ISet> _out157; (this).GenExpr(_168_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out155, out _out156, out _out157); _172_recursiveGen = _out155; - _173___v110 = _out156; + _173___v114 = _out156; _174_recIdents = _out157; RAST._IType _175_arrayType; RAST._IType _out158; @@ -5307,14 +5417,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _177_expr = _source0.dtor_expr; { RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v111; + Defs._IOwnership _179___v115; Dafny.ISet> _180_recIdents; RAST._IExpr _out162; Defs._IOwnership _out163; Dafny.ISet> _out164; (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); _178_recursiveGen = _out162; - _179___v111 = _out163; + _179___v115 = _out163; _180_recIdents = _out164; readIdents = _180_recIdents; r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); @@ -5333,14 +5443,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _181_expr = _source0.dtor_expr; { RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v112; + Defs._IOwnership _183___v116; Dafny.ISet> _184_recIdents; RAST._IExpr _out167; Defs._IOwnership _out168; Dafny.ISet> _out169; (this).GenExpr(_181_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); _182_recursiveGen = _out167; - _183___v112 = _out168; + _183___v116 = _out168; _184_recIdents = _out169; readIdents = _184_recIdents; r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); @@ -5359,14 +5469,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _185_expr = _source0.dtor_expr; { RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v113; + Defs._IOwnership _187___v117; Dafny.ISet> _188_recIdents; RAST._IExpr _out172; Defs._IOwnership _out173; Dafny.ISet> _out174; (this).GenExpr(_185_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out172, out _out173, out _out174); _186_recursiveGen = _out172; - _187___v113 = _out173; + _187___v117 = _out173; _188_recIdents = _out174; readIdents = _188_recIdents; r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); @@ -5438,15 +5548,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _209_name = _let_tmp_rhs1.dtor__0; RAST._IType _210_ty = _let_tmp_rhs1.dtor__1; RAST._IExpr _211_rIdent; - Defs._IOwnership _212___v114; - Dafny.ISet> _213___v115; + Defs._IOwnership _212___v118; + Dafny.ISet> _213___v119; RAST._IExpr _out181; Defs._IOwnership _out182; Dafny.ISet> _out183; (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((!(_193_isConstant)) && ((_210_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); _211_rIdent = _out181; - _212___v114 = _out182; - _213___v115 = _out183; + _212___v118 = _out182; + _213___v119 = _out183; _207_onExprArgs = Dafny.Sequence.Concat(_207_onExprArgs, Dafny.Sequence.FromElements(_211_rIdent)); } _206_body = (_206_body).Apply(_207_onExprArgs); @@ -5737,14 +5847,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _258_l = _source5.dtor_value; { RAST._IExpr _259_lExpr; - Defs._IOwnership _260___v118; + Defs._IOwnership _260___v122; Dafny.ISet> _261_recIdentsL; RAST._IExpr _out217; Defs._IOwnership _out218; Dafny.ISet> _out219; (this).GenExpr(_258_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out217, out _out218, out _out219); _259_lExpr = _out217; - _260___v118 = _out218; + _260___v122 = _out218; _261_recIdentsL = _out219; _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_259_lExpr)); readIdents = Dafny.Set>.Union(readIdents, _261_recIdentsL); @@ -5761,14 +5871,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _262_h = _source6.dtor_value; { RAST._IExpr _263_hExpr; - Defs._IOwnership _264___v119; + Defs._IOwnership _264___v123; Dafny.ISet> _265_recIdentsH; RAST._IExpr _out220; Defs._IOwnership _out221; Dafny.ISet> _out222; (this).GenExpr(_262_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out220, out _out221, out _out222); _263_hExpr = _out220; - _264___v119 = _out221; + _264___v123 = _out221; _265_recIdentsH = _out222; _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_263_hExpr)); readIdents = Dafny.Set>.Union(readIdents, _265_recIdentsH); @@ -5890,7 +6000,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir RAST._IExpr _288_onExpr = RAST.Expr.Default(); Defs._IOwnership _289_recOwnership = Defs.Ownership.Default(); Dafny.ISet> _290_recIdents = Dafny.Set>.Empty; - if (((_285_base).is_Trait) || ((_285_base).is_Class)) { + if ((((_285_base).is_Trait) && (((_285_base).dtor_traitType).is_ObjectTrait)) || ((_285_base).is_Class)) { RAST._IExpr _out236; Defs._IOwnership _out237; Dafny.ISet> _out238; @@ -5900,7 +6010,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _290_recIdents = _out238; _288_onExpr = ((this).read__macro).Apply1(_288_onExpr); readIdents = Dafny.Set>.Union(readIdents, _290_recIdents); - } else { + } else if (((_285_base).is_Trait) && (((_285_base).dtor_traitType).is_GeneralTrait)) { RAST._IExpr _out239; Defs._IOwnership _out240; Dafny.ISet> _out241; @@ -5908,28 +6018,51 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _288_onExpr = _out239; _289_recOwnership = _out240; _290_recIdents = _out241; + if (((_288_onExpr).is_Identifier) && ((env).NeedsAsRefForBorrow((_288_onExpr).dtor_name))) { + _288_onExpr = ((_288_onExpr).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); + } else if ((_288_onExpr).IsBorrow()) { + _288_onExpr = (((_288_onExpr).dtor_underlying).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); + } + readIdents = Dafny.Set>.Union(readIdents, _290_recIdents); + } else if (((_285_base).is_Newtype) && (Defs.__default.IsNewtypeCopy((_285_base).dtor_range))) { + RAST._IExpr _out242; + Defs._IOwnership _out243; + Dafny.ISet> _out244; + (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out242, out _out243, out _out244); + _288_onExpr = _out242; + _289_recOwnership = _out243; + _290_recIdents = _out244; + readIdents = Dafny.Set>.Union(readIdents, _290_recIdents); + } else { + RAST._IExpr _out245; + Defs._IOwnership _out246; + Dafny.ISet> _out247; + (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out245, out _out246, out _out247); + _288_onExpr = _out245; + _289_recOwnership = _out246; + _290_recIdents = _out247; readIdents = Dafny.Set>.Union(readIdents, _290_recIdents); } r = ((((_286_fullPath).ApplyType(_287_onTypeExprs)).FSel(Defs.__default.escapeName((_276_name).dtor_name))).ApplyType(_281_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_288_onExpr), _279_argExprs)); - RAST._IExpr _out242; - Defs._IOwnership _out243; - (this).FromOwned(r, expectedOwnership, out _out242, out _out243); - r = _out242; - resultingOwnership = _out243; + RAST._IExpr _out248; + Defs._IOwnership _out249; + (this).FromOwned(r, expectedOwnership, out _out248, out _out249); + r = _out248; + resultingOwnership = _out249; goto after_match8; } } { RAST._IExpr _291_onExpr; - Defs._IOwnership _292___v125; + Defs._IOwnership _292___v129; Dafny.ISet> _293_recIdents; - RAST._IExpr _out244; - Defs._IOwnership _out245; - Dafny.ISet> _out246; - (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out244, out _out245, out _out246); - _291_onExpr = _out244; - _292___v125 = _out245; - _293_recIdents = _out246; + RAST._IExpr _out250; + Defs._IOwnership _out251; + Dafny.ISet> _out252; + (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out250, out _out251, out _out252); + _291_onExpr = _out250; + _292___v129 = _out251; + _293_recIdents = _out252; readIdents = Dafny.Set>.Union(readIdents, _293_recIdents); Dafny.ISequence _294_renderedName; _294_renderedName = (this).GetMethodName(_275_on, _276_name); @@ -5959,9 +6092,9 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (onType0.is_Some) { DAST._IType _295_tpe = onType0.dtor_value; RAST._IType _296_typ; - RAST._IType _out247; - _out247 = (this).GenType(_295_tpe, Defs.GenTypeContext.@default()); - _296_typ = _out247; + RAST._IType _out253; + _out253 = (this).GenType(_295_tpe, Defs.GenTypeContext.@default()); + _296_typ = _out253; if ((_296_typ).IsObjectOrPointer()) { _291_onExpr = ((this).read__macro).Apply1(_291_onExpr); } @@ -5978,11 +6111,11 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } after_match9: ; r = ((_291_onExpr).ApplyType(_281_typeExprs)).Apply(_279_argExprs); - RAST._IExpr _out248; - Defs._IOwnership _out249; - (this).FromOwned(r, expectedOwnership, out _out248, out _out249); - r = _out248; - resultingOwnership = _out249; + RAST._IExpr _out254; + Defs._IOwnership _out255; + (this).FromOwned(r, expectedOwnership, out _out254, out _out255); + r = _out254; + resultingOwnership = _out255; return ; } after_match8: ; @@ -5997,9 +6130,9 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _299_body = _source0.dtor_body; { Dafny.ISequence _300_params; - Dafny.ISequence _out250; - _out250 = (this).GenParams(_297_paramsDafny, true); - _300_params = _out250; + Dafny.ISequence _out256; + _out256 = (this).GenParams(_297_paramsDafny, true); + _300_params = _out256; Dafny.ISequence> _301_paramNames; _301_paramNames = Dafny.Sequence>.FromElements(); Dafny.IMap,RAST._IType> _302_paramTypesMap; @@ -6015,14 +6148,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _305_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_301_paramNames, _302_paramTypesMap)); RAST._IExpr _306_recursiveGen; Dafny.ISet> _307_recIdents; - Defs._IEnvironment _308___v135; - RAST._IExpr _out251; - Dafny.ISet> _out252; - Defs._IEnvironment _out253; - (this).GenStmts(_299_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _305_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out251, out _out252, out _out253); - _306_recursiveGen = _out251; - _307_recIdents = _out252; - _308___v135 = _out253; + Defs._IEnvironment _308___v139; + RAST._IExpr _out257; + Dafny.ISet> _out258; + Defs._IEnvironment _out259; + (this).GenStmts(_299_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _305_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out257, out _out258, out _out259); + _306_recursiveGen = _out257; + _307_recIdents = _out258; + _308___v139 = _out259; readIdents = Dafny.Set>.FromElements(); _307_recIdents = Dafny.Set>.Difference(_307_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_309_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); @@ -6048,15 +6181,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir after__ASSIGN_SUCH_THAT_1: ; if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_312_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { RAST._IExpr _313_selfCloned; - Defs._IOwnership _314___v136; - Dafny.ISet> _315___v137; - RAST._IExpr _out254; - Defs._IOwnership _out255; - Dafny.ISet> _out256; - (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out254, out _out255, out _out256); - _313_selfCloned = _out254; - _314___v136 = _out255; - _315___v137 = _out256; + Defs._IOwnership _314___v140; + Dafny.ISet> _315___v141; + RAST._IExpr _out260; + Defs._IOwnership _out261; + Dafny.ISet> _out262; + (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out260, out _out261, out _out262); + _313_selfCloned = _out260; + _314___v140 = _out261; + _315___v141 = _out262; _311_allReadCloned = (_311_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_313_selfCloned))); } else if (!((_301_paramNames).Contains(_312_next))) { RAST._IExpr _316_copy; @@ -6067,15 +6200,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _307_recIdents = Dafny.Set>.Difference(_307_recIdents, Dafny.Set>.FromElements(_312_next)); } RAST._IType _317_retTypeGen; - RAST._IType _out257; - _out257 = (this).GenType(_298_retType, Defs.GenTypeContext.@default()); - _317_retTypeGen = _out257; + RAST._IType _out263; + _out263 = (this).GenType(_298_retType, Defs.GenTypeContext.@default()); + _317_retTypeGen = _out263; r = RAST.Expr.create_Block((_311_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_300_params, Std.Wrappers.Option.create_Some(_317_retTypeGen), RAST.Expr.create_Block(_306_recursiveGen))))); - RAST._IExpr _out258; - Defs._IOwnership _out259; - (this).FromOwned(r, expectedOwnership, out _out258, out _out259); - r = _out258; - resultingOwnership = _out259; + RAST._IExpr _out264; + Defs._IOwnership _out265; + (this).FromOwned(r, expectedOwnership, out _out264, out _out265); + r = _out264; + resultingOwnership = _out265; return ; } goto after_match0; @@ -6090,11 +6223,11 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence> _321_paramNames; _321_paramNames = Dafny.Sequence>.FromElements(); Dafny.ISequence _322_paramFormals; - Dafny.ISequence _out260; - _out260 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_323_value) => { + Dafny.ISequence _out266; + _out266 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_323_value) => { return (_323_value).dtor__0; })), _318_values), false); - _322_paramFormals = _out260; + _322_paramFormals = _out266; Dafny.IMap,RAST._IType> _324_paramTypes; _324_paramTypes = Dafny.Map, RAST._IType>.FromElements(); Dafny.ISet> _325_paramNamesSet; @@ -6114,19 +6247,19 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi13 = new BigInteger((_318_values).Count); for (BigInteger _329_i = BigInteger.Zero; _329_i < _hi13; _329_i++) { RAST._IType _330_typeGen; - RAST._IType _out261; - _out261 = (this).GenType((((_318_values).Select(_329_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); - _330_typeGen = _out261; + RAST._IType _out267; + _out267 = (this).GenType((((_318_values).Select(_329_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); + _330_typeGen = _out267; RAST._IExpr _331_valueGen; - Defs._IOwnership _332___v138; + Defs._IOwnership _332___v142; Dafny.ISet> _333_recIdents; - RAST._IExpr _out262; - Defs._IOwnership _out263; - Dafny.ISet> _out264; - (this).GenExpr(((_318_values).Select(_329_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out262, out _out263, out _out264); - _331_valueGen = _out262; - _332___v138 = _out263; - _333_recIdents = _out264; + RAST._IExpr _out268; + Defs._IOwnership _out269; + Dafny.ISet> _out270; + (this).GenExpr(((_318_values).Select(_329_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out268, out _out269, out _out270); + _331_valueGen = _out268; + _332___v142 = _out269; + _333_recIdents = _out270; r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_318_values).Select(_329_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_330_typeGen), Std.Wrappers.Option.create_Some(_331_valueGen))); readIdents = Dafny.Set>.Union(readIdents, _333_recIdents); } @@ -6135,20 +6268,20 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir RAST._IExpr _335_recGen; Defs._IOwnership _336_recOwned; Dafny.ISet> _337_recIdents; - RAST._IExpr _out265; - Defs._IOwnership _out266; - Dafny.ISet> _out267; - (this).GenExpr(_320_expr, selfIdent, _334_newEnv, expectedOwnership, out _out265, out _out266, out _out267); - _335_recGen = _out265; - _336_recOwned = _out266; - _337_recIdents = _out267; + RAST._IExpr _out271; + Defs._IOwnership _out272; + Dafny.ISet> _out273; + (this).GenExpr(_320_expr, selfIdent, _334_newEnv, expectedOwnership, out _out271, out _out272, out _out273); + _335_recGen = _out271; + _336_recOwned = _out272; + _337_recIdents = _out273; readIdents = Dafny.Set>.Difference(_337_recIdents, _325_paramNamesSet); r = RAST.Expr.create_Block((r).Then(_335_recGen)); - RAST._IExpr _out268; - Defs._IOwnership _out269; - (this).FromOwnership(r, _336_recOwned, expectedOwnership, out _out268, out _out269); - r = _out268; - resultingOwnership = _out269; + RAST._IExpr _out274; + Defs._IOwnership _out275; + (this).FromOwnership(r, _336_recOwned, expectedOwnership, out _out274, out _out275); + r = _out274; + resultingOwnership = _out275; return ; } goto after_match0; @@ -6162,39 +6295,39 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _341_iifeBody = _source0.dtor_iifeBody; { RAST._IExpr _342_valueGen; - Defs._IOwnership _343___v139; + Defs._IOwnership _343___v143; Dafny.ISet> _344_recIdents; - RAST._IExpr _out270; - Defs._IOwnership _out271; - Dafny.ISet> _out272; - (this).GenExpr(_340_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out270, out _out271, out _out272); - _342_valueGen = _out270; - _343___v139 = _out271; - _344_recIdents = _out272; + RAST._IExpr _out276; + Defs._IOwnership _out277; + Dafny.ISet> _out278; + (this).GenExpr(_340_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out276, out _out277, out _out278); + _342_valueGen = _out276; + _343___v143 = _out277; + _344_recIdents = _out278; readIdents = _344_recIdents; RAST._IType _345_valueTypeGen; - RAST._IType _out273; - _out273 = (this).GenType(_339_tpe, Defs.GenTypeContext.@default()); - _345_valueTypeGen = _out273; + RAST._IType _out279; + _out279 = (this).GenType(_339_tpe, Defs.GenTypeContext.@default()); + _345_valueTypeGen = _out279; Dafny.ISequence _346_iifeVar; _346_iifeVar = Defs.__default.escapeVar(_338_name); RAST._IExpr _347_bodyGen; - Defs._IOwnership _348___v140; + Defs._IOwnership _348___v144; Dafny.ISet> _349_bodyIdents; - RAST._IExpr _out274; - Defs._IOwnership _out275; - Dafny.ISet> _out276; - (this).GenExpr(_341_iifeBody, selfIdent, (env).AddAssigned(_346_iifeVar, _345_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out274, out _out275, out _out276); - _347_bodyGen = _out274; - _348___v140 = _out275; - _349_bodyIdents = _out276; + RAST._IExpr _out280; + Defs._IOwnership _out281; + Dafny.ISet> _out282; + (this).GenExpr(_341_iifeBody, selfIdent, (env).AddAssigned(_346_iifeVar, _345_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out280, out _out281, out _out282); + _347_bodyGen = _out280; + _348___v144 = _out281; + _349_bodyIdents = _out282; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_349_bodyIdents, Dafny.Set>.FromElements(_346_iifeVar))); r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _346_iifeVar, Std.Wrappers.Option.create_Some(_345_valueTypeGen), Std.Wrappers.Option.create_Some(_342_valueGen))).Then(_347_bodyGen)); - RAST._IExpr _out277; - Defs._IOwnership _out278; - (this).FromOwned(r, expectedOwnership, out _out277, out _out278); - r = _out277; - resultingOwnership = _out278; + RAST._IExpr _out283; + Defs._IOwnership _out284; + (this).FromOwned(r, expectedOwnership, out _out283, out _out284); + r = _out283; + resultingOwnership = _out284; return ; } goto after_match0; @@ -6206,15 +6339,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _351_args = _source0.dtor_args; { RAST._IExpr _352_funcExpr; - Defs._IOwnership _353___v141; + Defs._IOwnership _353___v145; Dafny.ISet> _354_recIdents; - RAST._IExpr _out279; - Defs._IOwnership _out280; - Dafny.ISet> _out281; - (this).GenExpr(_350_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out279, out _out280, out _out281); - _352_funcExpr = _out279; - _353___v141 = _out280; - _354_recIdents = _out281; + RAST._IExpr _out285; + Defs._IOwnership _out286; + Dafny.ISet> _out287; + (this).GenExpr(_350_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out285, out _out286, out _out287); + _352_funcExpr = _out285; + _353___v145 = _out286; + _354_recIdents = _out287; readIdents = _354_recIdents; Dafny.ISequence _355_rArgs; _355_rArgs = Dafny.Sequence.FromElements(); @@ -6223,22 +6356,22 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir RAST._IExpr _357_argExpr; Defs._IOwnership _358_argOwned; Dafny.ISet> _359_argIdents; - RAST._IExpr _out282; - Defs._IOwnership _out283; - Dafny.ISet> _out284; - (this).GenExpr((_351_args).Select(_356_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out282, out _out283, out _out284); - _357_argExpr = _out282; - _358_argOwned = _out283; - _359_argIdents = _out284; + RAST._IExpr _out288; + Defs._IOwnership _out289; + Dafny.ISet> _out290; + (this).GenExpr((_351_args).Select(_356_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out288, out _out289, out _out290); + _357_argExpr = _out288; + _358_argOwned = _out289; + _359_argIdents = _out290; _355_rArgs = Dafny.Sequence.Concat(_355_rArgs, Dafny.Sequence.FromElements(_357_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _359_argIdents); } r = (_352_funcExpr).Apply(_355_rArgs); - RAST._IExpr _out285; - Defs._IOwnership _out286; - (this).FromOwned(r, expectedOwnership, out _out285, out _out286); - r = _out285; - resultingOwnership = _out286; + RAST._IExpr _out291; + Defs._IOwnership _out292; + (this).FromOwned(r, expectedOwnership, out _out291, out _out292); + r = _out291; + resultingOwnership = _out292; return ; } goto after_match0; @@ -6251,25 +6384,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _362_variant = _source0.dtor_variant; { RAST._IExpr _363_exprGen; - Defs._IOwnership _364___v142; + Defs._IOwnership _364___v146; Dafny.ISet> _365_recIdents; - RAST._IExpr _out287; - Defs._IOwnership _out288; - Dafny.ISet> _out289; - (this).GenExpr(_360_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out287, out _out288, out _out289); - _363_exprGen = _out287; - _364___v142 = _out288; - _365_recIdents = _out289; + RAST._IExpr _out293; + Defs._IOwnership _out294; + Dafny.ISet> _out295; + (this).GenExpr(_360_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out293, out _out294, out _out295); + _363_exprGen = _out293; + _364___v146 = _out294; + _365_recIdents = _out295; RAST._IExpr _366_variantExprPath; - RAST._IExpr _out290; - _out290 = (this).GenPathExpr(Dafny.Sequence>.Concat(_361_dType, Dafny.Sequence>.FromElements(_362_variant)), true); - _366_variantExprPath = _out290; + RAST._IExpr _out296; + _out296 = (this).GenPathExpr(Dafny.Sequence>.Concat(_361_dType, Dafny.Sequence>.FromElements(_362_variant)), true); + _366_variantExprPath = _out296; r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_363_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _366_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); - RAST._IExpr _out291; - Defs._IOwnership _out292; - (this).FromOwned(r, expectedOwnership, out _out291, out _out292); - r = _out291; - resultingOwnership = _out292; + RAST._IExpr _out297; + Defs._IOwnership _out298; + (this).FromOwned(r, expectedOwnership, out _out297, out _out298); + r = _out297; + resultingOwnership = _out298; readIdents = _365_recIdents; return ; } @@ -6285,34 +6418,34 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir RAST._IExpr _370_expr; Defs._IOwnership _371_recOwned; Dafny.ISet> _372_recIdents; - RAST._IExpr _out293; - Defs._IOwnership _out294; - Dafny.ISet> _out295; - (this).GenExpr(_367_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out293, out _out294, out _out295); - _370_expr = _out293; - _371_recOwned = _out294; - _372_recIdents = _out295; + RAST._IExpr _out299; + Defs._IOwnership _out300; + Dafny.ISet> _out301; + (this).GenExpr(_367_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out299, out _out300, out _out301); + _370_expr = _out299; + _371_recOwned = _out300; + _372_recIdents = _out301; RAST._IType _373_fromType; - RAST._IType _out296; - _out296 = (this).GenType(_368_fromType, Defs.GenTypeContext.@default()); - _373_fromType = _out296; + RAST._IType _out302; + _out302 = (this).GenType(_368_fromType, Defs.GenTypeContext.@default()); + _373_fromType = _out302; RAST._IType _374_toType; - RAST._IType _out297; - _out297 = (this).GenType(_369_toType, Defs.GenTypeContext.@default()); - _374_toType = _out297; + RAST._IType _out303; + _out303 = (this).GenType(_369_toType, Defs.GenTypeContext.@default()); + _374_toType = _out303; if (((_373_fromType).IsObjectOrPointer()) && ((_374_toType).IsObjectOrPointer())) { r = (((_370_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_374_toType).ObjectOrPointerUnderlying()))).Apply0(); } else { - RAST._IExpr _out298; - _out298 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object or Ptr"), (this).InitEmptyExpr()); - r = _out298; + RAST._IExpr _out304; + _out304 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object or Ptr"), (this).InitEmptyExpr()); + r = _out304; readIdents = Dafny.Set>.FromElements(); } - RAST._IExpr _out299; - Defs._IOwnership _out300; - (this).FromOwnership(r, _371_recOwned, expectedOwnership, out _out299, out _out300); - r = _out299; - resultingOwnership = _out300; + RAST._IExpr _out305; + Defs._IOwnership _out306; + (this).FromOwnership(r, _371_recOwned, expectedOwnership, out _out305, out _out306); + r = _out305; + resultingOwnership = _out306; readIdents = _372_recIdents; return ; } @@ -6323,11 +6456,11 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_BoolBoundedPool) { { r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("[false, true]")); - RAST._IExpr _out301; - Defs._IOwnership _out302; - (this).FromOwned(r, expectedOwnership, out _out301, out _out302); - r = _out301; - resultingOwnership = _out302; + RAST._IExpr _out307; + Defs._IOwnership _out308; + (this).FromOwned(r, expectedOwnership, out _out307, out _out308); + r = _out307; + resultingOwnership = _out308; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6339,21 +6472,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _375_of = _source0.dtor_of; { RAST._IExpr _376_exprGen; - Defs._IOwnership _377___v143; + Defs._IOwnership _377___v147; Dafny.ISet> _378_recIdents; - RAST._IExpr _out303; - Defs._IOwnership _out304; - Dafny.ISet> _out305; - (this).GenExpr(_375_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out303, out _out304, out _out305); - _376_exprGen = _out303; - _377___v143 = _out304; - _378_recIdents = _out305; + RAST._IExpr _out309; + Defs._IOwnership _out310; + Dafny.ISet> _out311; + (this).GenExpr(_375_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out309, out _out310, out _out311); + _376_exprGen = _out309; + _377___v147 = _out310; + _378_recIdents = _out311; r = ((_376_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - RAST._IExpr _out306; - Defs._IOwnership _out307; - (this).FromOwned(r, expectedOwnership, out _out306, out _out307); - r = _out306; - resultingOwnership = _out307; + RAST._IExpr _out312; + Defs._IOwnership _out313; + (this).FromOwned(r, expectedOwnership, out _out312, out _out313); + r = _out312; + resultingOwnership = _out313; readIdents = _378_recIdents; return ; } @@ -6366,24 +6499,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _380_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _381_exprGen; - Defs._IOwnership _382___v144; + Defs._IOwnership _382___v148; Dafny.ISet> _383_recIdents; - RAST._IExpr _out308; - Defs._IOwnership _out309; - Dafny.ISet> _out310; - (this).GenExpr(_379_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out308, out _out309, out _out310); - _381_exprGen = _out308; - _382___v144 = _out309; - _383_recIdents = _out310; + RAST._IExpr _out314; + Defs._IOwnership _out315; + Dafny.ISet> _out316; + (this).GenExpr(_379_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out314, out _out315, out _out316); + _381_exprGen = _out314; + _382___v148 = _out315; + _383_recIdents = _out316; r = ((_381_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_380_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } - RAST._IExpr _out311; - Defs._IOwnership _out312; - (this).FromOwned(r, expectedOwnership, out _out311, out _out312); - r = _out311; - resultingOwnership = _out312; + RAST._IExpr _out317; + Defs._IOwnership _out318; + (this).FromOwned(r, expectedOwnership, out _out317, out _out318); + r = _out317; + resultingOwnership = _out318; readIdents = _383_recIdents; return ; } @@ -6396,24 +6529,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _385_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _386_exprGen; - Defs._IOwnership _387___v145; + Defs._IOwnership _387___v149; Dafny.ISet> _388_recIdents; - RAST._IExpr _out313; - Defs._IOwnership _out314; - Dafny.ISet> _out315; - (this).GenExpr(_384_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out313, out _out314, out _out315); - _386_exprGen = _out313; - _387___v145 = _out314; - _388_recIdents = _out315; + RAST._IExpr _out319; + Defs._IOwnership _out320; + Dafny.ISet> _out321; + (this).GenExpr(_384_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out319, out _out320, out _out321); + _386_exprGen = _out319; + _387___v149 = _out320; + _388_recIdents = _out321; r = ((_386_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_385_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } - RAST._IExpr _out316; - Defs._IOwnership _out317; - (this).FromOwned(r, expectedOwnership, out _out316, out _out317); - r = _out316; - resultingOwnership = _out317; + RAST._IExpr _out322; + Defs._IOwnership _out323; + (this).FromOwned(r, expectedOwnership, out _out322, out _out323); + r = _out322; + resultingOwnership = _out323; readIdents = _388_recIdents; return ; } @@ -6425,22 +6558,22 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _389_of = _source0.dtor_of; { RAST._IExpr _390_exprGen; - Defs._IOwnership _391___v146; + Defs._IOwnership _391___v150; Dafny.ISet> _392_recIdents; - RAST._IExpr _out318; - Defs._IOwnership _out319; - Dafny.ISet> _out320; - (this).GenExpr(_389_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out318, out _out319, out _out320); - _390_exprGen = _out318; - _391___v146 = _out319; - _392_recIdents = _out320; + RAST._IExpr _out324; + Defs._IOwnership _out325; + Dafny.ISet> _out326; + (this).GenExpr(_389_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out324, out _out325, out _out326); + _390_exprGen = _out324; + _391___v150 = _out325; + _392_recIdents = _out326; r = ((((_390_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); readIdents = _392_recIdents; - RAST._IExpr _out321; - Defs._IOwnership _out322; - (this).FromOwned(r, expectedOwnership, out _out321, out _out322); - r = _out321; - resultingOwnership = _out322; + RAST._IExpr _out327; + Defs._IOwnership _out328; + (this).FromOwned(r, expectedOwnership, out _out327, out _out328); + r = _out327; + resultingOwnership = _out328; } goto after_match0; } @@ -6450,22 +6583,22 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _393_of = _source0.dtor_of; { RAST._IExpr _394_exprGen; - Defs._IOwnership _395___v147; + Defs._IOwnership _395___v151; Dafny.ISet> _396_recIdents; - RAST._IExpr _out323; - Defs._IOwnership _out324; - Dafny.ISet> _out325; - (this).GenExpr(_393_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out323, out _out324, out _out325); - _394_exprGen = _out323; - _395___v147 = _out324; - _396_recIdents = _out325; + RAST._IExpr _out329; + Defs._IOwnership _out330; + Dafny.ISet> _out331; + (this).GenExpr(_393_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out329, out _out330, out _out331); + _394_exprGen = _out329; + _395___v151 = _out330; + _396_recIdents = _out331; r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_394_exprGen); readIdents = _396_recIdents; - RAST._IExpr _out326; - Defs._IOwnership _out327; - (this).FromOwned(r, expectedOwnership, out _out326, out _out327); - r = _out326; - resultingOwnership = _out327; + RAST._IExpr _out332; + Defs._IOwnership _out333; + (this).FromOwned(r, expectedOwnership, out _out332, out _out333); + r = _out332; + resultingOwnership = _out333; } goto after_match0; } @@ -6478,25 +6611,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _400_up = _source0.dtor_up; { RAST._IExpr _401_lo; - Defs._IOwnership _402___v148; + Defs._IOwnership _402___v152; Dafny.ISet> _403_recIdentsLo; - RAST._IExpr _out328; - Defs._IOwnership _out329; - Dafny.ISet> _out330; - (this).GenExpr(_398_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out328, out _out329, out _out330); - _401_lo = _out328; - _402___v148 = _out329; - _403_recIdentsLo = _out330; + RAST._IExpr _out334; + Defs._IOwnership _out335; + Dafny.ISet> _out336; + (this).GenExpr(_398_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); + _401_lo = _out334; + _402___v152 = _out335; + _403_recIdentsLo = _out336; RAST._IExpr _404_hi; - Defs._IOwnership _405___v149; + Defs._IOwnership _405___v153; Dafny.ISet> _406_recIdentsHi; - RAST._IExpr _out331; - Defs._IOwnership _out332; - Dafny.ISet> _out333; - (this).GenExpr(_399_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out331, out _out332, out _out333); - _404_hi = _out331; - _405___v149 = _out332; - _406_recIdentsHi = _out333; + RAST._IExpr _out337; + Defs._IOwnership _out338; + Dafny.ISet> _out339; + (this).GenExpr(_399_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); + _404_hi = _out337; + _405___v153 = _out338; + _406_recIdentsHi = _out339; if (_400_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_401_lo, _404_hi)); } else { @@ -6504,16 +6637,16 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } if (!((_397_typ).is_Primitive)) { RAST._IType _407_tpe; - RAST._IType _out334; - _out334 = (this).GenType(_397_typ, Defs.GenTypeContext.@default()); - _407_tpe = _out334; + RAST._IType _out340; + _out340 = (this).GenType(_397_typ, Defs.GenTypeContext.@default()); + _407_tpe = _out340; r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_407_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); } - RAST._IExpr _out335; - Defs._IOwnership _out336; - (this).FromOwned(r, expectedOwnership, out _out335, out _out336); - r = _out335; - resultingOwnership = _out336; + RAST._IExpr _out341; + Defs._IOwnership _out342; + (this).FromOwned(r, expectedOwnership, out _out341, out _out342); + r = _out341; + resultingOwnership = _out342; readIdents = Dafny.Set>.Union(_403_recIdentsLo, _406_recIdentsHi); return ; } @@ -6526,25 +6659,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _409_up = _source0.dtor_up; { RAST._IExpr _410_start; - Defs._IOwnership _411___v150; + Defs._IOwnership _411___v154; Dafny.ISet> _412_recIdentStart; - RAST._IExpr _out337; - Defs._IOwnership _out338; - Dafny.ISet> _out339; - (this).GenExpr(_408_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); - _410_start = _out337; - _411___v150 = _out338; - _412_recIdentStart = _out339; + RAST._IExpr _out343; + Defs._IOwnership _out344; + Dafny.ISet> _out345; + (this).GenExpr(_408_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out343, out _out344, out _out345); + _410_start = _out343; + _411___v154 = _out344; + _412_recIdentStart = _out345; if (_409_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_410_start); } else { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_410_start); } - RAST._IExpr _out340; - Defs._IOwnership _out341; - (this).FromOwned(r, expectedOwnership, out _out340, out _out341); - r = _out340; - resultingOwnership = _out341; + RAST._IExpr _out346; + Defs._IOwnership _out347; + (this).FromOwned(r, expectedOwnership, out _out346, out _out347); + r = _out346; + resultingOwnership = _out347; readIdents = _412_recIdentStart; return ; } @@ -6557,19 +6690,19 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IType _414_valueType = _source0.dtor_valueType; { RAST._IType _415_kType; - RAST._IType _out342; - _out342 = (this).GenType(_413_keyType, Defs.GenTypeContext.@default()); - _415_kType = _out342; + RAST._IType _out348; + _out348 = (this).GenType(_413_keyType, Defs.GenTypeContext.@default()); + _415_kType = _out348; RAST._IType _416_vType; - RAST._IType _out343; - _out343 = (this).GenType(_414_valueType, Defs.GenTypeContext.@default()); - _416_vType = _out343; + RAST._IType _out349; + _out349 = (this).GenType(_414_valueType, Defs.GenTypeContext.@default()); + _416_vType = _out349; r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_415_kType, _416_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out344; - Defs._IOwnership _out345; - (this).FromOwned(r, expectedOwnership, out _out344, out _out345); - r = _out344; - resultingOwnership = _out345; + RAST._IExpr _out350; + Defs._IOwnership _out351; + (this).FromOwned(r, expectedOwnership, out _out350, out _out351); + r = _out350; + resultingOwnership = _out351; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6581,16 +6714,16 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IType _417_elemType = _source0.dtor_elemType; { RAST._IType _418_eType; - RAST._IType _out346; - _out346 = (this).GenType(_417_elemType, Defs.GenTypeContext.@default()); - _418_eType = _out346; + RAST._IType _out352; + _out352 = (this).GenType(_417_elemType, Defs.GenTypeContext.@default()); + _418_eType = _out352; readIdents = Dafny.Set>.FromElements(); r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_418_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out347; - Defs._IOwnership _out348; - (this).FromOwned(r, expectedOwnership, out _out347, out _out348); - r = _out347; - resultingOwnership = _out348; + RAST._IExpr _out353; + Defs._IOwnership _out354; + (this).FromOwned(r, expectedOwnership, out _out353, out _out354); + r = _out353; + resultingOwnership = _out354; return ; } goto after_match0; @@ -6603,19 +6736,19 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _422_lambda = _source0.dtor_lambda; { RAST._IType _423_tpe; - RAST._IType _out349; - _out349 = (this).GenType(_419_elemType, Defs.GenTypeContext.@default()); - _423_tpe = _out349; + RAST._IType _out355; + _out355 = (this).GenType(_419_elemType, Defs.GenTypeContext.@default()); + _423_tpe = _out355; RAST._IExpr _424_collectionGen; - Defs._IOwnership _425___v151; + Defs._IOwnership _425___v155; Dafny.ISet> _426_recIdents; - RAST._IExpr _out350; - Defs._IOwnership _out351; - Dafny.ISet> _out352; - (this).GenExpr(_420_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out350, out _out351, out _out352); - _424_collectionGen = _out350; - _425___v151 = _out351; - _426_recIdents = _out352; + RAST._IExpr _out356; + Defs._IOwnership _out357; + Dafny.ISet> _out358; + (this).GenExpr(_420_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out356, out _out357, out _out358); + _424_collectionGen = _out356; + _425___v155 = _out357; + _426_recIdents = _out358; Dafny.ISequence _427_extraAttributes; _427_extraAttributes = Dafny.Sequence.FromElements(); if ((((((_420_collection).is_IntRange) || ((_420_collection).is_UnboundedIntRange)) || ((_420_collection).is_SeqBoundedPool)) || ((_420_collection).is_ExactBoundedPool)) || ((_420_collection).is_MultisetBoundedPool)) { @@ -6637,15 +6770,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _435_dt__update_hparams_h0 = _429_newFormals; _433_newLambda = DAST.Expression.create_Lambda(_435_dt__update_hparams_h0, (_434_dt__update__tmp_h1).dtor_retType, (_434_dt__update__tmp_h1).dtor_body); RAST._IExpr _436_lambdaGen; - Defs._IOwnership _437___v152; + Defs._IOwnership _437___v156; Dafny.ISet> _438_recLambdaIdents; - RAST._IExpr _out353; - Defs._IOwnership _out354; - Dafny.ISet> _out355; - (this).GenExpr(_433_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out353, out _out354, out _out355); - _436_lambdaGen = _out353; - _437___v152 = _out354; - _438_recLambdaIdents = _out355; + RAST._IExpr _out359; + Defs._IOwnership _out360; + Dafny.ISet> _out361; + (this).GenExpr(_433_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out359, out _out360, out _out361); + _436_lambdaGen = _out359; + _437___v156 = _out360; + _438_recLambdaIdents = _out361; Dafny.ISequence _439_fn; if (_421_is__forall) { _439_fn = Dafny.Sequence.UnicodeFromString("all"); @@ -6655,16 +6788,16 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir r = ((_424_collectionGen).Sel(_439_fn)).Apply1(((_436_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); readIdents = Dafny.Set>.Union(_426_recIdents, _438_recLambdaIdents); } else { - RAST._IExpr _out356; - _out356 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); - r = _out356; + RAST._IExpr _out362; + _out362 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); + r = _out362; readIdents = Dafny.Set>.FromElements(); } - RAST._IExpr _out357; - Defs._IOwnership _out358; - (this).FromOwned(r, expectedOwnership, out _out357, out _out358); - r = _out357; - resultingOwnership = _out358; + RAST._IExpr _out363; + Defs._IOwnership _out364; + (this).FromOwned(r, expectedOwnership, out _out363, out _out364); + r = _out363; + resultingOwnership = _out364; } } after_match0: ; @@ -6751,15 +6884,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v153; - Dafny.ISet> _2___v154; + Defs._IOwnership _1___v157; + Dafny.ISet> _2___v158; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v153 = _out1; - _2___v154 = _out2; + _1___v157 = _out1; + _2___v158 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index 103c0fd9324..da2947b0c4a 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -400,7 +400,7 @@ public static bool IsNewtypeCopy(DAST._INewtypeRange range) { } public static bool OwnershipGuarantee(Defs._IOwnership expectedOwnership, Defs._IOwnership resultingOwnership) { - return (!(!object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())) || (object.Equals(resultingOwnership, expectedOwnership))) && (!object.Equals(resultingOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())); + return ((!object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwnedBox())) && (!(!object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())) || ((object.Equals(resultingOwnership, expectedOwnership)) || ((object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) && (object.Equals(resultingOwnership, Defs.Ownership.create_OwnershipOwnedBox())))))) && (!object.Equals(resultingOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())); } public static bool BecomesLeftCallsRight(DAST._IBinOp op) { DAST._IBinOp _source0 = op; @@ -546,6 +546,9 @@ public static Dafny.ISequence ASSIGNED__PREFIX { get { public static Dafny.ISequence IND { get { return RAST.__default.IND; } } + public static Dafny.ISet> builtin__trait__preferred__methods { get { + return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("le"), Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.UnicodeFromString("lt"), Dafny.Sequence.UnicodeFromString("ge"), Dafny.Sequence.UnicodeFromString("gt")); + } } public static DAST._IAttribute AttributeOwned { get { return DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("owned"), Dafny.Sequence>.FromElements()); } } @@ -727,6 +730,8 @@ public interface _IEnvironment { Std.Wrappers._IOption GetType(Dafny.ISequence name); bool IsBorrowed(Dafny.ISequence name); bool IsBorrowedMut(Dafny.ISequence name); + bool IsBoxed(Dafny.ISequence name); + bool NeedsAsRefForBorrow(Dafny.ISequence name); Defs._IEnvironment AddAssigned(Dafny.ISequence name, RAST._IType tpe); Defs._IEnvironment merge(Defs._IEnvironment other); Defs._IEnvironment RemoveAssigned(Dafny.ISequence name); @@ -823,6 +828,12 @@ public bool IsBorrowed(Dafny.ISequence name) { public bool IsBorrowedMut(Dafny.ISequence name) { return (((this).dtor_types).Contains(name)) && ((Dafny.Map, RAST._IType>.Select((this).dtor_types,name)).is_BorrowedMut); } + public bool IsBoxed(Dafny.ISequence name) { + return (((this).dtor_types).Contains(name)) && ((Dafny.Map, RAST._IType>.Select((this).dtor_types,name)).IsBox()); + } + public bool NeedsAsRefForBorrow(Dafny.ISequence name) { + return (((this).dtor_types).Contains(name)) && ((Dafny.Map, RAST._IType>.Select((this).dtor_types,name)).NeedsAsRefForBorrow()); + } public Defs._IEnvironment AddAssigned(Dafny.ISequence name, RAST._IType tpe) { return Defs.Environment.create(Dafny.Sequence>.Concat((this).dtor_names, Dafny.Sequence>.FromElements(name)), Dafny.Map, RAST._IType>.Update((this).dtor_types, name, tpe)); diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index 1d87cd6768f..5046c9f1452 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -66,10 +66,10 @@ 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)); + return RAST.Type.create_TypeApp((RAST.__default.BoxPath).AsType(), Dafny.Sequence.FromElements(content)); } public static RAST._IExpr BoxNew(RAST._IExpr content) { - return ((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Box"))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements(content)); + return (((RAST.__default.BoxPath).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements(content)); } public static RAST._IType SystemTupleType(Dafny.ISequence elements) { return ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("_System"))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Tuple"), Std.Strings.__default.OfNat(new BigInteger((elements).Count))))).AsType()).Apply(elements); @@ -198,6 +198,9 @@ public static RAST._IExpr Object { get { public static RAST._IPath PtrPath { get { return (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Ptr")); } } + public static RAST._IPath BoxPath { get { + return ((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("boxed"))).MSel(Dafny.Sequence.UnicodeFromString("Box")); + } } public static RAST._IExpr Ptr { get { return (RAST.__default.PtrPath).AsExpr(); } } @@ -2785,6 +2788,9 @@ public interface _IType { RAST._IType TypeAtInitialization(); bool IsMaybeUninit(); bool IsUninitArray(); + bool IsBox(); + bool NeedsAsRefForBorrow(); + RAST._IType BoxUnderlying(); bool IsObject(); bool IsPointer(); bool IsObjectOrPointer(); @@ -3649,6 +3655,38 @@ public bool IsUninitArray() { return false; } } + public bool IsBox() { + RAST._IType _source0 = this; + { + if (_source0.is_TypeApp) { + RAST._IType baseName0 = _source0.dtor_baseName; + if (baseName0.is_TypeFromPath) { + RAST._IPath _0_o = baseName0.dtor_path; + Dafny.ISequence _1_elems1 = _source0.dtor_arguments; + return (object.Equals(_0_o, RAST.__default.BoxPath)) && ((new BigInteger((_1_elems1).Count)) == (BigInteger.One)); + } + } + } + { + return false; + } + } + public bool NeedsAsRefForBorrow() { + if ((this).is_Borrowed) { + return (((this).dtor_underlying).IsBox()) || (((this).dtor_underlying).IsRc()); + } else { + return ((this).IsBox()) || ((this).IsRc()); + } + } + public RAST._IType BoxUnderlying() { + RAST._IType _source0 = this; + { + RAST._IType baseName0 = _source0.dtor_baseName; + RAST._IPath _0_o = baseName0.dtor_path; + Dafny.ISequence _1_elems1 = _source0.dtor_arguments; + return (_1_elems1).Select(BigInteger.Zero); + } + } public bool IsObject() { RAST._IType _source0 = this; { @@ -5917,6 +5955,7 @@ public interface _IExpr { bool IsLhsIdentifier(); Dafny.ISequence LhsIdentifierName(); RAST._IExpr Clone(); + bool IsBorrow(); } public abstract class Expr : _IExpr { public Expr() { @@ -7340,6 +7379,9 @@ public bool IsLhsIdentifier() { public RAST._IExpr Clone() { return (RAST.Expr.create_Select(this, Dafny.Sequence.UnicodeFromString("clone"))).Apply0(); } + public bool IsBorrow() { + return ((this).is_UnaryOp) && (((this).dtor_op1).Equals(Dafny.Sequence.UnicodeFromString("&"))); + } public RAST._IPrintingInfo printingInfo { get { RAST._IExpr _source0 = this; { diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index 6db6d689b4a..5183d3c55c6 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -3976,20 +3976,32 @@ macro_rules! UpcastObjectFn { }; } - +// This is for Box or traits #[macro_export] macro_rules! UpcastBoxFn { - ($B:ident) => { - fn upcast(&self) -> ::std::boxed::Box { - $B::_clone(self.as_ref()) + (dyn $trait_name:ident<$($type_args:ty),*>) => { + fn upcast(&self) -> ::std::boxed::Box> { + $trait_name::<$($type_args), *>::_clone(self.as_ref()) + } + }; + (dyn $trait_name:ident) => { + fn upcast(&self) -> ::std::boxed::Box { + $trait_name::_clone(self.as_ref()) } }; } + +// This is for datatypes #[macro_export] macro_rules! UpcastStructBoxFn { - ($B:ident) => { - fn upcast(&self) -> ::std::boxed::Box { - $B::_clone(self) + (dyn $trait_name:ident<$($type_args:ty),*>) => { + fn upcast(&self) -> ::std::boxed::Box> { + $trait_name::<$($type_args), *>::_clone(self) + } + }; + (dyn $trait_name:ident) => { + fn upcast(&self) -> ::std::boxed::Box { + $trait_name::_clone(self) } }; } diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index bd850940788..1a210d29b8d 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -1,3 +1,5 @@ +#![allow(nonstandard_style)] + // Test module #[cfg(test)] mod tests { @@ -924,24 +926,24 @@ mod tests { } // Every general trait must declare how to clone a Box of itself - trait GeneralTraitSuper { - fn _clone(&self) -> Box; + trait GeneralTraitSuper { + fn _clone(&self) -> Box>; fn _is_GeneralTrait(&self) -> bool; fn _as_GeneralTrait(&self) -> Box; fn _is_Datatype(&self) -> bool; fn _as_Datatype(&self) -> ADatatype; } - impl Clone for Box { + impl Clone for Box> { fn clone(&self) -> Self { GeneralTraitSuper::_clone(self.as_ref()) } } // Traits extending other traits also implement a direct way to upcast their Box of themselves - trait GeneralTrait: GeneralTraitSuper + UpcastBox { + trait GeneralTrait: GeneralTraitSuper + UpcastBox> { fn _clone(&self) -> Box; } - impl UpcastBox for Box { - UpcastBoxFn!(GeneralTraitSuper); + impl UpcastBox> for Box { + UpcastBoxFn!(dyn GeneralTraitSuper); } impl Clone for Box { fn clone(&self) -> Self { @@ -956,8 +958,8 @@ mod tests { Box::new(self.clone()) as Box } } - impl GeneralTraitSuper for ADatatype { - fn _clone(&self) -> Box { + impl GeneralTraitSuper for ADatatype { + fn _clone(&self) -> Box> { Box::new(self.clone()) } @@ -978,17 +980,17 @@ mod tests { } } impl UpcastBox for ADatatype { - UpcastStructBoxFn!(GeneralTrait); + UpcastStructBoxFn!(dyn GeneralTrait); } - impl UpcastBox for ADatatype { - UpcastStructBoxFn!(GeneralTraitSuper); + impl UpcastBox> for ADatatype { + UpcastStructBoxFn!(dyn GeneralTraitSuper); } #[test] fn test_general_traits() { let x = ADatatype{i: 3}; let gt = upcast_box::()(x.clone()); - let gts = upcast_box::()(x.clone()); - let gtgts = upcast_box_box::()(gt.clone()); + let gts = upcast_box::>()(x.clone()); + let gtgts = upcast_box_box::>()(gt.clone()); assert!(gt._is_Datatype()); assert!(gts._is_Datatype()); assert!(gtgts._is_Datatype()); diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy index a821d081ae6..82cdcc341f7 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy @@ -12,7 +12,7 @@ trait DatatypeOps { } } -datatype ADatatype extends DatatypeOps = ADatatype(i: int) { +datatype {:rust_rc false} ADatatype extends DatatypeOps = ADatatype(i: int) { function AsDatatypeOps(): DatatypeOps { this as DatatypeOps } From f2e38c7f6ebf9e7ce9b1e1fb64fbd2960bd5bd0a Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 25 Nov 2024 14:00:02 -0600 Subject: [PATCH 05/69] Simplified the code further. No box ownership --- .../Rust/Dafny-compiler-rust-definitions.dfy | 9 ++--- .../Backends/Rust/Dafny-compiler-rust.dfy | 38 +------------------ Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 29 +------------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 35 ++--------------- 4 files changed, 9 insertions(+), 102 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 6561e133aa4..0bcd1d43337 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -134,11 +134,10 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { escapeIdent(f.dafny_name) } - // T, &T, &mut T, Box - // Rc, &Rc are counted in T and &T since the type itself is wrapped by Rc + // T, &T, &mut T + // Box, &Box, Rc, &Rc are counted in T datatype Ownership = | OwnershipOwned - | OwnershipOwnedBox | OwnershipBorrowed | OwnershipBorrowedMut | OwnershipAutoBorrowed @@ -436,10 +435,8 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { } predicate OwnershipGuarantee(expectedOwnership: Ownership, resultingOwnership: Ownership) { - && expectedOwnership != OwnershipOwnedBox // We don't ask for a box, but we might get one && (expectedOwnership != OwnershipAutoBorrowed ==> - || resultingOwnership == expectedOwnership - || (expectedOwnership == OwnershipOwned && resultingOwnership == OwnershipOwnedBox)) + resultingOwnership == expectedOwnership) && resultingOwnership != OwnershipAutoBorrowed // We know what's going on } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 1d321522062..7a4e6f13aea 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -2164,13 +2164,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method FromOwned(r: R.Expr, expectedOwnership: Ownership) returns (out: R.Expr, resultingOwnership: Ownership) modifies this - requires expectedOwnership != OwnershipOwnedBox ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) { - if expectedOwnership == OwnershipOwnedBox { - out := R.BoxNew(r); - resultingOwnership := OwnershipOwnedBox; - } else if expectedOwnership == OwnershipOwned || expectedOwnership == OwnershipAutoBorrowed { + if expectedOwnership == OwnershipOwned || expectedOwnership == OwnershipAutoBorrowed { out := r; resultingOwnership := OwnershipOwned; } else if expectedOwnership == OwnershipBorrowed { @@ -2187,7 +2183,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method FromOwnership(r: R.Expr, ownership: Ownership, expectedOwnership: Ownership) returns (out: R.Expr, resultingOwnership: Ownership) requires ownership != OwnershipAutoBorrowed - requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) { @@ -2199,28 +2194,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if ownership == OwnershipOwned { out, resultingOwnership := FromOwned(r, expectedOwnership); return; - } else if ownership == OwnershipOwnedBox { - if expectedOwnership == OwnershipBorrowed { - out := r.Sel("as_ref").Apply0(); - resultingOwnership := OwnershipBorrowed; - } else if expectedOwnership == OwnershipAutoBorrowed { - resultingOwnership := OwnershipOwnedBox; - out := r; - } else if expectedOwnership == OwnershipBorrowedMut { - out := r.Sel("as_mut").Apply0(); // For completeness, not sure we can ever reach that case - resultingOwnership := OwnershipBorrowedMut; - } else if expectedOwnership == OwnershipOwned { - resultingOwnership := OwnershipOwnedBox; - out := r; - } - return; } else if ownership == OwnershipBorrowed || ownership == OwnershipBorrowedMut { if expectedOwnership == OwnershipOwned{ resultingOwnership := OwnershipOwned; out := r.Clone(); - } else if expectedOwnership == OwnershipOwnedBox { - resultingOwnership := OwnershipOwnedBox; - out := R.BoxNew(r.Clone()); } else if expectedOwnership == ownership || expectedOwnership == OwnershipAutoBorrowed { resultingOwnership := ownership; @@ -2247,7 +2224,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.Literal? - requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0 @@ -2399,7 +2375,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.BinOp? - requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0 @@ -2590,7 +2565,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership) requires exprOwnership != OwnershipAutoBorrowed - requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases fromTpe, toTpe // We unwrap newtypes @@ -2866,7 +2840,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { toTpe: Type, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership) - requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) { @@ -2905,7 +2878,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) requires e.Convert? - requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 0 @@ -2930,7 +2902,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) - requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) { @@ -2976,12 +2947,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } resultingOwnership := OwnershipOwned; - } else if expectedOwnership == OwnershipOwnedBox { - if !noNeedOfClone { - r := r.Clone(); // We don't transfer the ownership of an identifier - } - r := R.BoxNew(r); - resultingOwnership := OwnershipOwnedBox; } else if currentlyBorrowed { assert expectedOwnership == OwnershipBorrowed; resultingOwnership := OwnershipBorrowed; @@ -3097,7 +3062,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership, readIdents: set) - requires expectedOwnership != OwnershipOwnedBox modifies this ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) decreases e, 1 { diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 25624a5cdb6..9ccc2a4120b 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -2916,10 +2916,7 @@ public void FromOwned(RAST._IExpr r, Defs._IOwnership expectedOwnership, out RAS { @out = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); - if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwnedBox())) { - @out = RAST.__default.BoxNew(r); - resultingOwnership = Defs.Ownership.create_OwnershipOwnedBox(); - } else if ((object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) || (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipAutoBorrowed()))) { + if ((object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) || (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipAutoBorrowed()))) { @out = r; resultingOwnership = Defs.Ownership.create_OwnershipOwned(); } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipBorrowed())) { @@ -2949,28 +2946,10 @@ public void FromOwnership(RAST._IExpr r, Defs._IOwnership ownership, Defs._IOwne @out = _out0; resultingOwnership = _out1; return ; - } else if (object.Equals(ownership, Defs.Ownership.create_OwnershipOwnedBox())) { - if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipBorrowed())) { - @out = ((r).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); - resultingOwnership = Defs.Ownership.create_OwnershipBorrowed(); - } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())) { - resultingOwnership = Defs.Ownership.create_OwnershipOwnedBox(); - @out = r; - } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipBorrowedMut())) { - @out = ((r).Sel(Dafny.Sequence.UnicodeFromString("as_mut"))).Apply0(); - resultingOwnership = Defs.Ownership.create_OwnershipBorrowedMut(); - } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) { - resultingOwnership = Defs.Ownership.create_OwnershipOwnedBox(); - @out = r; - } - return ; } else if ((object.Equals(ownership, Defs.Ownership.create_OwnershipBorrowed())) || (object.Equals(ownership, Defs.Ownership.create_OwnershipBorrowedMut()))) { if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) { resultingOwnership = Defs.Ownership.create_OwnershipOwned(); @out = (r).Clone(); - } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwnedBox())) { - resultingOwnership = Defs.Ownership.create_OwnershipOwnedBox(); - @out = RAST.__default.BoxNew((r).Clone()); } else if ((object.Equals(expectedOwnership, ownership)) || (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipAutoBorrowed()))) { resultingOwnership = ownership; @out = r; @@ -4241,12 +4220,6 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden } } resultingOwnership = Defs.Ownership.create_OwnershipOwned(); - } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwnedBox())) { - if (!(_3_noNeedOfClone)) { - r = (r).Clone(); - } - r = RAST.__default.BoxNew(r); - resultingOwnership = Defs.Ownership.create_OwnershipOwnedBox(); } else if (_2_currentlyBorrowed) { resultingOwnership = Defs.Ownership.create_OwnershipBorrowed(); } else { diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index da2947b0c4a..44daffe1423 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -400,7 +400,7 @@ public static bool IsNewtypeCopy(DAST._INewtypeRange range) { } public static bool OwnershipGuarantee(Defs._IOwnership expectedOwnership, Defs._IOwnership resultingOwnership) { - return ((!object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwnedBox())) && (!(!object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())) || ((object.Equals(resultingOwnership, expectedOwnership)) || ((object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) && (object.Equals(resultingOwnership, Defs.Ownership.create_OwnershipOwnedBox())))))) && (!object.Equals(resultingOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())); + return (!(!object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())) || (object.Equals(resultingOwnership, expectedOwnership))) && (!object.Equals(resultingOwnership, Defs.Ownership.create_OwnershipAutoBorrowed())); } public static bool BecomesLeftCallsRight(DAST._IBinOp op) { DAST._IBinOp _source0 = op; @@ -565,7 +565,6 @@ public static Dafny.ISequence DAFNY__EXTERN__MODULE { get { public interface _IOwnership { bool is_OwnershipOwned { get; } - bool is_OwnershipOwnedBox { get; } bool is_OwnershipBorrowed { get; } bool is_OwnershipBorrowedMut { get; } bool is_OwnershipAutoBorrowed { get; } @@ -585,9 +584,6 @@ public static Defs._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(); } @@ -598,14 +594,12 @@ 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(); @@ -634,27 +628,6 @@ 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 Defs.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 = "DafnyToRustCompilerDefinitions.Ownership.OwnershipOwnedBox"; - return s; - } - } public class Ownership_OwnershipBorrowed : Ownership { public Ownership_OwnershipBorrowed() : base() { } @@ -668,7 +641,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + 1; return (int) hash; } public override string ToString() { @@ -689,7 +662,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 3; + hash = ((hash << 5) + hash) + 2; return (int) hash; } public override string ToString() { @@ -710,7 +683,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 4; + hash = ((hash << 5) + hash) + 3; return (int) hash; } public override string ToString() { From 535f0613c9ca9e4f13dbee94455660a05e445898 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Tue, 26 Nov 2024 06:10:06 -0600 Subject: [PATCH 06/69] Removed where clauses + WIP upcastBox --- .../FactorPathsOptimizationTest.cs | 4 +- .../Rust/Dafny-compiler-rust-definitions.dfy | 8 -- ...afny-compiler-rust-path-simplification.dfy | 12 +- .../Rust/Dafny-compiler-rust-rast.dfy | 16 +-- .../Backends/Rust/Dafny-compiler-rust.dfy | 18 +-- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 134 +++++++++--------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 16 +-- Source/DafnyCore/GeneratedFromDafny/RAST.cs | 78 ++++------ .../DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 6 +- .../DafnyRuntimeRust/src/tests/mod.rs | 14 +- 10 files changed, 138 insertions(+), 168 deletions(-) diff --git a/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs b/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs index 5d1211e0dae..749438a6e07 100644 --- a/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs +++ b/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs @@ -40,8 +40,8 @@ public static void TestApply() _3_std__any__Any = (((RAST.__default.@global).MSel(Dafny.Sequence.UnicodeFromString("std"))).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any")); RAST._IType _4_Any; _4_Any = RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Any")); - FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_0_T__Decl), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), (_3_std__any__Any).AsType())))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_0_T__Decl), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (_3_std__any__Any).AsType(), ((((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("onemodule"))).MSel(Dafny.Sequence.UnicodeFromString("test"))).AsType()).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), _3_std__any__Any)), RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_1_T__Decl__simp), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), _4_Any)))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), _4_Any, (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements()))))); - FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastObject"))).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastObject")))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("UpcastObject"))).Apply(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements()))))); + FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_0_T__Decl), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), (_3_std__any__Any).AsType())))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_0_T__Decl), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (_3_std__any__Any).AsType(), ((((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("onemodule"))).MSel(Dafny.Sequence.UnicodeFromString("test"))).AsType()).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), _3_std__any__Any)), RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_1_T__Decl__simp), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), _4_Any)))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), _4_Any, (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))); + FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastObject"))).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastObject")))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("UpcastObject"))).Apply(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))); FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_ConstDecl(RAST.Constant.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("dummy"), (_3_std__any__Any).AsType(), RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("doit"), Std.Wrappers.Option.create_Some(((RAST.__default.std__rc__Rc).AsType()).Apply1(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("unknown")))), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("something"))).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_DynType((RAST.__default.std__default__Default).AsType())))).Apply(Dafny.Sequence.FromElements(RAST.__default.std__default__Default__default, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("rd!"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("obj"))))))), RAST.Expr.create_TypeAscription(RAST.Expr.create_ExprFromType(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyString"))).AsType()), ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType"))).AsType()))))))), RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), _3_std__any__Any)), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), RAST.__default.std__rc__Rc)), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), RAST.__default.std__default__Default)), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("rd")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyString")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("dummy"), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Any")), RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("doit"), Std.Wrappers.Option.create_Some((RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Rc"))).Apply1(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("unknown")))), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("something"))).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_DynType(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Default")))))).Apply(Dafny.Sequence.FromElements(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Default"))).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply(Dafny.Sequence.FromElements()), (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("rd!"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("obj"))))))), RAST.Expr.create_TypeAscription(RAST.Expr.create_ExprFromType(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("DafnyString"))), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("DafnyType"))))))))); FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(Dafny.Sequence.FromElements(), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Something")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("dummyExtern"), (((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("anothermodule"))).MSel(Dafny.Sequence.UnicodeFromString("Something"))).AsType(), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing")))), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("dummyIntern"), (((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("onemodule"))).MSel(Dafny.Sequence.UnicodeFromString("Something"))).AsType(), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing"))))))), RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(Dafny.Sequence.FromElements(), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Something")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("dummyExtern"), (((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("anothermodule"))).MSel(Dafny.Sequence.UnicodeFromString("Something"))).AsType(), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing")))), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("dummyIntern"), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Something")), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing"))))))); } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 0bcd1d43337..d933d16979f 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -485,7 +485,6 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { rTypeParamsDecls, R.std.MSel("fmt").MSel("Debug").AsType(), datatypeType, - "", [ R.FnDecl( R.PRIV, @@ -515,7 +514,6 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { rTypeParamsDecls, R.DafnyPrint, datatypeType, - "", [R.FnDecl( R.PRIV, R.Fn( @@ -543,7 +541,6 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { R.Impl( rTypeParamsDecls, datatypeType, - "", [R.FnDecl( R.PUB, R.Fn( @@ -572,7 +569,6 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { R.Impl( rTypeParamsDecls, datatypeType, - "", [R.FnDecl( R.PUB, R.Fn( @@ -596,7 +592,6 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { rTypeParamsDeclsWithHash, R.Hash, datatypeOrNewtypeType, - "", [R.FnDecl( R.PRIV, R.Fn( @@ -625,7 +620,6 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { rTypeParamsDecls, R.std.MSel("ops").MSel(traitName).AsType(), newtypeType, - "", [ R.TypeDeclMember("Output", newtypeType), R.FnDecl( R.PRIV, @@ -662,7 +656,6 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { rTypeParamsDecls, R.std.MSel("ops").MSel(traitName).AsType(), newtypeType, - "", [ R.TypeDeclMember("Output", newtypeType), R.FnDecl( R.PRIV, @@ -693,7 +686,6 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { rTypeParamsDecls, R.std.MSel("cmp").MSel("PartialOrd").AsType(), newtypeType, - "", [ R.FnDecl( R.PRIV, R.Fn( diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy index 54b947ad870..fa63ce28557 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy @@ -28,10 +28,10 @@ module FactorPathsOptimizationTest { Struct([], "test", [T_Decl], NamedFields([Field(PUB, Formal("a", std_any_Any.AsType()))]))), // ::std::any::Any ==> Any - ImplDecl(Impl([T_Decl], TIdentifier("test").Apply([T]), "", [])), + ImplDecl(Impl([T_Decl], TIdentifier("test").Apply([T]), [])), ImplDecl( ImplFor( - [T_Decl], std_any_Any.AsType(), crate.MSel("onemodule").MSel("test").AsType().Apply([T]), "", [])) + [T_Decl], std_any_Any.AsType(), crate.MSel("onemodule").MSel("test").AsType().Apply([T]), [])) // ::std::any::Any ==> Any crate::onemodule::test ==> test ])), Mod( @@ -41,8 +41,8 @@ module FactorPathsOptimizationTest { StructDecl( Struct([], "test", [T_Decl_simp], NamedFields([Field(PUB, Formal("a", Any))]))), - ImplDecl(Impl([T_Decl_simp], TIdentifier("test").Apply([T]), "", [])), - ImplDecl(ImplFor([T_Decl_simp], Any, TIdentifier("test").Apply([T]), "", [])) + ImplDecl(Impl([T_Decl_simp], TIdentifier("test").Apply([T]), [])), + ImplDecl(ImplFor([T_Decl_simp], Any, TIdentifier("test").Apply([T]), [])) ])); ShouldBeEqual( apply(crate)( @@ -51,7 +51,7 @@ module FactorPathsOptimizationTest { ImplDecl( ImplFor( [T_Decl], dafny_runtime.MSel("UpcastObject").AsType().Apply([TIdentifier("x")]), - TIdentifier("test").Apply([T]), "", [])) + TIdentifier("test").Apply([T]), [])) ])), Mod( "onemodule", [], [ @@ -60,7 +60,7 @@ module FactorPathsOptimizationTest { ImplDecl( ImplFor( [T_Decl_simp], TIdentifier("UpcastObject").Apply([TIdentifier("x")]), - TIdentifier("test").Apply([T]), "", [])) + TIdentifier("test").Apply([T]), [])) ])); ShouldBeEqual( apply(crate)( diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index 25fa8065b30..1d84729d2a7 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -112,13 +112,13 @@ module RAST function VisitImplMapping(acc: T, impl: Impl): T { match impl { - case ImplFor(typeParams, tpe, forType, where, body) => + case ImplFor(typeParams, tpe, forType, body) => var acc := VisitTypeParams(acc, typeParams); var acc := VisitType(acc, tpe); var acc := VisitType(acc, forType); VisitBody(acc, body) // TODO: Add body - case Impl(typeParams, tpe, where, body) => + case Impl(typeParams, tpe, body) => var acc := VisitType(acc, tpe); VisitBody(acc, body) } @@ -243,15 +243,14 @@ module RAST function ReplaceImplDecl(impl: Impl): Impl { match impl { - case ImplFor(typeParams, tpe, forType, where, body) => + case ImplFor(typeParams, tpe, forType, body) => ImplFor( ReplaceTypeParams(typeParams), ReplaceType(tpe), ReplaceType(forType), - where, ReplaceBody(body)) - case Impl(typeParams, tpe, where, body) => - Impl(ReplaceTypeParams(typeParams), ReplaceType(tpe), where, ReplaceBody(body)) + case Impl(typeParams, tpe, body) => + Impl(ReplaceTypeParams(typeParams), ReplaceType(tpe), ReplaceBody(body)) } } @@ -1118,13 +1117,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, body: seq) + | Impl(typeParams: seq, tpe: Type, body: seq) { function ToString(ind: string): string { "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), "") + (if |body| == 0 then "" else "\n" + ind) + "}" diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 7a4e6f13aea..5abf8f164a5 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -317,7 +317,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, fullTraitPath, R.TypeApp(genSelfPath, rTypeParams), - "", body )); s := s + [x]; @@ -335,7 +334,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.dafny_runtime.MSel(upcastTraitToImplement).AsType().Apply([ R.DynType(fullTraitPath)]), R.TypeApp(genSelfPath, rTypeParams), - "", [ R.ImplMemberMacro( R.dafny_runtime @@ -432,7 +430,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var i := R.Impl( rTypeParamsDecls, R.TypeApp(selfTypeForImpl, rTypeParams), - "", implBody ); s := s + [R.ImplDecl(i)]; @@ -466,7 +463,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.dafny_runtime.MSel(Upcast).AsType().Apply([R.DynType(R.AnyTrait)]), R.TypeApp(genSelfPath, rTypeParams), - "", [ R.ImplMemberMacro( R.dafny_runtime @@ -548,10 +544,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.dafny_runtime.MSel("UpcastBox").AsType().Apply1(R.DynType(parentTpe)), R.Box(R.DynType(traitFulltype)), - "", [ R.ImplMemberMacro( R.dafny_runtime - .MSel("UpcastBoxFn").AsExpr() + .MSel("UpcastBoxFn!").AsExpr() .Apply1(R.ExprFromType(parentTpe)))])) ]; } @@ -575,7 +570,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.std.MSel("clone").MSel("Clone").AsType(), R.Box(R.DynType(traitFulltype)), - "", [R.FnDecl( R.PRIV, R.Fn("clone", [], @@ -659,7 +653,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Impl( rTypeParamsDecls, resultingType, - "", [ R.FnDecl( R.PUB, @@ -678,7 +671,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.DefaultTrait, resultingType, - "", [body]))]; s := s + [ R.ImplDecl( @@ -686,7 +678,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.DafnyPrint, resultingType, - "", [R.FnDecl( R.PRIV, R.Fn("fmt_print", [], @@ -706,7 +697,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.std.MSel("ops").MSel("Deref").AsType(), resultingType, - "", [R.TypeDeclMember("Target", wrappedType), R.FnDecl( R.PRIV, @@ -721,7 +711,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Impl( rTypeParamsDecls, resultingType, - "", [R.FnDecl( R.PUB, R.Fn( @@ -767,7 +756,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Impl( rTypeParamsDecls, R.TypeApp(R.TIdentifier(newtypeName), rTypeParams), - "", implementation ) )]; @@ -1059,7 +1047,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Impl( rTypeParamsDecls, R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), - "", implBody ))]; @@ -1225,7 +1212,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDeclsWithEq, R.Eq, R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), - "", [] ) )]; @@ -1262,7 +1248,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { defaultConstrainedTypeParams, R.DefaultTrait, fullType, - "", [R.FnDecl( R.PRIV, R.Fn( @@ -1284,7 +1269,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.std.MSel("convert").MSel("AsRef").AsType().Apply1(fullType), R.Borrowed(fullType), - "", [R.FnDecl( R.PRIV, R.Fn("as_ref", [], [R.Formal.selfBorrowed], Some(R.SelfOwned), diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 9ccc2a4120b..6d97cb762dc 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -339,7 +339,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } } RAST._IModDecl _14_x; - _14_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _10_fullTraitPath, RAST.Type.create_TypeApp(_0_genSelfPath, rTypeParams), Dafny.Sequence.UnicodeFromString(""), _9_body)); + _14_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _10_fullTraitPath, RAST.Type.create_TypeApp(_0_genSelfPath, rTypeParams), _9_body)); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_14_x)); Dafny.ISequence _15_upcastTraitToImplement = Dafny.Sequence.Empty; Dafny.ISequence _16_upcastTraitFn = Dafny.Sequence.Empty; @@ -354,7 +354,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _15_upcastTraitToImplement = _rhs2; _16_upcastTraitFn = _rhs3; } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(_15_upcastTraitToImplement)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_10_fullTraitPath))), RAST.Type.create_TypeApp(_0_genSelfPath, rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel(_16_upcastTraitFn)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_10_fullTraitPath))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(_15_upcastTraitToImplement)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_10_fullTraitPath))), RAST.Type.create_TypeApp(_0_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel(_16_upcastTraitFn)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_10_fullTraitPath))))))))); } goto after_match0; } @@ -461,7 +461,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } if ((new BigInteger((_19_implBody).Count)).Sign == 1) { RAST._IImpl _22_i; - _22_i = RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(_21_selfTypeForImpl, _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), _19_implBody); + _22_i = RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(_21_selfTypeForImpl, _1_rTypeParams), _19_implBody); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(_22_i))); } Dafny.ISequence _23_testMethods; @@ -489,7 +489,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _out13 = (this).GenPathType(path); _28_genSelfPath = _out13; if (!(_16_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(RAST.__default.AnyTrait))), RAST.Type.create_TypeApp(_28_genSelfPath, _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(RAST.__default.AnyTrait))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(RAST.__default.AnyTrait))), RAST.Type.create_TypeApp(_28_genSelfPath, _1_rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(RAST.__default.AnyTrait))))))))); } Dafny.ISequence _29_superTraitTypes; if ((_16_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { @@ -573,12 +573,12 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } _14_parents = Dafny.Sequence.Concat(_14_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_19_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)))); if ((_17_parentTyp).IsGeneralTrait()) { - _15_upcastImplemented = Dafny.Sequence.Concat(_15_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBoxFn"))).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(_18_parentTpe)))))))); + _15_upcastImplemented = Dafny.Sequence.Concat(_15_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBoxFn!"))).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(_18_parentTpe)))))))); } } s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_rTypeParamsDecls, _10_traitFulltype, _14_parents, _12_implBody))); if (((t).dtor_traitType).is_GeneralTrait) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); } s = Dafny.Sequence.Concat(s, _15_upcastImplemented); return s; @@ -676,13 +676,13 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc Dafny.ISequence _out10; _out10 = (this).GenParams(Dafny.Sequence.FromElements(_17_formal), false); _22_rFormals = _out10; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _22_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_19_rStmts)))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _22_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_19_rStmts)))))))); } after_match1: ; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _8_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(_16_body))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _8_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsType(), _8_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Target"), _4_wrappedType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("deref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(((RAST.Path.create_Self()).MSel(Dafny.Sequence.UnicodeFromString("Target"))).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_from_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("o"), RAST.Type.create_Borrowed(_4_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("transmute"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("o"))))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _8_resultingType, Dafny.Sequence.FromElements(_16_body))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsType(), _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Target"), _4_wrappedType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("deref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(((RAST.Path.create_Self()).MSel(Dafny.Sequence.UnicodeFromString("Target"))).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_from_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("o"), RAST.Type.create_Borrowed(_4_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("transmute"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("o"))))))))))))); Dafny.ISequence _23_rTypeParamsDeclsWithHash; _23_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_23_rTypeParamsDeclsWithHash, _8_resultingType, (((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))).Sel(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))); @@ -703,7 +703,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("No support for trait in newtypes yet")); } if ((new BigInteger((_24_implementation).Count)).Sign == 1) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), _24_implementation)))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams), _24_implementation)))); } return s; } @@ -1118,7 +1118,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } bool _67_cIsEq; _67_cIsEq = (this).DatatypeIsEq(c); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create(((_67_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _3_datatypeName, _2_rTypeParamsDecls, _5_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), _26_implBody))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create(((_67_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _3_datatypeName, _2_rTypeParamsDecls, _5_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), _26_implBody))); Dafny.ISequence _68_printImplBodyCases; _68_printImplBodyCases = Dafny.Sequence.FromElements(); Dafny.ISequence _69_hashImplBodyCases; @@ -1247,7 +1247,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_2_rTypeParamsDecls, _98_datatypeType, _100_instantiationType, _8_singletonConstructors))); } if (_67_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_94_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements())))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_94_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), Dafny.Sequence.FromElements())))); } s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_95_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), _97_hashImplBody))); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { @@ -1266,9 +1266,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) RAST._IType _106_fullType; _106_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams); if (_67_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_105_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, _106_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(_106_fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_101_structName, _102_structAssignments))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_105_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, _106_fullType, 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(_106_fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_101_structName, _102_structAssignments))))))))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsType()).Apply1(_106_fullType), RAST.Type.create_Borrowed(_106_fullType), Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self)))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsType()).Apply1(_106_fullType), RAST.Type.create_Borrowed(_106_fullType), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self)))))))); } Dafny.ISequence _107_superTraitImplementations; Dafny.ISequence _out16; @@ -3167,7 +3167,7 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } after_match0: ; } - public RAST._IExpr ToPrimitive(RAST._IExpr r, DAST._IType typ, DAST._IType primitiveType) + public RAST._IExpr ToPrimitive(RAST._IExpr r, DAST._IType typ, DAST._IType primitiveType, Defs._IEnvironment env) { RAST._IExpr @out = RAST.Expr.Default(); @out = r; @@ -3175,29 +3175,29 @@ public RAST._IExpr ToPrimitive(RAST._IExpr r, DAST._IType typ, DAST._IType primi Defs._IOwnership _0_dummy = Defs.Ownership.Default(); RAST._IExpr _out0; Defs._IOwnership _out1; - (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), typ, primitiveType, Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1); + (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), typ, primitiveType, env, Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1); @out = _out0; _0_dummy = _out1; } return @out; } - public RAST._IExpr ToBool(RAST._IExpr r, DAST._IType typ) + public RAST._IExpr ToBool(RAST._IExpr r, DAST._IType typ, Defs._IEnvironment env) { RAST._IExpr @out = RAST.Expr.Default(); RAST._IExpr _out0; - _out0 = (this).ToPrimitive(r, typ, DAST.Type.create_Primitive(DAST.Primitive.create_Bool())); + _out0 = (this).ToPrimitive(r, typ, DAST.Type.create_Primitive(DAST.Primitive.create_Bool()), env); @out = _out0; return @out; } - public RAST._IExpr ToInt(RAST._IExpr r, DAST._IType typ) + public RAST._IExpr ToInt(RAST._IExpr r, DAST._IType typ, Defs._IEnvironment env) { RAST._IExpr @out = RAST.Expr.Default(); RAST._IExpr _out0; - _out0 = (this).ToPrimitive(r, typ, DAST.Type.create_Primitive(DAST.Primitive.create_Int())); + _out0 = (this).ToPrimitive(r, typ, DAST.Type.create_Primitive(DAST.Primitive.create_Int()), env); @out = _out0; return @out; } - public RAST._IExpr FromPrimitive(RAST._IExpr r, DAST._IType primitiveType, DAST._IType typ) + public RAST._IExpr FromPrimitive(RAST._IExpr r, DAST._IType primitiveType, DAST._IType typ, Defs._IEnvironment env) { RAST._IExpr @out = RAST.Expr.Default(); @out = r; @@ -3205,25 +3205,25 @@ public RAST._IExpr FromPrimitive(RAST._IExpr r, DAST._IType primitiveType, DAST. Defs._IOwnership _0_dummy = Defs.Ownership.Default(); RAST._IExpr _out0; Defs._IOwnership _out1; - (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), primitiveType, typ, Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1); + (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), primitiveType, typ, env, Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1); @out = _out0; _0_dummy = _out1; } return @out; } - public RAST._IExpr FromBool(RAST._IExpr r, DAST._IType typ) + public RAST._IExpr FromBool(RAST._IExpr r, DAST._IType typ, Defs._IEnvironment env) { RAST._IExpr @out = RAST.Expr.Default(); RAST._IExpr _out0; - _out0 = (this).FromPrimitive(r, DAST.Type.create_Primitive(DAST.Primitive.create_Bool()), typ); + _out0 = (this).FromPrimitive(r, DAST.Type.create_Primitive(DAST.Primitive.create_Bool()), typ, env); @out = _out0; return @out; } - public RAST._IExpr FromInt(RAST._IExpr r, DAST._IType typ) + public RAST._IExpr FromInt(RAST._IExpr r, DAST._IType typ, Defs._IEnvironment env) { RAST._IExpr @out = RAST.Expr.Default(); RAST._IExpr _out0; - _out0 = (this).FromPrimitive(r, DAST.Type.create_Primitive(DAST.Primitive.create_Int()), typ); + _out0 = (this).FromPrimitive(r, DAST.Type.create_Primitive(DAST.Primitive.create_Int()), typ, env); @out = _out0; return @out; } @@ -3427,25 +3427,25 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ if ((Defs.__default.OpTable).Contains(_0_op)) { if (Defs.__default.IsBooleanOperator(_0_op)) { RAST._IExpr _out6; - _out6 = (this).ToBool(_11_left, _1_lType); + _out6 = (this).ToBool(_11_left, _1_lType, env); _11_left = _out6; RAST._IExpr _out7; - _out7 = (this).ToBool(_14_right, _2_rType); + _out7 = (this).ToBool(_14_right, _2_rType, env); _14_right = _out7; } r = RAST.Expr.create_BinaryOp(Dafny.Map>.Select(Defs.__default.OpTable,_0_op), _11_left, _14_right, _6_format); if (Defs.__default.IsBooleanOperator(_0_op)) { RAST._IExpr _out8; - _out8 = (this).FromBool(r, _3_resType); + _out8 = (this).FromBool(r, _3_resType, env); r = _out8; } } else { if (Defs.__default.IsComplexArithmetic(_0_op)) { RAST._IExpr _out9; - _out9 = (this).ToInt(_11_left, _1_lType); + _out9 = (this).ToInt(_11_left, _1_lType, env); _11_left = _out9; RAST._IExpr _out10; - _out10 = (this).ToInt(_14_right, _2_rType); + _out10 = (this).ToInt(_14_right, _2_rType, env); _14_right = _out10; } DAST._IBinOp _source1 = _0_op; @@ -3471,7 +3471,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ if (!object.Equals(_3_resType, DAST.Type.create_Primitive(DAST.Primitive.create_Bool()))) { RAST._IExpr _out12; Defs._IOwnership _out13; - (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), DAST.Type.create_Primitive(DAST.Primitive.create_Bool()), _3_resType, Defs.Ownership.create_OwnershipOwned(), out _out12, out _out13); + (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), DAST.Type.create_Primitive(DAST.Primitive.create_Bool()), _3_resType, env, Defs.Ownership.create_OwnershipOwned(), out _out12, out _out13); r = _out12; resultingOwnership = _out13; } @@ -3542,7 +3542,7 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ after_match1: ; if (Defs.__default.IsComplexArithmetic(_0_op)) { RAST._IExpr _out14; - _out14 = (this).FromInt(r, _3_resType); + _out14 = (this).FromInt(r, _3_resType, env); r = _out14; } } @@ -3588,7 +3588,7 @@ public RAST._IExpr WrapWithNewtype(RAST._IExpr expr, Defs._IOwnership exprOwners } return r; } - public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) + public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) { r = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); @@ -3604,7 +3604,7 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D if (((fromTpe).is_UserDefined) && ((((fromTpe).dtor_resolved).dtor_kind).is_SynonymType)) { RAST._IExpr _out2; Defs._IOwnership _out3; - (this).GenExprConvertTo(expr, exprOwnership, (((fromTpe).dtor_resolved).dtor_kind).dtor_baseType, toTpe, expectedOwnership, out _out2, out _out3); + (this).GenExprConvertTo(expr, exprOwnership, (((fromTpe).dtor_resolved).dtor_kind).dtor_baseType, toTpe, env, expectedOwnership, out _out2, out _out3); r = _out2; resultingOwnership = _out3; return ; @@ -3612,7 +3612,7 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D if (((toTpe).is_UserDefined) && ((((toTpe).dtor_resolved).dtor_kind).is_SynonymType)) { RAST._IExpr _out4; Defs._IOwnership _out5; - (this).GenExprConvertTo(expr, exprOwnership, fromTpe, (((toTpe).dtor_resolved).dtor_kind).dtor_baseType, expectedOwnership, out _out4, out _out5); + (this).GenExprConvertTo(expr, exprOwnership, fromTpe, (((toTpe).dtor_resolved).dtor_kind).dtor_baseType, env, expectedOwnership, out _out4, out _out5); r = _out4; resultingOwnership = _out5; return ; @@ -3623,7 +3623,7 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D r = _out6; RAST._IExpr _out7; Defs._IOwnership _out8; - (this).GenExprConvertTo(r, exprOwnership, (((fromTpe).dtor_resolved).dtor_kind).dtor_baseType, toTpe, expectedOwnership, out _out7, out _out8); + (this).GenExprConvertTo(r, exprOwnership, (((fromTpe).dtor_resolved).dtor_kind).dtor_baseType, toTpe, env, expectedOwnership, out _out7, out _out8); r = _out7; resultingOwnership = _out8; return ; @@ -3633,7 +3633,7 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D _0_toKind = ((toTpe).dtor_resolved).dtor_kind; RAST._IExpr _out9; Defs._IOwnership _out10; - (this).GenExprConvertTo(r, exprOwnership, fromTpe, (_0_toKind).dtor_baseType, expectedOwnership, out _out9, out _out10); + (this).GenExprConvertTo(r, exprOwnership, fromTpe, (_0_toKind).dtor_baseType, env, expectedOwnership, out _out9, out _out10); r = _out9; resultingOwnership = _out10; RAST._IExpr _out11; @@ -3891,7 +3891,7 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D { RAST._IExpr _out48; Defs._IOwnership _out49; - (this).GenExprConvertOther(expr, exprOwnership, fromTpe, toTpe, expectedOwnership, out _out48, out _out49); + (this).GenExprConvertOther(expr, exprOwnership, fromTpe, toTpe, env, expectedOwnership, out _out48, out _out49); r = _out48; resultingOwnership = _out49; } @@ -4053,7 +4053,27 @@ public bool IsDowncastConversion(RAST._IType fromTpe, RAST._IType toTpe) return false; } } - public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) + public RAST._IExpr BorrowedToOwned(RAST._IExpr expr, Defs._IEnvironment env) + { + RAST._IExpr _source0 = expr; + { + if (_source0.is_UnaryOp) { + Dafny.ISequence op10 = _source0.dtor_op1; + if (object.Equals(op10, Dafny.Sequence.UnicodeFromString("&"))) { + RAST._IExpr _0_underlying = _source0.dtor_underlying; + if (((_0_underlying).is_Identifier) && ((env).CanReadWithoutClone((_0_underlying).dtor_name))) { + return _0_underlying; + } else { + return (_0_underlying).Clone(); + } + } + } + } + { + return (expr).Clone(); + } + } + public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) { r = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); @@ -4072,21 +4092,7 @@ public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership RAST._IExpr _3_conversionLambda; _3_conversionLambda = (_2_upcastConverter).dtor_value; if (object.Equals(exprOwnership, Defs.Ownership.create_OwnershipBorrowed())) { - RAST._IExpr _source0 = r; - { - if (_source0.is_UnaryOp) { - Dafny.ISequence op10 = _source0.dtor_op1; - if (object.Equals(op10, Dafny.Sequence.UnicodeFromString("&"))) { - RAST._IExpr _4_underlying = _source0.dtor_underlying; - r = _4_underlying; - goto after_match0; - } - } - } - { - r = (r).Clone(); - } - after_match0: ; + r = (this).BorrowedToOwned(r, env); } r = (_3_conversionLambda).Apply1(r); RAST._IExpr _out2; @@ -4105,13 +4111,13 @@ public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership } else { Std.Wrappers._IResult,RAST._IExpr>>> _let_tmp_rhs0 = _2_upcastConverter; _System._ITuple5,RAST._IExpr>> _let_tmp_rhs1 = _let_tmp_rhs0.dtor_error; - DAST._IType _5_fromType = _let_tmp_rhs1.dtor__0; - RAST._IType _6_fromTpeGen = _let_tmp_rhs1.dtor__1; - DAST._IType _7_toType = _let_tmp_rhs1.dtor__2; - RAST._IType _8_toTpeGen = _let_tmp_rhs1.dtor__3; - Dafny.IMap<_System._ITuple2,RAST._IExpr> _9_m = _let_tmp_rhs1.dtor__4; + DAST._IType _4_fromType = _let_tmp_rhs1.dtor__0; + RAST._IType _5_fromTpeGen = _let_tmp_rhs1.dtor__1; + DAST._IType _6_toType = _let_tmp_rhs1.dtor__2; + RAST._IType _7_toTpeGen = _let_tmp_rhs1.dtor__3; + Dafny.IMap<_System._ITuple2,RAST._IExpr> _8_m = _let_tmp_rhs1.dtor__4; RAST._IExpr _out6; - _out6 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Coercion from "), (_6_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_8_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), r); + _out6 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Coercion from "), (_5_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_7_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), r); r = _out6; RAST._IExpr _out7; Defs._IOwnership _out8; @@ -4148,7 +4154,7 @@ public void GenExprConvert(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. readIdents = _6_recIdents; RAST._IExpr _out3; Defs._IOwnership _out4; - (this).GenExprConvertTo(r, _5_recOwned, _1_fromTpe, _2_toTpe, expectedOwnership, out _out3, out _out4); + (this).GenExprConvertTo(r, _5_recOwned, _1_fromTpe, _2_toTpe, env, expectedOwnership, out _out3, out _out4); r = _out3; resultingOwnership = _out4; return ; diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index 44daffe1423..a8768c459ef 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -470,23 +470,23 @@ public static RAST._IExpr UnreachablePanicIfVerified(Defs._IPointerType pointerT } public static RAST._IModDecl DebugImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, Dafny.ISequence rTypeParams) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Debug"))).AsType(), datatypeType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("f"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType()))), Std.Wrappers.Option.create_Some((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(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))))))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Debug"))).AsType(), datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("f"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType()))), Std.Wrappers.Option.create_Some((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(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))))))))); } public static RAST._IModDecl PrintImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, Dafny.ISequence rTypeParams, RAST._IExpr printImplBody) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, RAST.__default.DafnyPrint, datatypeType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("std::fmt::Result"))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(printImplBody)))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, RAST.__default.DafnyPrint, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("std::fmt::Result"))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(printImplBody)))))); } public static RAST._IModDecl CoerceImpl(Dafny.ISequence rTypeParamsDecls, Dafny.ISequence datatypeName, RAST._IType datatypeType, Dafny.ISequence rCoerceTypeParams, Dafny.ISequence coerceArguments, Dafny.ISequence coerceTypes, RAST._IExpr coerceImplBody) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("coerce"), rCoerceTypeParams, coerceArguments, Std.Wrappers.Option.create_Some(RAST.__default.Rc(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(datatypeType), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes))))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.RcNew(RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("this"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes)), coerceImplBody)))))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("coerce"), rCoerceTypeParams, coerceArguments, Std.Wrappers.Option.create_Some(RAST.__default.Rc(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(datatypeType), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes))))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.RcNew(RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("this"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes)), coerceImplBody)))))))); } public static RAST._IModDecl SingletonsImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, RAST._IType instantiationType, Dafny.ISequence singletonConstructors) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_AllSingletonConstructors"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SequenceIter"))).AsType()).Apply(Dafny.Sequence.FromElements(instantiationType))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).AsExpr()).Apply(singletonConstructors)).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0())))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_AllSingletonConstructors"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SequenceIter"))).AsType()).Apply(Dafny.Sequence.FromElements(instantiationType))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).AsExpr()).Apply(singletonConstructors)).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0())))))); } public static RAST._IModDecl HashImpl(Dafny.ISequence rTypeParamsDeclsWithHash, RAST._IType datatypeOrNewtypeType, RAST._IExpr hashImplBody) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithHash, RAST.__default.Hash, datatypeOrNewtypeType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Dafny.Sequence.FromElements(RAST.TypeParamDecl.create(Dafny.Sequence.UnicodeFromString("_H"), Dafny.Sequence.FromElements((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hasher"))).AsType()))), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_state"), RAST.Type.create_BorrowedMut(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_H"))))), Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(hashImplBody)))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithHash, RAST.__default.Hash, datatypeOrNewtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Dafny.Sequence.FromElements(RAST.TypeParamDecl.create(Dafny.Sequence.UnicodeFromString("_H"), Dafny.Sequence.FromElements((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hasher"))).AsType()))), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_state"), RAST.Type.create_BorrowedMut(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_H"))))), Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(hashImplBody)))))); } public static RAST._IModDecl UnaryOpsImpl(Dafny.Rune op, Dafny.ISequence rTypeParamsDecls, RAST._IType newtypeType, Dafny.ISequence newtypeConstructor) { @@ -498,7 +498,7 @@ public static RAST._IModDecl UnaryOpsImpl(Dafny.Rune op, Dafny.ISequence _0_traitName = _let_tmp_rhs0.dtor__0; Dafny.ISequence _1_methodName = _let_tmp_rhs0.dtor__1; - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(_0_traitName)).AsType(), newtypeType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Output"), newtypeType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(_1_methodName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfOwned), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((RAST.Expr.create_Identifier(newtypeConstructor)).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.FromElements(op), (RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.UnaryOpFormat.create_NoFormat())))))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(_0_traitName)).AsType(), newtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Output"), newtypeType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(_1_methodName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfOwned), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((RAST.Expr.create_Identifier(newtypeConstructor)).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.FromElements(op), (RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.UnaryOpFormat.create_NoFormat())))))))); } public static RAST._IModDecl OpsImpl(Dafny.Rune op, Dafny.ISequence rTypeParamsDecls, RAST._IType newtypeType, Dafny.ISequence newtypeConstructor) { @@ -525,11 +525,11 @@ public static RAST._IModDecl OpsImpl(Dafny.Rune op, Dafny.ISequence _0_traitName = _let_tmp_rhs0.dtor__0; Dafny.ISequence _1_methodName = _let_tmp_rhs0.dtor__1; - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(_0_traitName)).AsType(), newtypeType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Output"), newtypeType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(_1_methodName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfOwned, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((RAST.Expr.create_Identifier(newtypeConstructor)).Apply1(RAST.Expr.create_BinaryOp(Dafny.Sequence.FromElements(op), (RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.BinaryOpFormat.create_NoFormat())))))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(_0_traitName)).AsType(), newtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Output"), newtypeType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(_1_methodName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfOwned, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((RAST.Expr.create_Identifier(newtypeConstructor)).Apply1(RAST.Expr.create_BinaryOp(Dafny.Sequence.FromElements(op), (RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.BinaryOpFormat.create_NoFormat())))))))); } public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType newtypeType, Dafny.ISequence newtypeConstructor) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsType(), newtypeType, Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("partial_cmp"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("option"))).MSel(Dafny.Sequence.UnicodeFromString("Option"))).AsType()).Apply1((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Ordering"))).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("partial_cmp"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.__default.Borrow((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsType(), newtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("partial_cmp"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("option"))).MSel(Dafny.Sequence.UnicodeFromString("Option"))).AsType()).Apply1((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Ordering"))).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("partial_cmp"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.__default.Borrow((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); } public static Dafny.ISet> reserved__rust { get { return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("as"), Dafny.Sequence.UnicodeFromString("async"), Dafny.Sequence.UnicodeFromString("await"), Dafny.Sequence.UnicodeFromString("break"), Dafny.Sequence.UnicodeFromString("const"), Dafny.Sequence.UnicodeFromString("continue"), Dafny.Sequence.UnicodeFromString("crate"), Dafny.Sequence.UnicodeFromString("dyn"), Dafny.Sequence.UnicodeFromString("else"), Dafny.Sequence.UnicodeFromString("enum"), Dafny.Sequence.UnicodeFromString("extern"), Dafny.Sequence.UnicodeFromString("false"), Dafny.Sequence.UnicodeFromString("fn"), Dafny.Sequence.UnicodeFromString("for"), Dafny.Sequence.UnicodeFromString("if"), Dafny.Sequence.UnicodeFromString("impl"), Dafny.Sequence.UnicodeFromString("in"), Dafny.Sequence.UnicodeFromString("let"), Dafny.Sequence.UnicodeFromString("loop"), Dafny.Sequence.UnicodeFromString("match"), Dafny.Sequence.UnicodeFromString("mod"), Dafny.Sequence.UnicodeFromString("move"), Dafny.Sequence.UnicodeFromString("mut"), Dafny.Sequence.UnicodeFromString("pub"), Dafny.Sequence.UnicodeFromString("ref"), Dafny.Sequence.UnicodeFromString("return"), Dafny.Sequence.UnicodeFromString("static"), Dafny.Sequence.UnicodeFromString("struct"), Dafny.Sequence.UnicodeFromString("super"), Dafny.Sequence.UnicodeFromString("trait"), Dafny.Sequence.UnicodeFromString("true"), Dafny.Sequence.UnicodeFromString("type"), Dafny.Sequence.UnicodeFromString("union"), Dafny.Sequence.UnicodeFromString("unsafe"), Dafny.Sequence.UnicodeFromString("use"), Dafny.Sequence.UnicodeFromString("where"), Dafny.Sequence.UnicodeFromString("while"), Dafny.Sequence.UnicodeFromString("Keywords"), Dafny.Sequence.UnicodeFromString("The"), Dafny.Sequence.UnicodeFromString("abstract"), Dafny.Sequence.UnicodeFromString("become"), Dafny.Sequence.UnicodeFromString("box"), Dafny.Sequence.UnicodeFromString("do"), Dafny.Sequence.UnicodeFromString("final"), Dafny.Sequence.UnicodeFromString("macro"), Dafny.Sequence.UnicodeFromString("override"), Dafny.Sequence.UnicodeFromString("priv"), Dafny.Sequence.UnicodeFromString("try"), Dafny.Sequence.UnicodeFromString("typeof"), Dafny.Sequence.UnicodeFromString("unsized"), Dafny.Sequence.UnicodeFromString("virtual"), Dafny.Sequence.UnicodeFromString("yield")); diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index 5046c9f1452..5f2fbfec458 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -556,21 +556,19 @@ public T VisitImplMapping(T acc, RAST._IImpl impl) Dafny.ISequence _0_typeParams = _source0.dtor_typeParams; RAST._IType _1_tpe = _source0.dtor_tpe; RAST._IType _2_forType = _source0.dtor_forType; - Dafny.ISequence _3_where = _source0.dtor_where; - Dafny.ISequence _4_body = _source0.dtor_body; - T _5_acc = (this).VisitTypeParams(acc, _0_typeParams); - T _6_acc = (this).VisitType(_5_acc, _1_tpe); - T _7_acc = (this).VisitType(_6_acc, _2_forType); - return (this).VisitBody(_7_acc, _4_body); + Dafny.ISequence _3_body = _source0.dtor_body; + T _4_acc = (this).VisitTypeParams(acc, _0_typeParams); + T _5_acc = (this).VisitType(_4_acc, _1_tpe); + T _6_acc = (this).VisitType(_5_acc, _2_forType); + return (this).VisitBody(_6_acc, _3_body); } } { - Dafny.ISequence _8_typeParams = _source0.dtor_typeParams; - RAST._IType _9_tpe = _source0.dtor_tpe; - Dafny.ISequence _10_where = _source0.dtor_where; - Dafny.ISequence _11_body = _source0.dtor_body; - T _12_acc = (this).VisitType(acc, _9_tpe); - return (this).VisitBody(_12_acc, _11_body); + Dafny.ISequence _7_typeParams = _source0.dtor_typeParams; + RAST._IType _8_tpe = _source0.dtor_tpe; + Dafny.ISequence _9_body = _source0.dtor_body; + T _10_acc = (this).VisitType(acc, _8_tpe); + return (this).VisitBody(_10_acc, _9_body); } } public T VisitBody(T acc, Dafny.ISequence members) @@ -845,17 +843,15 @@ public RAST._IImpl ReplaceImplDecl(RAST._IImpl impl) { Dafny.ISequence _0_typeParams = _source0.dtor_typeParams; RAST._IType _1_tpe = _source0.dtor_tpe; RAST._IType _2_forType = _source0.dtor_forType; - Dafny.ISequence _3_where = _source0.dtor_where; - Dafny.ISequence _4_body = _source0.dtor_body; - return RAST.Impl.create_ImplFor((this).ReplaceTypeParams(_0_typeParams), (this).ReplaceType(_1_tpe), (this).ReplaceType(_2_forType), _3_where, (this).ReplaceBody(_4_body)); + Dafny.ISequence _3_body = _source0.dtor_body; + return RAST.Impl.create_ImplFor((this).ReplaceTypeParams(_0_typeParams), (this).ReplaceType(_1_tpe), (this).ReplaceType(_2_forType), (this).ReplaceBody(_3_body)); } } { - Dafny.ISequence _5_typeParams = _source0.dtor_typeParams; - RAST._IType _6_tpe = _source0.dtor_tpe; - Dafny.ISequence _7_where = _source0.dtor_where; - Dafny.ISequence _8_body = _source0.dtor_body; - return RAST.Impl.create_Impl((this).ReplaceTypeParams(_5_typeParams), (this).ReplaceType(_6_tpe), _7_where, (this).ReplaceBody(_8_body)); + Dafny.ISequence _4_typeParams = _source0.dtor_typeParams; + RAST._IType _5_tpe = _source0.dtor_tpe; + Dafny.ISequence _6_body = _source0.dtor_body; + return RAST.Impl.create_Impl((this).ReplaceTypeParams(_4_typeParams), (this).ReplaceType(_5_tpe), (this).ReplaceBody(_6_body)); } } public RAST._ITrait ReplaceTrait(RAST._ITrait tr) { @@ -4534,7 +4530,6 @@ public interface _IImpl { Dafny.ISequence dtor_typeParams { get; } RAST._IType dtor_tpe { get; } RAST._IType dtor_forType { get; } - Dafny.ISequence dtor_where { get; } Dafny.ISequence dtor_body { get; } _IImpl DowncastClone(); Dafny.ISequence _ToString(Dafny.ISequence ind); @@ -4542,7 +4537,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); public static RAST._IImpl Default() { return theDefault; } @@ -4550,11 +4545,11 @@ 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) { - return new Impl_ImplFor(typeParams, tpe, forType, @where, body); + public static _IImpl create_ImplFor(Dafny.ISequence typeParams, RAST._IType tpe, RAST._IType forType, Dafny.ISequence body) { + return new Impl_ImplFor(typeParams, tpe, forType, 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 static _IImpl create_Impl(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence body) { + return new Impl_Impl(typeParams, tpe, body); } public bool is_ImplFor { get { return this is Impl_ImplFor; } } public bool is_Impl { get { return this is Impl_Impl; } } @@ -4578,13 +4573,6 @@ public RAST._IType dtor_forType { return ((Impl_ImplFor)d)._forType; } } - public Dafny.ISequence dtor_where { - get { - var d = this; - if (d is Impl_ImplFor) { return ((Impl_ImplFor)d)._where; } - return ((Impl_Impl)d)._where; - } - } public Dafny.ISequence dtor_body { get { var d = this; @@ -4594,7 +4582,7 @@ 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.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>>>((_0_ind) => ((System.Func>)((_1_member) => { + 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.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("")))), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString((this).dtor_body, Dafny.Helpers.Id, Func>>>((_0_ind) => ((System.Func>)((_1_member) => { return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _0_ind), RAST.__default.IND), (_1_member)._ToString(Dafny.Sequence.Concat(_0_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("}")); } @@ -4603,22 +4591,20 @@ public class Impl_ImplFor : Impl { 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 body) : base() { this._typeParams = typeParams; this._tpe = tpe; this._forType = forType; - this._where = @where; this._body = body; } public override _IImpl DowncastClone() { if (this is _IImpl dt) { return dt; } - return new Impl_ImplFor(_typeParams, _tpe, _forType, _where, _body); + return new Impl_ImplFor(_typeParams, _tpe, _forType, _body); } public override bool Equals(object other) { var oth = other as RAST.Impl_ImplFor; - return oth != null && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._tpe, oth._tpe) && object.Equals(this._forType, oth._forType) && object.Equals(this._where, oth._where) && object.Equals(this._body, oth._body); + return oth != null && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._tpe, oth._tpe) && object.Equals(this._forType, oth._forType) && object.Equals(this._body, oth._body); } public override int GetHashCode() { ulong hash = 5381; @@ -4626,7 +4612,6 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParams)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._tpe)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._forType)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._where)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); return (int) hash; } @@ -4639,8 +4624,6 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._forType); s += ", "; - s += this._where.ToVerbatimString(true); - s += ", "; s += Dafny.Helpers.ToString(this._body); s += ")"; return s; @@ -4649,28 +4632,25 @@ public override string ToString() { public class Impl_Impl : Impl { 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 body) : base() { this._typeParams = typeParams; this._tpe = tpe; - this._where = @where; this._body = body; } public override _IImpl DowncastClone() { if (this is _IImpl dt) { return dt; } - return new Impl_Impl(_typeParams, _tpe, _where, _body); + return new Impl_Impl(_typeParams, _tpe, _body); } public override bool Equals(object other) { var oth = other as RAST.Impl_Impl; - return oth != null && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._tpe, oth._tpe) && object.Equals(this._where, oth._where) && object.Equals(this._body, oth._body); + return oth != null && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._tpe, oth._tpe) && object.Equals(this._body, oth._body); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 1; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParams)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._tpe)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._where)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); return (int) hash; } @@ -4681,8 +4661,6 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._tpe); s += ", "; - s += this._where.ToVerbatimString(true); - s += ", "; s += Dafny.Helpers.ToString(this._body); s += ")"; return s; diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index 5183d3c55c6..6d2e2f3c392 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -3979,12 +3979,12 @@ macro_rules! UpcastObjectFn { // This is for Box or traits #[macro_export] macro_rules! UpcastBoxFn { - (dyn $trait_name:ident<$($type_args:ty),*>) => { - fn upcast(&self) -> ::std::boxed::Box> { + (dyn $trait_name:path, $($type_args:ty),*) => { + fn upcast(&self) -> ::std::boxed::Box)> { $trait_name::<$($type_args), *>::_clone(self.as_ref()) } }; - (dyn $trait_name:ident) => { + (dyn $trait_name:path) => { fn upcast(&self) -> ::std::boxed::Box { $trait_name::_clone(self.as_ref()) } diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index 1a210d29b8d..f9296bf2806 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -938,18 +938,30 @@ mod tests { GeneralTraitSuper::_clone(self.as_ref()) } } + impl DafnyPrint for Box> { + fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { + write!(f, "GeneralTraitSuper") + } + } // Traits extending other traits also implement a direct way to upcast their Box of themselves trait GeneralTrait: GeneralTraitSuper + UpcastBox> { fn _clone(&self) -> Box; } impl UpcastBox> for Box { - UpcastBoxFn!(dyn GeneralTraitSuper); + fn upcast(&self) -> ::std::boxed::Box> { + crate::tests::tests::GeneralTraitSuper::::_clone(self.as_ref()) + } } impl Clone for Box { fn clone(&self) -> Self { GeneralTrait::_clone(self.as_ref()) } } + impl DafnyPrint for Box { + fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result { + write!(f, "GeneralTrait") + } + } #[derive(Clone, PartialEq, Debug)] struct ADatatype{i: i32} From 30919454a6e82944040478923a8fe81d8fe81a54 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Tue, 26 Nov 2024 06:11:20 -0600 Subject: [PATCH 07/69] Fix ownership issue --- .../Backends/Rust/Dafny-compiler-rust.dfy | 71 +++++++++++-------- Source/DafnyCore/DafnyGeneratedFromDafny.sh | 1 - .../DafnyCore/DafnyGeneratedFromDafnyPost.py | 4 ++ .../LitTests/LitTest/comp/rust/traits.dfy | 13 ++++ 4 files changed, 58 insertions(+), 31 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 5abf8f164a5..965590f8e93 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -2308,48 +2308,48 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - method ToPrimitive(r: R.Expr, typ: Type, primitiveType: Type) returns (out: R.Expr) + method ToPrimitive(r: R.Expr, typ: Type, primitiveType: Type, env: Environment) returns (out: R.Expr) modifies this { out := r; if typ != primitiveType { var dummy; - out, dummy := GenExprConvertTo(r, OwnershipOwned, typ, primitiveType, OwnershipOwned); + out, dummy := GenExprConvertTo(r, OwnershipOwned, typ, primitiveType, env, OwnershipOwned); } } - method ToBool(r: R.Expr, typ: Type) returns (out: R.Expr) + method ToBool(r: R.Expr, typ: Type, env: Environment) returns (out: R.Expr) modifies this { - out := ToPrimitive(r, typ, Primitive(Primitive.Bool)); + out := ToPrimitive(r, typ, Primitive(Primitive.Bool), env); } - method ToInt(r: R.Expr, typ: Type) returns (out: R.Expr) + method ToInt(r: R.Expr, typ: Type, env: Environment) returns (out: R.Expr) modifies this { - out := ToPrimitive(r, typ, Primitive(Primitive.Int)); + out := ToPrimitive(r, typ, Primitive(Primitive.Int), env); } - method FromPrimitive(r: R.Expr, primitiveType: Type, typ: Type) returns (out: R.Expr) + method FromPrimitive(r: R.Expr, primitiveType: Type, typ: Type, env: Environment) returns (out: R.Expr) modifies this { out := r; if typ != primitiveType { var dummy; - out, dummy := GenExprConvertTo(r, OwnershipOwned, primitiveType, typ, OwnershipOwned); + out, dummy := GenExprConvertTo(r, OwnershipOwned, primitiveType, typ, env, OwnershipOwned); } } - method FromBool(r: R.Expr, typ: Type) returns (out: R.Expr) + method FromBool(r: R.Expr, typ: Type, env: Environment) returns (out: R.Expr) modifies this { - out := FromPrimitive(r, Primitive(Primitive.Bool), typ); + out := FromPrimitive(r, Primitive(Primitive.Bool), typ, env); } - method FromInt(r: R.Expr, typ: Type) returns (out: R.Expr) + method FromInt(r: R.Expr, typ: Type, env: Environment) returns (out: R.Expr) modifies this { - out := FromPrimitive(r, Primitive(Primitive.Int), typ); + out := FromPrimitive(r, Primitive(Primitive.Int), typ, env); } method GenExprBinary( @@ -2433,8 +2433,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case _ => { if op in OpTable { if IsBooleanOperator(op) { - left := ToBool(left, lType); - right := ToBool(right, rType); + left := ToBool(left, lType, env); + right := ToBool(right, rType, env); } r := R.Expr.BinaryOp( OpTable[op], @@ -2442,12 +2442,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { right, format); if IsBooleanOperator(op) { - r := FromBool(r, resType); + r := FromBool(r, resType, env); } } else { if IsComplexArithmetic(op) { - left := ToInt(left, lType); - right := ToInt(right, rType); + left := ToInt(left, lType, env); + right := ToInt(right, rType, env); } match op { case Eq(referential) => { @@ -2466,7 +2466,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } else { r := R.BinaryOp("==", left, right, DAST.Format.BinaryOpFormat.NoFormat()); if resType != Primitive(Primitive.Bool) { - r, resultingOwnership := GenExprConvertTo(r, OwnershipOwned, Primitive(Primitive.Bool), resType, OwnershipOwned); + r, resultingOwnership := GenExprConvertTo(r, OwnershipOwned, Primitive(Primitive.Bool), resType, env, OwnershipOwned); } } } @@ -2490,7 +2490,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } if IsComplexArithmetic(op) { - r := FromInt(r, resType); + r := FromInt(r, resType, env); } } } @@ -2546,6 +2546,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { exprOwnership: Ownership, fromTpe: Type, toTpe: Type, + env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership) requires exprOwnership != OwnershipAutoBorrowed @@ -2559,24 +2560,24 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } if fromTpe.UserDefined? && fromTpe.resolved.kind.SynonymType? { - r, resultingOwnership := GenExprConvertTo(expr, exprOwnership, fromTpe.resolved.kind.baseType, toTpe, expectedOwnership); + r, resultingOwnership := GenExprConvertTo(expr, exprOwnership, fromTpe.resolved.kind.baseType, toTpe, env, expectedOwnership); return; } if toTpe.UserDefined? && toTpe.resolved.kind.SynonymType? { - r, resultingOwnership := GenExprConvertTo(expr, exprOwnership, fromTpe, toTpe.resolved.kind.baseType, expectedOwnership); + r, resultingOwnership := GenExprConvertTo(expr, exprOwnership, fromTpe, toTpe.resolved.kind.baseType, env, expectedOwnership); return; } if NeedsUnwrappingConversion(fromTpe) { // From type is a newtype but it's not a primitive one. r := UnwrapNewtype(r, exprOwnership, fromTpe); r, resultingOwnership := - GenExprConvertTo(r, exprOwnership, fromTpe.resolved.kind.baseType, toTpe, expectedOwnership); + GenExprConvertTo(r, exprOwnership, fromTpe.resolved.kind.baseType, toTpe, env, expectedOwnership); return; } if NeedsUnwrappingConversion(toTpe) { var toKind := toTpe.resolved.kind; r, resultingOwnership := - GenExprConvertTo(r, exprOwnership, fromTpe, toKind.baseType, expectedOwnership); + GenExprConvertTo(r, exprOwnership, fromTpe, toKind.baseType, env, expectedOwnership); r := WrapWithNewtype(r, resultingOwnership, toTpe); r, resultingOwnership := FromOwnership(r, resultingOwnership, expectedOwnership); return; @@ -2681,7 +2682,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r, resultingOwnership := FromOwned(r, expectedOwnership); } case _ => { - r, resultingOwnership := GenExprConvertOther(expr, exprOwnership, fromTpe, toTpe, expectedOwnership); + r, resultingOwnership := GenExprConvertOther(expr, exprOwnership, fromTpe, toTpe, env, expectedOwnership); } } } @@ -2817,11 +2818,24 @@ module {:extern "DCOMP"} DafnyToRustCompiler { false } + // Assumes expr to be borrowed. Will return and expression that is owned instead + function BorrowedToOwned(expr: R.Expr, env: Environment): (out: R.Expr) { + match expr + case UnaryOp("&", underlying, _) => + // We need to clone underlying unless it has borrow semantics. + if underlying.Identifier? && env.CanReadWithoutClone(underlying.name) then + underlying + else + underlying.Clone() // Auto-borrow allows for implicit code + case _ => expr.Clone() + } + method GenExprConvertOther( expr: R.Expr, exprOwnership: Ownership, fromTpe: Type, toTpe: Type, + env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership) modifies this @@ -2834,11 +2848,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if upcastConverter.Success? { var conversionLambda := upcastConverter.value; if exprOwnership == OwnershipBorrowed { - match r { - case UnaryOp("&", underlying, _) => - r := underlying; - case _ => r := r.Clone(); - } + // we need the value to be owned for conversion + r := BorrowedToOwned(r, env); } r := conversionLambda.Apply1(r); r, resultingOwnership := FromOwnership(r, OwnershipOwned, expectedOwnership); @@ -2875,7 +2886,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var recursiveGen, recOwned, recIdents := GenExpr(expr, selfIdent, env, argumentOwnership); r := recursiveGen; readIdents := recIdents; - r, resultingOwnership := GenExprConvertTo(r, recOwned, fromTpe, toTpe, expectedOwnership); + r, resultingOwnership := GenExprConvertTo(r, recOwned, fromTpe, toTpe, env, expectedOwnership); assert OwnershipGuarantee(expectedOwnership, resultingOwnership); return; } diff --git a/Source/DafnyCore/DafnyGeneratedFromDafny.sh b/Source/DafnyCore/DafnyGeneratedFromDafny.sh index ddc4ccab8fa..2ae61370ed8 100755 --- a/Source/DafnyCore/DafnyGeneratedFromDafny.sh +++ b/Source/DafnyCore/DafnyGeneratedFromDafny.sh @@ -33,5 +33,4 @@ if [ $? -ne 0 ]; then exit 1 fi -rm $output-cs.dtr python3 DafnyGeneratedFromDafnyPost.py $output \ No newline at end of file diff --git a/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py b/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py index 8ed810683f8..9486726fc45 100644 --- a/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py +++ b/Source/DafnyCore/DafnyGeneratedFromDafnyPost.py @@ -20,6 +20,10 @@ print(f"File {output}.cs was not generated. Fix issues and re-run ./DafnyGeneratedFromDafny.sh") exit() +if os.path.exists(output + '-cs.dtr'): + os.remove(output + '-cs.dtr') + print("File deleted: " + output + '-cs.dtr') + with open(output + '.cs', 'r' ) as f: content = f.read() content_trimmed = re.sub('\[assembly[\s\S]*?(?=namespace Formatting)|namespace\s+\w+\s*\{\s*\}\s*//.*', '', content, flags = re.M) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy index 952050e36b2..b9ba137de84 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy @@ -127,6 +127,19 @@ module All { r := Some(true); } + datatype ObjectContainer = ObjectContainer(y: Y) + + method ParameterBorrows(y: Y, o: ObjectContainer) { // y is borrowed + var z: SubTrait := y as SubTrait; + var p: SuperTrait := y; + var y2 := o.y; // y2 is owned + ConsumeBorrows(y2 as SubTrait); + ConsumeBorrows(y2 as SubTrait); + } + method ConsumeBorrows(y: SubTrait) { + + } + method Main() { var rts := Test(Some(2)); expect rts == Some(true); From 45b6741f9256459db52209d83f8ee2e7141bb868 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Thu, 28 Nov 2024 13:12:05 +0000 Subject: [PATCH 08/69] PR Preparation. Support for method overrides --- Source/DafnyCore/Backends/Dafny/AST.dfy | 4 +- Source/DafnyCore/Backends/Dafny/ASTBuilder.cs | 6 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 92 +- .../Rust/Dafny-compiler-rust-rast.dfy | 4 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 297 ++- .../SinglePassCodeGenerator.cs | 19 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 1742 ++++++++--------- .../DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 30 - .../DafnyRuntimeRust/src/tests/mod.rs | 8 +- .../LitTest/comp/rust/traits-datatypes.dfy | 17 +- 10 files changed, 1055 insertions(+), 1164 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 8b6914c356c..8fae0e88c7b 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -124,7 +124,7 @@ module {:extern "DAST"} DAST { case _ => false } } - + predicate IsGeneralTrait() { match this { case UserDefined(ResolvedType(_, _, typeKind, _, _, _)) => @@ -180,7 +180,7 @@ module {:extern "DAST"} DAST { datatype Attribute = Attribute(name: string, args: seq) datatype NewtypeType = NewtypeType(baseType: Type, range: NewtypeRange, erase: bool) - + datatype TraitType = | ObjectTrait() // Traits that extend objects with --type-system-refresh, all traits otherwise | GeneralTrait() // Traits that don't necessarily extend objects with --type-system-refresh diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index 23f15bd19b6..63455990df6 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -41,12 +41,12 @@ public ModuleBuilder Module(string name, Sequence attributes, bool re public static Module UnsupportedToModule(string why) { return new Module( - Sequence.UnicodeFromString(why.Replace(".", ",")), + Sequence.UnicodeFromString($"uncompilable/*{why.Replace(".", ",")}*/"), Sequence.FromElements( (Attribute)Attribute.create_Attribute( Sequence.UnicodeFromString("extern"), Sequence>.FromElements( - (Sequence)Sequence.UnicodeFromString(why)))), false, + (Sequence)Sequence.UnicodeFromString($"uncompilable/*{why}*/")))), false, Std.Wrappers.Option>.create_None()); } } @@ -1323,7 +1323,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($"uncompilable(\"Unsupported: {why}\")") ); } } diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 894db1e6513..3b01e93706a 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -22,7 +22,7 @@ class DafnyCodeGenerator : SinglePassCodeGenerator { public string internalFieldPrefix; public bool preventShadowing; - protected override bool ClassMethodsAllowedToCallTraitMethods => false; + protected override bool InstanceMethodsAllowedToCallTraitMethods => false; public void Start() { if (items != null) { @@ -54,19 +54,23 @@ protected override string GetCompileNameNotProtected(IVariable v) { return preventShadowing ? v.GetOrCreateCompileName(currentIdGenerator) : v.CompileNameShadowable; } - public void AddUnsupported(string why) { + public string TokenToString(IToken tok) { + return $"{tok.Uri}({tok.line},{tok.col})"; + } + + public void AddUnsupported(IToken tok, string why) { if (emitUncompilableCode && currentBuilder is Container container) { - container.AddUnsupported(why); + container.AddUnsupported($"{TokenToString(tok)}: {why}"); } else { throw new UnsupportedInvalidOperationException(why); } } - public void AddUnsupportedFeature(IToken token, Feature feature) { + public void AddUnsupportedFeature(IToken tok, Feature feature) { if (emitUncompilableCode && currentBuilder is Container container) { - container.AddUnsupported("" + feature.ToString() + ""); + container.AddUnsupported($"{TokenToString(tok)}DCOMP: {feature}"); } else { - throw new RecoverableUnsupportedFeatureException(token, feature); + throw new RecoverableUnsupportedFeatureException(tok, feature); } } @@ -110,11 +114,11 @@ protected override void EmitHeader(Program program, ConcreteSyntaxTree wr) { } public override void EmitCallToMain(Method mainMethod, string baseName, ConcreteSyntaxTree wr) { - AddUnsupported("Call to main"); + AddUnsupported(Token.NoToken, "Call to main"); } protected override ConcreteSyntaxTree CreateStaticMain(IClassWriter cw, string argsParameterName) { - AddUnsupported("create static main"); + AddUnsupported(Token.NoToken, "create static main"); return WrBuffer(out _); } @@ -200,7 +204,7 @@ private Variance GenTypeVariance(TypeParameter tp) { } if (tp.Variance is TypeParameter.TPVariance.Contra) { - AddUnsupported("Contravariance"); + AddUnsupported(tp.tok, "Contravariance"); } return (Variance)Variance.create_Nonvariant(); } @@ -422,7 +426,7 @@ private DAST.Type GenType(Type typ) { return (DAST.Type)DAST.Type.create_Map(GenType(keyType), GenType(valueType)); } else { var why = "Type name for " + xType + " (" + typ.GetType() + ")"; - AddUnsupported(why); + AddUnsupported(typ.tok, why); return (DAST.Type)DAST.Type.create_Passthrough(Sequence.UnicodeFromString($"Unsupported: {why}")); } } @@ -524,7 +528,7 @@ public ClassWriter(DafnyCodeGenerator compiler, bool hasTypeArgs, ClassLike buil public ConcreteSyntaxTree CreateMethod(Method m, List typeArgs, bool createBody, bool forBodyInheritance, bool lookasideBody) { if (m.IsStatic && this.hasTypeArgs) { - compiler.AddUnsupported("Static methods with type arguments"); + compiler.AddUnsupported(m.tok, "Static methods with type arguments"); return new BuilderSyntaxTree(new StatementBuffer(), this.compiler); } @@ -589,7 +593,7 @@ public ConcreteSyntaxTree CreateFunction(string name, List formals, Type resultType, IToken tok, bool isStatic, bool createBody, MemberDecl member, bool forBodyInheritance, bool lookasideBody) { if (isStatic && this.hasTypeArgs) { - compiler.AddUnsupported("Static functions with type arguments"); + compiler.AddUnsupported(tok, "Static functions with type arguments"); return new BuilderSyntaxTree(new StatementBuffer(), this.compiler); } @@ -621,7 +625,7 @@ public ConcreteSyntaxTree CreateFunction(string name, ListStatic fields with type arguments"); + compiler.AddUnsupported(tok, "Static fields with type arguments"); return new BuilderSyntaxTree(new StatementBuffer(), this.compiler); } @@ -650,7 +654,7 @@ public ConcreteSyntaxTree CreateGetter(string name, TopLevelDecl enclosingDecl, public ConcreteSyntaxTree CreateGetterSetter(string name, Type resultType, IToken tok, bool createBody, MemberDecl member, out ConcreteSyntaxTree setterWriter, bool forBodyInheritance) { - compiler.AddUnsupported("Create Getter Setter"); + compiler.AddUnsupported(tok, "Create Getter Setter"); if (createBody) { setterWriter = new BuilderSyntaxTree(new StatementBuffer(), this.compiler); return new BuilderSyntaxTree(new StatementBuffer(), this.compiler); @@ -883,7 +887,7 @@ protected override void EmitNameAndActualTypeArgs(string protectedName, List.UnicodeFromString(protectedName), receiverType, receiverArg, receiverAsArgument, signature)); } else { - AddUnsupported("Builder issue: wr is as " + wr.GetType() + + AddUnsupported(tok, "Builder issue: wr is as " + wr.GetType() + (GetExprBuilder(wr, out var st3) ? " and its builder is a " + st3.Builder.GetType() : "" )); @@ -899,7 +903,7 @@ protected override void TypeArgDescriptorUse(bool isStatic, bool lookasideBody, } protected override bool DeclareFormal(string prefix, string name, Type type, IToken tok, bool isInParam, ConcreteSyntaxTree wr) { - AddUnsupported("Declare formal"); + AddUnsupported(tok, "Declare formal"); return true; } @@ -1021,7 +1025,17 @@ protected override void EmitCallToInheritedMethod(Method method, [CanBeNull] Top 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); + throw new InvalidOperationException("Cannot call inherited method in this context: " + currentBuilder); + } + } + + protected override void EmitCallToInheritedFunction(Function f, [CanBeNull] TopLevelDeclWithMembers heir, + ConcreteSyntaxTree wr) { + if (wr is BuilderSyntaxTree exprContainer) { + var callBuilder = exprContainer.Builder.Call(GenFormals(f.Ins)); + base.EmitCallToInheritedFunction(f, heir, new BuilderSyntaxTree(callBuilder, this)); + } else { + throw new InvalidOperationException("Cannot call inherited function in this context: " + currentBuilder); } } @@ -1096,7 +1110,7 @@ public void EmitRead(ConcreteSyntaxTree wr) { if (GetExprBuilder(wr, out var exprContainer)) { exprContainer.Builder.AddExpr(expr); } else { - compiler.AddUnsupported("EmitRead without ExprContainer builder"); + compiler.AddUnsupported(Token.NoToken, "EmitRead without ExprContainer builder"); } } @@ -1345,11 +1359,11 @@ protected override ConcreteSyntaxTree CreateDoublingForLoop(string indexVar, int } protected override void EmitIncrementVar(string varName, ConcreteSyntaxTree wr) { - AddUnsupported("EmitIncrementVar"); + AddUnsupported(Token.NoToken, "EmitIncrementVar"); } protected override void EmitDecrementVar(string varName, ConcreteSyntaxTree wr) { - AddUnsupported("EmitDecrementVar"); + AddUnsupported(Token.NoToken, "EmitDecrementVar"); } protected override ConcreteSyntaxTree EmitQuantifierExpr(Action collection, bool isForall, Type collectionElementType, BoundVar bv, ConcreteSyntaxTree wr) { @@ -1394,7 +1408,7 @@ protected override void EmitDowncastVariableAssignment(string boundVarName, Type protected override ConcreteSyntaxTree CreateForeachIngredientLoop(string boundVarName, int L, string tupleTypeArgs, out ConcreteSyntaxTree collectionWriter, ConcreteSyntaxTree wr) { - AddUnsupported("CreateForeachIngredientLoop"); + AddUnsupported(Token.NoToken, "CreateForeachIngredientLoop"); collectionWriter = new BuilderSyntaxTree(new ExprBuffer(null), this); return new BuilderSyntaxTree(new StatementBuffer(), this); } @@ -1415,7 +1429,7 @@ protected override void EmitNew(Type type, IToken tok, CallStmt initCall, Concre } if (ctor == null) { - AddUnsupported("Creation of object of type " + type.ToString() + " requires a constructor"); + AddUnsupported(tok, "Creation of object of type " + type.ToString() + " requires a constructor"); } var typeArgs = type.TypeArgs.Select(GenType).ToArray(); @@ -1454,7 +1468,7 @@ protected override void EmitIdentifier(string ident, ConcreteSyntaxTree wr) { Sequence.UnicodeFromString(ident) )); } else { - AddUnsupported("Expected ExprContainer, got " + wr.GetType()); + AddUnsupported(Token.NoToken, "Expected ExprContainer, got " + wr.GetType()); } } @@ -1582,7 +1596,7 @@ protected override void EmitLiteralExpr(ConcreteSyntaxTree wr, LiteralExpr e) { } protected override void EmitStringLiteral(string str, bool isVerbatim, ConcreteSyntaxTree wr) { - AddUnsupported("EmitStringLiteral"); + AddUnsupported(Token.NoToken, "EmitStringLiteral"); } protected override ConcreteSyntaxTree EmitBitvectorTruncation(BitvectorType bvType, [CanBeNull] NativeType nativeType, @@ -1591,7 +1605,7 @@ protected override ConcreteSyntaxTree EmitBitvectorTruncation(BitvectorType bvTy return wr; } - AddUnsupported($"EmitBitvectorTruncation from {bvType} to {nativeType}"); + AddUnsupported(bvType.Tok, $"EmitBitvectorTruncation from {bvType} to {nativeType}"); return wr; } @@ -1627,7 +1641,7 @@ public override string PublicIdProtect(string name) { } protected override string FullTypeName(UserDefinedType udt, MemberDecl member = null) { - AddUnsupported("FullTypeName"); + AddUnsupported(udt.tok, "FullTypeName"); return "FullTypeName"; } @@ -1943,7 +1957,7 @@ protected override void GetSpecialFieldInfo(SpecialField.ID id, object idParam, case SpecialField.ID.Items: break; default: - AddUnsupported("Special field: " + id + ""); + AddUnsupported(receiverType.tok, "Special field: " + id + ""); break; } } @@ -2218,7 +2232,7 @@ protected override void EmitIndexCollectionUpdate(Expression source, Expression convert(source), convert(index), convert(value) )); } else { - AddUnsupported("EmitIndexCollectionUpdate for " + resultCollectionType.ToString() + ""); + AddUnsupported(source.tok, "EmitIndexCollectionUpdate for " + resultCollectionType.ToString() + ""); } } else { throw new InvalidOperationException(); @@ -2464,11 +2478,11 @@ protected override void EmitBoolBoundedPool(bool inLetExprBody, ConcreteSyntaxTr } protected override void EmitCharBoundedPool(bool inLetExprBody, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { - AddUnsupported("EmitCharBoundedPool"); + AddUnsupported(Token.NoToken, "EmitCharBoundedPool"); } protected override void EmitWiggleWaggleBoundedPool(bool inLetExprBody, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { - AddUnsupported("EmitWiggleWaggleBoundedPool"); + AddUnsupported(Token.NoToken, "EmitWiggleWaggleBoundedPool"); } protected override void EmitSetBoundedPool(Expression of, string propertySuffix, bool inLetExprBody, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { @@ -2492,7 +2506,7 @@ protected override void EmitMultiSetBoundedPool(Expression of, bool includeDupli } protected override void EmitSubSetBoundedPool(Expression of, string propertySuffix, bool inLetExprBody, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { - AddUnsupported("EmitSubSetBoundedPool"); + AddUnsupported(of.tok, "EmitSubSetBoundedPool"); } protected override void EmitMapBoundedPool(Expression map, string propertySuffix, bool inLetExprBody, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { @@ -2591,7 +2605,7 @@ protected override void EmitUnaryExpr(ResolvedUnaryOp op, Expression expr, bool } } } else { - AddUnsupported("UnaryExpr " + op + " without expr container"); + AddUnsupported(expr.tok, "UnaryExpr " + op + " without expr container"); } } @@ -2889,7 +2903,7 @@ protected override void EmitITE(Expression guard, Expression thn, Expression els } protected override void EmitIsZero(string varName, ConcreteSyntaxTree wr) { - AddUnsupported("EmitIsZero"); + AddUnsupported(Token.NoToken, "EmitIsZero"); } protected override void EmitConversionExpr(Expression fromExpr, Type fromType, Type toType, bool inLetExprBody, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { @@ -3028,7 +3042,7 @@ protected override void EmitMapBuilder_New(ConcreteSyntaxTree wr, MapComprehensi ) )); } else { - AddUnsupported("EmitMapBuilder_New (non-statement)"); + AddUnsupported(e.tok, "EmitMapBuilder_New (non-statement)"); } //throw new InvalidOperationException(); } @@ -3044,7 +3058,7 @@ protected override void EmitSetBuilder_Add(CollectionType ct, string collName, E stmtBuilder.AddExpr(ConvertExpression(elmt, builder)); builder.Builder.AddBuildable(stmtBuilder); } else { - AddUnsupported("EmitSetBuilder_Add"); + AddUnsupported(elmt.tok, "EmitSetBuilder_Add"); } //throw new InvalidOperationException(); } @@ -3079,7 +3093,7 @@ protected override ConcreteSyntaxTree EmitMapBuilder_Add(MapType mt, IToken tok, builder.Builder.AddBuildable(stmtBuilder); return keyBuilder; } else { - AddUnsupported("EMitMapBuilder_Add"); + AddUnsupported(tok, "EMitMapBuilder_Add"); return WrBuffer(out _); } } @@ -3093,7 +3107,7 @@ protected override Action GetSubtypeCondition(string tmpVarN baseExpr = DAST.Expression.create_Literal(DAST.Literal.create_BoolLiteral(true)); } else { // typeTest = $"{tmpVarName} instanceof {TypeName(boundVarType, wPreconditions, tok)}"; - AddUnsupported("TypeName"); + AddUnsupported(tok, "TypeName"); return (ConcreteSyntaxTree w) => { }; } @@ -3162,7 +3176,7 @@ protected override void GetCollectionBuilder_Build(CollectionType ct, IToken tok callExpr.AddExpr((DAST.Expression)DAST.Expression.create_Ident(Sequence.UnicodeFromString(collName))); builder.Builder.AddBuildable(callExpr); } else { - AddUnsupported("GetCollectionBuilder_Build"); + AddUnsupported(tok, "GetCollectionBuilder_Build"); } } @@ -3193,7 +3207,7 @@ protected override (Type, Action) EmitIntegerRange(Type type } protected override void EmitNull(Type _, ConcreteSyntaxTree wr) { - AddUnsupported("EmitNull"); + AddUnsupported(Token.NoToken, "EmitNull"); } protected override void EmitSingleValueGenerator(Expression e, bool inLetExprBody, string type, diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index 1d84729d2a7..44efc8f12ad 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -592,7 +592,7 @@ module RAST } const PtrPath: Path := dafny_runtime.MSel("Ptr") - + const BoxPath := std.MSel("boxed").MSel("Box") const Ptr := PtrPath.AsExpr() @@ -953,7 +953,7 @@ module RAST false else false - } + } predicate IsBox() { match this { case TypeApp(TypeFromPath(o), elems1) => diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 965590f8e93..010b7bd7756 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -21,7 +21,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { const rootType: RootType const thisFile: R.Path := if rootType.RootCrate? then R.crate else R.crate.MSel(rootType.moduleName) - const DafnyChar := if charType.UTF32? then "DafnyChar" else "DafnyCharUTF16" const conversions := if charType.UTF32? then "unicode_chars_true" else "unicode_chars_false" const DafnyCharUnderlying := if charType.UTF32? then R.RawType("char") else R.RawType("u16") @@ -250,18 +249,20 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } method GenTraitImplementations( - path: seq, - rTypeParams: seq, - rTypeParamsDecls: seq, - superTraitTypes: seq, - traitBodies: map, seq>, - extern: ExternAttribute, - kind: string) + path: seq, + rTypeParams: seq, + rTypeParamsDecls: seq, + superTraitTypes: seq, + traitBodies: map, seq>, + extern: ExternAttribute, + kind: string) returns (s: seq) - modifies this + modifies this { s := []; - var genSelfPath := GenPathType(path); + var genPath := GenPath(path); + var genSelfPath := genPath.AsType(); + var genPathExpr := genPath.AsExpr(); for i := 0 to |superTraitTypes| { var superTraitType := superTraitTypes[i]; match superTraitType { @@ -301,17 +302,17 @@ module {:extern "DCOMP"} DafnyToRustCompiler { body := body + [ R.FnDecl( R.PRIV, - R.Fn( - "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(fullTraitPath))), - "", - Some(R.BoxNew(R.self.Sel("clone").Apply0())))) + R.Fn( + "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(fullTraitPath))), + "", + Some(R.BoxNew(R.self.Sel("clone").Apply0())))) ]; } else { if kind == "datatype" || kind == "newtype" { var dummy := Error("Cannot extend non-general traits"); } } - + var x := R.ImplDecl( R.ImplFor( rTypeParamsDecls, @@ -324,25 +325,41 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var upcastTraitToImplement, upcastTraitFn; if traitType.GeneralTrait? { upcastTraitToImplement, upcastTraitFn := "UpcastBox", "UpcastStructBoxFn!"; + s := s + [ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.dafny_runtime.MSel("UpcastBox").AsType().Apply1(R.DynType(fullTraitPath)), + R.TypeApp(genSelfPath, rTypeParams), + [ R.FnDecl( + R.PRIV, + R.Fn( + "upcast", + [], [R.Formal.selfBorrowed], + Some(R.Box(R.DynType(fullTraitPath))), + "", + Some(genPathExpr.ApplyType(rTypeParams).FSel("_clone").Apply1(R.self))) // Difference with UpcastStructBox is that there is no .as_ref() + ) ])) + ]; } else { - upcastTraitToImplement, upcastTraitFn := Upcast, UpcastFnMacro; - } - s := s + [ - R.ImplDecl( - R.ImplFor( - rTypeParamsDecls, - R.dafny_runtime.MSel(upcastTraitToImplement).AsType().Apply([ - R.DynType(fullTraitPath)]), - R.TypeApp(genSelfPath, rTypeParams), - [ - R.ImplMemberMacro( - R.dafny_runtime - .MSel(upcastTraitFn).AsExpr() - .Apply1(R.ExprFromType(R.DynType(fullTraitPath)))) - ] + s := s + [ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.dafny_runtime.MSel(Upcast).AsType().Apply([ + R.DynType(fullTraitPath)]), + R.TypeApp(genSelfPath, rTypeParams), + [ + R.ImplMemberMacro( + R.dafny_runtime + .MSel(UpcastFnMacro).AsExpr() + .Apply1(R.ExprFromType(R.DynType(fullTraitPath)))) + ] + ) ) - ) - ]; + ]; + } + } case _ => {} } @@ -536,18 +553,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { parents := parents + [R.dafny_runtime.MSel(upcastTrait).AsType().Apply1(R.DynType(parentTpe))]; if parentTyp.IsGeneralTrait() { /*impl UpcastBox for Box { - UpcastBoxFn!(GeneralTraitSuper); - }*/ + fn upcast(&self) -> ::std::boxed::Box { + GeneralTrait::::_clone(self.as_ref()) + } + }*/ upcastImplemented := upcastImplemented + [ R.ImplDecl( R.ImplFor( rTypeParamsDecls, R.dafny_runtime.MSel("UpcastBox").AsType().Apply1(R.DynType(parentTpe)), R.Box(R.DynType(traitFulltype)), - [ R.ImplMemberMacro( - R.dafny_runtime - .MSel("UpcastBoxFn!").AsExpr() - .Apply1(R.ExprFromType(parentTpe)))])) + [ R.FnDecl( + R.PRIV, + R.Fn( + "upcast", + [], [R.Formal.selfBorrowed], + Some(R.Box(R.DynType(parentTpe))), + "", + Some(traitFullExpr.FSel("_clone").Apply1(R.self.FSel("as_ref").Apply0())) + ) + )])) ]; } } @@ -1268,10 +1293,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplFor( rTypeParamsDecls, R.std.MSel("convert").MSel("AsRef").AsType().Apply1(fullType), - R.Borrowed(fullType), + fullType, [R.FnDecl( R.PRIV, - R.Fn("as_ref", [], [R.Formal.selfBorrowed], Some(R.SelfOwned), + R.Fn("as_ref", [], [R.Formal.selfBorrowed], Some(R.SelfBorrowed), "", Some(R.self)) )] @@ -1846,6 +1871,76 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } + method GenOwnedCallPart(ghost e: Expression, on: Expression, selfIdent: SelfInfo, name: CallName, typeArgs: seq, args: seq, env: Environment) returns (r: R.Expr, readIdents: set) + modifies this + decreases e, 1, 1 + { + var argExprs, recIdents, typeExprs, fullNameQualifier := GenArgs(e, selfIdent, name, typeArgs, args, env); + readIdents := recIdents; + + match fullNameQualifier { + // Trait calls are fully specified as we can't guarantee traits will be in context + case Some(ResolvedType(path, onTypeArgs, base, _, _, _)) => + var fullPath := GenPathExpr(path); + var onTypeExprs := GenTypeArgs(onTypeArgs, GenTypeContext.default()); + var onExpr, recOwnership, recIdents; + if (base.Trait? && base.traitType.ObjectTrait?) || base.Class? { + // First we own a pointer, then we read it + onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); + onExpr := read_macro.Apply1(onExpr); + readIdents := readIdents + recIdents; + } else if base.Trait? && base.traitType.GeneralTrait? { + // General traits borrow their self, from a Box + // The underlying type is a Box, self: Datatype or Rc + // 'on' is going to return an owned version of this box. + onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); + if onExpr.Identifier? && env.NeedsAsRefForBorrow(onExpr.name) { + onExpr := onExpr.Sel("as_ref").Apply0(); + } else if onExpr.IsBorrow() { + // If the resulting expression is a borrow, e.g. &something(), it means the trait was owned. + // In our case we want dynamic dispatch, so we need to get the bare reference. + // Because "on" is a general trait, we need to call as_ref() instead to get the bare expression + // If the onExpr is an identifier but not "self", we apply the same treatment + onExpr := R.std.MSel("convert").MSel("AsRef").AsExpr().FSel("as_ref").Apply1(onExpr); + } + readIdents := readIdents + recIdents; + } else if base.Newtype? && IsNewtypeCopy(base.range) { + // The self type of a newtype that is copy is also copy + onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); + readIdents := readIdents + recIdents; + } else { + // The self type of any other type is borrowed + onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); + readIdents := readIdents + recIdents; + } + r := fullPath.ApplyType(onTypeExprs).FSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); + case _ => // Infix call on.name(args) + var onExpr, _, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); + readIdents := readIdents + recIdents; + var renderedName := GetMethodName(on, name); + // Pointers in the role of "self" must be converted to borrowed versions. + match on { + case Companion(_, _) | ExternCompanion(_) => { + onExpr := onExpr.FSel(renderedName); + } + case _ => { + if onExpr != R.self { // Self has the reference type already + match name { + case CallName(_, Some(tpe), _, _, _) => + var typ := GenType(tpe, GenTypeContext.default()); + if typ.IsObjectOrPointer() && onExpr != R.Identifier("self") { + onExpr := read_macro.Apply1(onExpr); + } + case _ => + } + } + onExpr := onExpr.Sel(renderedName); + } + } + r := onExpr.ApplyType(typeExprs).Apply(argExprs); + } + } + method GenStmt(stmt: Statement, selfIdent: SelfInfo, env: Environment, isLast: bool, earlyReturn: Option>) returns (generated: R.Expr, readIdents: set, newEnv: Environment) decreases stmt, 1, 1 modifies this @@ -2031,48 +2126,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } case Call(on, name, typeArgs, args, maybeOutVars) => { assume {:axiom} (if |args| > 0 then args[0] else Expression.Tuple([])) < stmt; - var argExprs, recIdents, typeExprs, fullNameQualifier := GenArgs(None, selfIdent, name, typeArgs, args, env); - readIdents := recIdents; - - match fullNameQualifier { - // Trait calls are fully specified as we can't guarantee traits will be in context - case Some(ResolvedType(path, onTypeArgs, base, _, _, _)) => - var fullPath := GenPathExpr(path); - var onTypeExprs := GenTypeArgs(onTypeArgs, GenTypeContext.default()); - var onExpr, recOwnership, recIdents; - if base.Trait? || base.Class? { - onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); - onExpr := modify_macro.Apply1(onExpr); - readIdents := readIdents + recIdents; - } else { - onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); - readIdents := readIdents + recIdents; - } - generated := fullPath.ApplyType(onTypeExprs).FSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); - case _ => // Infix call on.name(args) - var onExpr, _, enclosingIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); - readIdents := readIdents + enclosingIdents; - var renderedName := GetMethodName(on, name); - match on { - case Companion(_, _) | ExternCompanion(_) => { - onExpr := onExpr.FSel(renderedName); - } - case _ => { - if onExpr != R.self { // Self has the reference type already - match name { - case CallName(_, Some(tpe), _, _, _) => - var typ := GenType(tpe, GenTypeContext.default()); - if typ.IsObjectOrPointer() && onExpr != R.Identifier("self") { - onExpr := read_macro.Apply1(onExpr); - } - case _ => - } - } - onExpr := onExpr.Sel(renderedName); - } - } - generated := onExpr.ApplyType(typeExprs).Apply(argExprs); - } + generated, readIdents := GenOwnedCallPart(Expression.Call(on, name, typeArgs, args), on, selfIdent, name, typeArgs, args, env); if maybeOutVars.Some? && |maybeOutVars.value| == 1 { var outVar := escapeVar(maybeOutVars.value[0]); @@ -2731,7 +2785,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if fromTpe.IsBox() then var fromTpeUnderlying := fromTpe.BoxUnderlying(); if !fromTpeUnderlying.DynType? then Failure((fromType, fromTpe, toType, toTpe, typeParams)) else - Success(R.dafny_runtime.MSel("upcast_box_box").AsExpr().ApplyType([fromTpeUnderlying, toTpeUnderlying]).Apply0()) + Success(R.dafny_runtime.MSel("upcast_box_box").AsExpr().ApplyType([fromTpeUnderlying, toTpeUnderlying]).Apply0()) else Success(R.dafny_runtime.MSel("upcast_box").AsExpr().ApplyType([fromTpe, toTpeUnderlying]).Apply0()) else if fromTpe.IsObjectOrPointer() && toTpe.IsObjectOrPointer() then @@ -2973,7 +3027,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } method GenArgs( - ghost e: Option, + ghost e: Expression, selfIdent: SelfInfo, name: CallName, typeArgs: seq, @@ -2981,8 +3035,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { env: Environment ) returns (argExprs: seq, readIdents: set, typeExprs: seq, fullNameQualifier: Option) modifies this - requires e.Some? ==> forall a <- args :: a < e.value - decreases if e.Some? then e.value else if |args| > 0 then args[0] else Expression.Tuple([]), 1, 1 + requires forall a <- args :: a < e + decreases e, 1, 1, 1 ensures fullNameQualifier.Some? ==> name.CallName? { argExprs := []; @@ -3003,7 +3057,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { argOwnership := OwnershipOwned; } } - assume {:axiom} args[i] < if e.Some? then e.value else if |args| > 0 then args[0] else Expression.Tuple([]); var argExpr, _, argIdents := GenExpr(args[i], selfIdent, env, argOwnership); argExprs := argExprs + [argExpr]; readIdents := readIdents + argIdents; @@ -3707,73 +3760,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case Call(on, name, typeArgs, args) => { - var argExprs, recIdents, typeExprs, fullNameQualifier := GenArgs(Some(e), selfIdent, name, typeArgs, args, env); - readIdents := recIdents; - - match fullNameQualifier { - // Trait calls are fully specified as we can't guarantee traits will be in context - case Some(ResolvedType(path, onTypeArgs, base, _, _, _)) => - var fullPath := GenPathExpr(path); - var onTypeExprs := GenTypeArgs(onTypeArgs, GenTypeContext.default()); - var onExpr, recOwnership, recIdents; - if (base.Trait? && base.traitType.ObjectTrait?) || base.Class? { - // First we own a pointer, then we read it - onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); - onExpr := read_macro.Apply1(onExpr); - readIdents := readIdents + recIdents; - } else if base.Trait? && base.traitType.GeneralTrait? { - // General traits borrow their self, from a Box - // The underlying type is a Box, self: Datatype or Rc - // 'on' is going to return an owned version of this box. - onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); - if onExpr.Identifier? && env.NeedsAsRefForBorrow(onExpr.name) { - onExpr := onExpr.Sel("as_ref").Apply0(); - } else if onExpr.IsBorrow() { - // If the resulting expression is a borrow, e.g. &something(), it means the trait was owned. - // In our case we want dynamic dispatch, so we need to get the bare reference. - // Because "on" is a general trait, we need to call as_ref() instead to get the bare expression - // If the onExpr is an identifier but not "self", we apply the same treatment - onExpr := onExpr.underlying.Sel("as_ref").Apply0(); - } - readIdents := readIdents + recIdents; - } else if base.Newtype? && IsNewtypeCopy(base.range) { - // The self type of a newtype that is copy is also copy - onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); - readIdents := readIdents + recIdents; - } else { - // The self type of any other type is borrowed - onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); - readIdents := readIdents + recIdents; - } - r := fullPath.ApplyType(onTypeExprs).FSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); - r, resultingOwnership := FromOwned(r, expectedOwnership); - case _ => // Infix call on.name(args) - var onExpr, _, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); - readIdents := readIdents + recIdents; - var renderedName := GetMethodName(on, name); - // Pointers in the role of "self" must be converted to borrowed versions. - match on { - case Companion(_, _) | ExternCompanion(_) => { - onExpr := onExpr.FSel(renderedName); - } - case _ => { - if onExpr != R.self { // Self has the reference type already - match name { - case CallName(_, Some(tpe), _, _, _) => - var typ := GenType(tpe, GenTypeContext.default()); - if typ.IsObjectOrPointer() { - onExpr := read_macro.Apply1(onExpr); - } - case _ => - } - } - onExpr := onExpr.Sel(renderedName); - } - } - r := onExpr.ApplyType(typeExprs).Apply(argExprs); - r, resultingOwnership := FromOwned(r, expectedOwnership); - return; - } + r, readIdents := GenOwnedCallPart(e, on, selfIdent, name, typeArgs, args, env); + r, resultingOwnership := FromOwned(r, expectedOwnership); + return; } case Lambda(paramsDafny, retType, body) => { var params := GenParams(paramsDafny, true); diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index 387bb43cd5e..cb586355535 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -217,7 +217,7 @@ protected interface IClassWriter { protected virtual bool IncludeExternMembers { get => false; } protected virtual bool SupportsStaticsInGenericClasses => true; protected virtual bool TraitRepeatsInheritedDeclarations => false; - protected virtual bool ClassMethodsAllowedToCallTraitMethods => true; + protected virtual bool InstanceMethodsAllowedToCallTraitMethods => true; protected IClassWriter CreateClass(string moduleName, string name, TopLevelDecl cls, ConcreteSyntaxTree wr) { return CreateClass(moduleName, name, false, null, cls.TypeArgs, cls, (cls as TopLevelDeclWithMembers)?.ParentTypeInformation.UniqueParentTraits(), null, wr); @@ -2147,6 +2147,8 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite if (c is not TraitDecl || TraitRepeatsInheritedDeclarations) { thisContext = c; + var canRedeclareMemberDefinedInTrait = c is not ClassLikeDecl and not DatatypeDecl and not NewtypeDecl || + InstanceMethodsAllowedToCallTraitMethods; foreach (var member in inheritedMembers.Select(memberx => (memberx as Function)?.ByMethodDecl ?? memberx)) { enclosingDeclaration = member; Contract.Assert(!member.IsStatic); // only instance members should ever be added to .InheritedMembers @@ -2196,13 +2198,15 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite EmitSetterParameter(sw); } } else if (member is Function fn) { - if (!Attributes.Contains(fn.Attributes, "extern") && (c is not ClassLikeDecl || ClassMethodsAllowedToCallTraitMethods)) { + if (!Attributes.Contains(fn.Attributes, "extern") && canRedeclareMemberDefinedInTrait) { Contract.Assert(fn.Body != null); var w = classWriter.CreateFunction(IdName(fn), CombineAllTypeArguments(fn), fn.Ins, fn.ResultType, fn.tok, fn.IsStatic, true, fn, true, false); + w = EmitReturnExpr(w); EmitCallToInheritedFunction(fn, null, w); } } else if (member is Method method) { - if (!Attributes.Contains(method.Attributes, "extern") && (c is not ClassLikeDecl || ClassMethodsAllowedToCallTraitMethods)) { + if (!Attributes.Contains(method.Attributes, "extern") + && canRedeclareMemberDefinedInTrait) { Contract.Assert(method.Body != null); var w = classWriter.CreateMethod(method, CombineAllTypeArguments(member), true, true, false); var wBefore = w.Fork(); @@ -2328,6 +2332,7 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite CompileFunction(f, classWriter, false); var w = classWriter.CreateFunction(IdName(f), CombineAllTypeArguments(f), f.Ins, f.ResultType, f.tok, false, true, f, true, false); + w = EmitReturnExpr(w); EmitCallToInheritedFunction(f, c, w); } else { CompileFunction(f, classWriter, false); @@ -2446,7 +2451,7 @@ protected void EmitCallToInheritedConstRHS(ConstantField f, ConcreteSyntaxTree w /// "heir" is the type declaration that inherits the function. Or, it can be "null" to indicate that the function is declared in /// the type itself, in which case the "call to inherited" is actually a call from the dynamically dispatched function to its implementation. /// - protected void EmitCallToInheritedFunction(Function f, [CanBeNull] TopLevelDeclWithMembers heir, ConcreteSyntaxTree wr) { + protected virtual void EmitCallToInheritedFunction(Function f, [CanBeNull] TopLevelDeclWithMembers heir, ConcreteSyntaxTree wr) { Contract.Requires(f != null); Contract.Requires(!f.IsStatic); Contract.Requires(f.EnclosingClass is TraitDecl); @@ -2465,14 +2470,14 @@ protected void EmitCallToInheritedFunction(Function f, [CanBeNull] TopLevelDeclW // In a target language that requires type coercions, the function declared in "thisContext" has // the same signature as in "f.Original.EnclosingClass". - wr = EmitReturnExpr(wr); wr = EmitCoercionIfNecessary(f.ResultType, f.Original.ResultType, f.tok, wr); var companionName = CompanionMemberIdName(f); var calleeReceiverType = UserDefinedType.FromTopLevelDecl(f.tok, f.EnclosingClass).Subst(thisContext.ParentFormalTypeParametersToActuals); wr.Write("{0}{1}", TypeName_Companion(calleeReceiverType, wr, f.tok, f), StaticClassAccessor); var typeArgs = CombineAllTypeArguments(f, thisContext); - EmitNameAndActualTypeArgs(companionName, TypeArgumentInstantiation.ToActuals(ForTypeParameters(typeArgs, f, true)), + EmitNameAndActualTypeArgs( + companionName, TypeArgumentInstantiation.ToActuals(ForTypeParameters(typeArgs, f, true)), f.tok, new ThisExpr(thisContext), true, wr); wr.Write("("); var sep = ""; @@ -2488,7 +2493,7 @@ protected void EmitCallToInheritedFunction(Function f, [CanBeNull] TopLevelDeclW if (!p.IsGhost) { wr.Write(sep); w = EmitCoercionIfNecessary(f.Original.Ins[j].Type, f.Ins[j].Type, f.tok, wr); - w.Write(IdName(p)); + EmitIdentifier(IdName(p), w); sep = ", "; l++; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 6d97cb762dc..77dd9e65d51 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -282,79 +282,80 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.FromElements(); - RAST._IType _0_genSelfPath; - RAST._IType _out0; - _out0 = (this).GenPathType(path); - _0_genSelfPath = _out0; + RAST._IPath _0_genPath; + RAST._IPath _out0; + _out0 = (this).GenPath(path, true); + _0_genPath = _out0; + RAST._IType _1_genSelfPath; + _1_genSelfPath = (_0_genPath).AsType(); + RAST._IExpr _2_genPathExpr; + _2_genPathExpr = (_0_genPath).AsExpr(); BigInteger _hi0 = new BigInteger((superTraitTypes).Count); - for (BigInteger _1_i = BigInteger.Zero; _1_i < _hi0; _1_i++) { - DAST._IType _2_superTraitType; - _2_superTraitType = (superTraitTypes).Select(_1_i); - DAST._IType _source0 = _2_superTraitType; + for (BigInteger _3_i = BigInteger.Zero; _3_i < _hi0; _3_i++) { + DAST._IType _4_superTraitType; + _4_superTraitType = (superTraitTypes).Select(_3_i); + DAST._IType _source0 = _4_superTraitType; { if (_source0.is_UserDefined) { DAST._IResolvedType resolved0 = _source0.dtor_resolved; - Dafny.ISequence> _3_traitPath = resolved0.dtor_path; - Dafny.ISequence _4_typeArgs = resolved0.dtor_typeArgs; + Dafny.ISequence> _5_traitPath = resolved0.dtor_path; + Dafny.ISequence _6_typeArgs = resolved0.dtor_typeArgs; DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; if (kind0.is_Trait) { - DAST._ITraitType _5_traitType = kind0.dtor_traitType; - Dafny.ISequence> _6_properMethods = resolved0.dtor_properMethods; + DAST._ITraitType _7_traitType = kind0.dtor_traitType; + Dafny.ISequence> _8_properMethods = resolved0.dtor_properMethods; { - RAST._IType _7_pathStr; + RAST._IType _9_pathStr; RAST._IType _out1; - _out1 = (this).GenPathType(_3_traitPath); - _7_pathStr = _out1; - Dafny.ISequence _8_typeArgs; + _out1 = (this).GenPathType(_5_traitPath); + _9_pathStr = _out1; + Dafny.ISequence _10_typeArgs; Dafny.ISequence _out2; - _out2 = (this).GenTypeArgs(_4_typeArgs, Defs.GenTypeContext.@default()); - _8_typeArgs = _out2; - Dafny.ISequence _9_body; - _9_body = Dafny.Sequence.FromElements(); - if ((traitBodies).Contains(_3_traitPath)) { - _9_body = Dafny.Map>, Dafny.ISequence>.Select(traitBodies,_3_traitPath); + _out2 = (this).GenTypeArgs(_6_typeArgs, Defs.GenTypeContext.@default()); + _10_typeArgs = _out2; + Dafny.ISequence _11_body; + _11_body = Dafny.Sequence.FromElements(); + if ((traitBodies).Contains(_5_traitPath)) { + _11_body = Dafny.Map>, Dafny.ISequence>.Select(traitBodies,_5_traitPath); } - RAST._IType _10_fullTraitPath; - _10_fullTraitPath = RAST.Type.create_TypeApp(_7_pathStr, _8_typeArgs); + RAST._IType _12_fullTraitPath; + _12_fullTraitPath = RAST.Type.create_TypeApp(_9_pathStr, _10_typeArgs); if (!((@extern).is_NoExtern)) { - if (((new BigInteger((_9_body).Count)).Sign == 0) && ((new BigInteger((_6_properMethods).Count)).Sign != 0)) { + if (((new BigInteger((_11_body).Count)).Sign == 0) && ((new BigInteger((_8_properMethods).Count)).Sign != 0)) { goto continue_0; } - if ((new BigInteger((_9_body).Count)) != (new BigInteger((_6_properMethods).Count))) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the "), kind), Dafny.Sequence.UnicodeFromString(" ")), RAST.__default.SeqToString>(path, ((System.Func, Dafny.ISequence>)((_11_s) => { - return ((_11_s)); -})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_10_fullTraitPath)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" are marked {:extern} and some are not.")), Dafny.Sequence.UnicodeFromString(" For the Rust compiler, please make all methods (")), RAST.__default.SeqToString>(_6_properMethods, ((System.Func, Dafny.ISequence>)((_12_s) => { - return (_12_s); + if ((new BigInteger((_11_body).Count)) != (new BigInteger((_8_properMethods).Count))) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the "), kind), Dafny.Sequence.UnicodeFromString(" ")), RAST.__default.SeqToString>(path, ((System.Func, Dafny.ISequence>)((_13_s) => { + return ((_13_s)); +})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_12_fullTraitPath)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" are marked {:extern} and some are not.")), Dafny.Sequence.UnicodeFromString(" For the Rust compiler, please make all methods (")), RAST.__default.SeqToString>(_8_properMethods, ((System.Func, Dafny.ISequence>)((_14_s) => { + return (_14_s); })), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(") bodiless and mark as {:extern} and implement them in a Rust file, ")), Dafny.Sequence.UnicodeFromString("or mark none of them as {:extern} and implement them in Dafny. ")), Dafny.Sequence.UnicodeFromString("Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible."))); } } - if ((_5_traitType).is_GeneralTrait) { - _9_body = Dafny.Sequence.Concat(_9_body, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))))); + if ((_7_traitType).is_GeneralTrait) { + _11_body = Dafny.Sequence.Concat(_11_body, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_12_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))))); } else { if (((kind).Equals(Dafny.Sequence.UnicodeFromString("datatype"))) || ((kind).Equals(Dafny.Sequence.UnicodeFromString("newtype")))) { - RAST._IExpr _13_dummy; + RAST._IExpr _15_dummy; RAST._IExpr _out3; _out3 = (this).Error(Dafny.Sequence.UnicodeFromString("Cannot extend non-general traits"), (this).InitEmptyExpr()); - _13_dummy = _out3; + _15_dummy = _out3; } } - RAST._IModDecl _14_x; - _14_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _10_fullTraitPath, RAST.Type.create_TypeApp(_0_genSelfPath, rTypeParams), _9_body)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_14_x)); - Dafny.ISequence _15_upcastTraitToImplement = Dafny.Sequence.Empty; - Dafny.ISequence _16_upcastTraitFn = Dafny.Sequence.Empty; - if ((_5_traitType).is_GeneralTrait) { + RAST._IModDecl _16_x; + _16_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _12_fullTraitPath, RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), _11_body)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_16_x)); + Dafny.ISequence _17_upcastTraitToImplement = Dafny.Sequence.Empty; + Dafny.ISequence _18_upcastTraitFn = Dafny.Sequence.Empty; + if ((_7_traitType).is_GeneralTrait) { Dafny.ISequence _rhs0 = Dafny.Sequence.UnicodeFromString("UpcastBox"); Dafny.ISequence _rhs1 = Dafny.Sequence.UnicodeFromString("UpcastStructBoxFn!"); - _15_upcastTraitToImplement = _rhs0; - _16_upcastTraitFn = _rhs1; + _17_upcastTraitToImplement = _rhs0; + _18_upcastTraitFn = _rhs1; + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_12_fullTraitPath)), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_12_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((_2_genPathExpr).ApplyType(rTypeParams)).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(RAST.__default.self))))))))); } else { - Dafny.ISequence _rhs2 = (this).Upcast; - Dafny.ISequence _rhs3 = (this).UpcastFnMacro; - _15_upcastTraitToImplement = _rhs2; - _16_upcastTraitFn = _rhs3; + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_12_fullTraitPath))), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_12_fullTraitPath))))))))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(_15_upcastTraitToImplement)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_10_fullTraitPath))), RAST.Type.create_TypeApp(_0_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel(_16_upcastTraitFn)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_10_fullTraitPath))))))))); } goto after_match0; } @@ -573,7 +574,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } _14_parents = Dafny.Sequence.Concat(_14_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_19_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)))); if ((_17_parentTyp).IsGeneralTrait()) { - _15_upcastImplemented = Dafny.Sequence.Concat(_15_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBoxFn!"))).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(_18_parentTpe)))))))); + _15_upcastImplemented = Dafny.Sequence.Concat(_15_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_18_parentTpe))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); } } s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_rTypeParamsDecls, _10_traitFulltype, _14_parents, _12_implBody))); @@ -1268,7 +1269,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) if (_67_cIsEq) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_105_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, _106_fullType, 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(_106_fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_101_structName, _102_structAssignments))))))))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsType()).Apply1(_106_fullType), RAST.Type.create_Borrowed(_106_fullType), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self)))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsType()).Apply1(_106_fullType), _106_fullType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfBorrowed), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self)))))))); } Dafny.ISequence _107_superTraitImplementations; Dafny.ISequence _out16; @@ -2223,6 +2224,151 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Defs._ISelfInfo } after_match0: ; } + public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequence typeArgs, Dafny.ISequence args, Defs._IEnvironment env, out RAST._IExpr r, out Dafny.ISet> readIdents) + { + r = RAST.Expr.Default(); + readIdents = Dafny.Set>.Empty; + Dafny.ISequence _0_argExprs; + Dafny.ISet> _1_recIdents; + Dafny.ISequence _2_typeExprs; + Std.Wrappers._IOption _3_fullNameQualifier; + Dafny.ISequence _out0; + Dafny.ISet> _out1; + Dafny.ISequence _out2; + Std.Wrappers._IOption _out3; + (this).GenArgs(selfIdent, name, typeArgs, args, env, out _out0, out _out1, out _out2, out _out3); + _0_argExprs = _out0; + _1_recIdents = _out1; + _2_typeExprs = _out2; + _3_fullNameQualifier = _out3; + readIdents = _1_recIdents; + Std.Wrappers._IOption _source0 = _3_fullNameQualifier; + { + if (_source0.is_Some) { + DAST._IResolvedType value0 = _source0.dtor_value; + Dafny.ISequence> _4_path = value0.dtor_path; + Dafny.ISequence _5_onTypeArgs = value0.dtor_typeArgs; + DAST._IResolvedTypeBase _6_base = value0.dtor_kind; + RAST._IExpr _7_fullPath; + RAST._IExpr _out4; + _out4 = (this).GenPathExpr(_4_path, true); + _7_fullPath = _out4; + Dafny.ISequence _8_onTypeExprs; + Dafny.ISequence _out5; + _out5 = (this).GenTypeArgs(_5_onTypeArgs, Defs.GenTypeContext.@default()); + _8_onTypeExprs = _out5; + RAST._IExpr _9_onExpr = RAST.Expr.Default(); + Defs._IOwnership _10_recOwnership = Defs.Ownership.Default(); + Dafny.ISet> _11_recIdents = Dafny.Set>.Empty; + if ((((_6_base).is_Trait) && (((_6_base).dtor_traitType).is_ObjectTrait)) || ((_6_base).is_Class)) { + RAST._IExpr _out6; + Defs._IOwnership _out7; + Dafny.ISet> _out8; + (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out6, out _out7, out _out8); + _9_onExpr = _out6; + _10_recOwnership = _out7; + _11_recIdents = _out8; + _9_onExpr = ((this).read__macro).Apply1(_9_onExpr); + readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); + } else if (((_6_base).is_Trait) && (((_6_base).dtor_traitType).is_GeneralTrait)) { + RAST._IExpr _out9; + Defs._IOwnership _out10; + Dafny.ISet> _out11; + (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out9, out _out10, out _out11); + _9_onExpr = _out9; + _10_recOwnership = _out10; + _11_recIdents = _out11; + if (((_9_onExpr).is_Identifier) && ((env).NeedsAsRefForBorrow((_9_onExpr).dtor_name))) { + _9_onExpr = ((_9_onExpr).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); + } else if ((_9_onExpr).IsBorrow()) { + _9_onExpr = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(_9_onExpr); + } + readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); + } else if (((_6_base).is_Newtype) && (Defs.__default.IsNewtypeCopy((_6_base).dtor_range))) { + RAST._IExpr _out12; + Defs._IOwnership _out13; + Dafny.ISet> _out14; + (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out12, out _out13, out _out14); + _9_onExpr = _out12; + _10_recOwnership = _out13; + _11_recIdents = _out14; + readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); + } else { + RAST._IExpr _out15; + Defs._IOwnership _out16; + Dafny.ISet> _out17; + (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out15, out _out16, out _out17); + _9_onExpr = _out15; + _10_recOwnership = _out16; + _11_recIdents = _out17; + readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); + } + r = ((((_7_fullPath).ApplyType(_8_onTypeExprs)).FSel(Defs.__default.escapeName((name).dtor_name))).ApplyType(_2_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_9_onExpr), _0_argExprs)); + goto after_match0; + } + } + { + RAST._IExpr _12_onExpr; + Defs._IOwnership _13___v35; + Dafny.ISet> _14_recIdents; + RAST._IExpr _out18; + Defs._IOwnership _out19; + Dafny.ISet> _out20; + (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out18, out _out19, out _out20); + _12_onExpr = _out18; + _13___v35 = _out19; + _14_recIdents = _out20; + readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); + Dafny.ISequence _15_renderedName; + _15_renderedName = (this).GetMethodName(@on, name); + DAST._IExpression _source1 = @on; + { + bool disjunctiveMatch0 = false; + if (_source1.is_Companion) { + disjunctiveMatch0 = true; + } + if (_source1.is_ExternCompanion) { + disjunctiveMatch0 = true; + } + if (disjunctiveMatch0) { + { + _12_onExpr = (_12_onExpr).FSel(_15_renderedName); + } + goto after_match1; + } + } + { + { + if (!object.Equals(_12_onExpr, RAST.__default.self)) { + DAST._ICallName _source2 = name; + { + if (_source2.is_CallName) { + Std.Wrappers._IOption onType0 = _source2.dtor_onType; + if (onType0.is_Some) { + DAST._IType _16_tpe = onType0.dtor_value; + RAST._IType _17_typ; + RAST._IType _out21; + _out21 = (this).GenType(_16_tpe, Defs.GenTypeContext.@default()); + _17_typ = _out21; + if (((_17_typ).IsObjectOrPointer()) && (!object.Equals(_12_onExpr, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))))) { + _12_onExpr = ((this).read__macro).Apply1(_12_onExpr); + } + goto after_match2; + } + } + } + { + } + after_match2: ; + } + _12_onExpr = (_12_onExpr).Sel(_15_renderedName); + } + } + after_match1: ; + r = ((_12_onExpr).ApplyType(_2_typeExprs)).Apply(_0_argExprs); + } + after_match0: ; + } public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, bool isLast, Std.Wrappers._IOption>> earlyReturn, out RAST._IExpr generated, out Dafny.ISet> readIdents, out Defs._IEnvironment newEnv) { generated = RAST.Expr.Default(); @@ -2250,15 +2396,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _5_isAssignedVar = Defs.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { RAST._IExpr _6_rhs; - Defs._IOwnership _7___v31; - Dafny.ISet> _8___v32; + Defs._IOwnership _7___v45; + Dafny.ISet> _8___v46; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr(DAST.Expression.create_InitializationValue(((_2_field).dtor_formal).dtor_typ), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); _6_rhs = _out1; - _7___v31 = _out2; - _8___v32 = _out3; + _7___v45 = _out2; + _8___v46 = _out3; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); Dafny.ISequence _9_update__if__uninit; if ((_2_field).dtor_isConstant) { @@ -2351,14 +2497,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _23_expression = _source0.dtor_value; { RAST._IExpr _24_exprGen; - Defs._IOwnership _25___v33; + Defs._IOwnership _25___v47; Dafny.ISet> _26_exprIdents; RAST._IExpr _out11; Defs._IOwnership _out12; Dafny.ISet> _out13; (this).GenExpr(_23_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out11, out _out12, out _out13); _24_exprGen = _out11; - _25___v33 = _out12; + _25___v47 = _out12; _26_exprIdents = _out13; if ((_22_lhs).is_Ident) { Dafny.ISequence _27_rustId; @@ -2408,14 +2554,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _37_elsDafny = _source0.dtor_els; { RAST._IExpr _38_cond; - Defs._IOwnership _39___v34; + Defs._IOwnership _39___v48; Dafny.ISet> _40_recIdents; RAST._IExpr _out18; Defs._IOwnership _out19; Dafny.ISet> _out20; (this).GenExpr(_35_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out18, out _out19, out _out20); _38_cond = _out18; - _39___v34 = _out19; + _39___v48 = _out19; _40_recIdents = _out20; Dafny.ISequence _41_condString; _41_condString = (_38_cond)._ToString(Defs.__default.IND); @@ -2476,14 +2622,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _54_body = _source0.dtor_body; { RAST._IExpr _55_cond; - Defs._IOwnership _56___v35; + Defs._IOwnership _56___v49; Dafny.ISet> _57_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr(_53_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _55_cond = _out30; - _56___v35 = _out31; + _56___v49 = _out31; _57_recIdents = _out32; readIdents = _57_recIdents; RAST._IExpr _58_bodyExpr; @@ -2511,14 +2657,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _64_body = _source0.dtor_body; { RAST._IExpr _65_over; - Defs._IOwnership _66___v36; + Defs._IOwnership _66___v50; Dafny.ISet> _67_recIdents; RAST._IExpr _out36; Defs._IOwnership _out37; Dafny.ISet> _out38; (this).GenExpr(_63_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out36, out _out37, out _out38); _65_over = _out36; - _66___v36 = _out37; + _66___v50 = _out37; _67_recIdents = _out38; if (((_63_overExpr).is_MapBoundedPool) || ((_63_overExpr).is_SetBoundedPool)) { _65_over = ((_65_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); @@ -2582,15 +2728,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _76_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { RAST._IExpr _77_selfClone; - Defs._IOwnership _78___v37; - Dafny.ISet> _79___v38; + Defs._IOwnership _78___v51; + Dafny.ISet> _79___v52; RAST._IExpr _out43; Defs._IOwnership _out44; Dafny.ISet> _out45; (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out43, out _out44, out _out45); _77_selfClone = _out43; - _78___v37 = _out44; - _79___v38 = _out45; + _78___v51 = _out44; + _79___v52 = _out45; generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_77_selfClone))); if (((_76_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { _76_oldEnv = (_76_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); @@ -2610,15 +2756,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv goto continue_4_0; } RAST._IExpr _83_paramInit; - Defs._IOwnership _84___v39; - Dafny.ISet> _85___v40; + Defs._IOwnership _84___v53; + Dafny.ISet> _85___v54; RAST._IExpr _out46; Defs._IOwnership _out47; Dafny.ISet> _out48; (this).GenIdent(_82_param, selfIdent, _76_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out46, out _out47, out _out48); _83_paramInit = _out46; - _84___v39 = _out47; - _85___v40 = _out48; + _84___v53 = _out47; + _85___v54 = _out48; Dafny.ISequence _86_recVar; _86_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_81_paramI)); generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _86_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_83_paramInit))); @@ -2666,149 +2812,37 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _94_args = _source0.dtor_args; Std.Wrappers._IOption>> _95_maybeOutVars = _source0.dtor_outs; { - Dafny.ISequence _96_argExprs; - Dafny.ISet> _97_recIdents; - Dafny.ISequence _98_typeExprs; - Std.Wrappers._IOption _99_fullNameQualifier; - Dafny.ISequence _out52; + RAST._IExpr _out52; Dafny.ISet> _out53; - Dafny.ISequence _out54; - Std.Wrappers._IOption _out55; - (this).GenArgs(selfIdent, _92_name, _93_typeArgs, _94_args, env, out _out52, out _out53, out _out54, out _out55); - _96_argExprs = _out52; - _97_recIdents = _out53; - _98_typeExprs = _out54; - _99_fullNameQualifier = _out55; - readIdents = _97_recIdents; - Std.Wrappers._IOption _source2 = _99_fullNameQualifier; - { - if (_source2.is_Some) { - DAST._IResolvedType value0 = _source2.dtor_value; - Dafny.ISequence> _100_path = value0.dtor_path; - Dafny.ISequence _101_onTypeArgs = value0.dtor_typeArgs; - DAST._IResolvedTypeBase _102_base = value0.dtor_kind; - RAST._IExpr _103_fullPath; - RAST._IExpr _out56; - _out56 = (this).GenPathExpr(_100_path, true); - _103_fullPath = _out56; - Dafny.ISequence _104_onTypeExprs; - Dafny.ISequence _out57; - _out57 = (this).GenTypeArgs(_101_onTypeArgs, Defs.GenTypeContext.@default()); - _104_onTypeExprs = _out57; - RAST._IExpr _105_onExpr = RAST.Expr.Default(); - Defs._IOwnership _106_recOwnership = Defs.Ownership.Default(); - Dafny.ISet> _107_recIdents = Dafny.Set>.Empty; - if (((_102_base).is_Trait) || ((_102_base).is_Class)) { - RAST._IExpr _out58; - Defs._IOwnership _out59; - Dafny.ISet> _out60; - (this).GenExpr(_91_on, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out58, out _out59, out _out60); - _105_onExpr = _out58; - _106_recOwnership = _out59; - _107_recIdents = _out60; - _105_onExpr = ((this).modify__macro).Apply1(_105_onExpr); - readIdents = Dafny.Set>.Union(readIdents, _107_recIdents); - } else { - RAST._IExpr _out61; - Defs._IOwnership _out62; - Dafny.ISet> _out63; - (this).GenExpr(_91_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out61, out _out62, out _out63); - _105_onExpr = _out61; - _106_recOwnership = _out62; - _107_recIdents = _out63; - readIdents = Dafny.Set>.Union(readIdents, _107_recIdents); - } - generated = ((((_103_fullPath).ApplyType(_104_onTypeExprs)).FSel(Defs.__default.escapeName((_92_name).dtor_name))).ApplyType(_98_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_105_onExpr), _96_argExprs)); - goto after_match2; - } - } - { - RAST._IExpr _108_onExpr; - Defs._IOwnership _109___v45; - Dafny.ISet> _110_enclosingIdents; - RAST._IExpr _out64; - Defs._IOwnership _out65; - Dafny.ISet> _out66; - (this).GenExpr(_91_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out64, out _out65, out _out66); - _108_onExpr = _out64; - _109___v45 = _out65; - _110_enclosingIdents = _out66; - readIdents = Dafny.Set>.Union(readIdents, _110_enclosingIdents); - Dafny.ISequence _111_renderedName; - _111_renderedName = (this).GetMethodName(_91_on, _92_name); - DAST._IExpression _source3 = _91_on; - { - bool disjunctiveMatch0 = false; - if (_source3.is_Companion) { - disjunctiveMatch0 = true; - } - if (_source3.is_ExternCompanion) { - disjunctiveMatch0 = true; - } - if (disjunctiveMatch0) { - { - _108_onExpr = (_108_onExpr).FSel(_111_renderedName); - } - goto after_match3; - } - } - { - { - if (!object.Equals(_108_onExpr, RAST.__default.self)) { - DAST._ICallName _source4 = _92_name; - { - if (_source4.is_CallName) { - Std.Wrappers._IOption onType0 = _source4.dtor_onType; - if (onType0.is_Some) { - DAST._IType _112_tpe = onType0.dtor_value; - RAST._IType _113_typ; - RAST._IType _out67; - _out67 = (this).GenType(_112_tpe, Defs.GenTypeContext.@default()); - _113_typ = _out67; - if (((_113_typ).IsObjectOrPointer()) && (!object.Equals(_108_onExpr, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))))) { - _108_onExpr = ((this).read__macro).Apply1(_108_onExpr); - } - goto after_match4; - } - } - } - { - } - after_match4: ; - } - _108_onExpr = (_108_onExpr).Sel(_111_renderedName); - } - } - after_match3: ; - generated = ((_108_onExpr).ApplyType(_98_typeExprs)).Apply(_96_argExprs); - } - after_match2: ; + (this).GenOwnedCallPart(_91_on, selfIdent, _92_name, _93_typeArgs, _94_args, env, out _out52, out _out53); + generated = _out52; + readIdents = _out53; if (((_95_maybeOutVars).is_Some) && ((new BigInteger(((_95_maybeOutVars).dtor_value).Count)) == (BigInteger.One))) { - Dafny.ISequence _114_outVar; - _114_outVar = Defs.__default.escapeVar(((_95_maybeOutVars).dtor_value).Select(BigInteger.Zero)); - if (!((env).CanReadWithoutClone(_114_outVar))) { + Dafny.ISequence _96_outVar; + _96_outVar = Defs.__default.escapeVar(((_95_maybeOutVars).dtor_value).Select(BigInteger.Zero)); + if (!((env).CanReadWithoutClone(_96_outVar))) { generated = RAST.__default.MaybePlacebo(generated); } - generated = RAST.__default.AssignVar(_114_outVar, generated); + generated = RAST.__default.AssignVar(_96_outVar, generated); } else if (((_95_maybeOutVars).is_None) || ((new BigInteger(((_95_maybeOutVars).dtor_value).Count)).Sign == 0)) { } else { - Dafny.ISequence _115_tmpVar; - _115_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); - RAST._IExpr _116_tmpId; - _116_tmpId = RAST.Expr.create_Identifier(_115_tmpVar); - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _115_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); - Dafny.ISequence> _117_outVars; - _117_outVars = (_95_maybeOutVars).dtor_value; - BigInteger _hi2 = new BigInteger((_117_outVars).Count); - for (BigInteger _118_outI = BigInteger.Zero; _118_outI < _hi2; _118_outI++) { - Dafny.ISequence _119_outVar; - _119_outVar = Defs.__default.escapeVar((_117_outVars).Select(_118_outI)); - RAST._IExpr _120_rhs; - _120_rhs = (_116_tmpId).Sel(Std.Strings.__default.OfNat(_118_outI)); - if (!((env).CanReadWithoutClone(_119_outVar))) { - _120_rhs = RAST.__default.MaybePlacebo(_120_rhs); + Dafny.ISequence _97_tmpVar; + _97_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); + RAST._IExpr _98_tmpId; + _98_tmpId = RAST.Expr.create_Identifier(_97_tmpVar); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _97_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); + Dafny.ISequence> _99_outVars; + _99_outVars = (_95_maybeOutVars).dtor_value; + BigInteger _hi2 = new BigInteger((_99_outVars).Count); + for (BigInteger _100_outI = BigInteger.Zero; _100_outI < _hi2; _100_outI++) { + Dafny.ISequence _101_outVar; + _101_outVar = Defs.__default.escapeVar((_99_outVars).Select(_100_outI)); + RAST._IExpr _102_rhs; + _102_rhs = (_98_tmpId).Sel(Std.Strings.__default.OfNat(_100_outI)); + if (!((env).CanReadWithoutClone(_101_outVar))) { + _102_rhs = RAST.__default.MaybePlacebo(_102_rhs); } - generated = (generated).Then(RAST.__default.AssignVar(_119_outVar, _120_rhs)); + generated = (generated).Then(RAST.__default.AssignVar(_101_outVar, _102_rhs)); } } newEnv = env; @@ -2818,23 +2852,23 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_Return) { - DAST._IExpression _121_exprDafny = _source0.dtor_expr; + DAST._IExpression _103_exprDafny = _source0.dtor_expr; { - RAST._IExpr _122_expr; - Defs._IOwnership _123___v55; - Dafny.ISet> _124_recIdents; - RAST._IExpr _out68; - Defs._IOwnership _out69; - Dafny.ISet> _out70; - (this).GenExpr(_121_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out68, out _out69, out _out70); - _122_expr = _out68; - _123___v55 = _out69; - _124_recIdents = _out70; - readIdents = _124_recIdents; + RAST._IExpr _104_expr; + Defs._IOwnership _105___v55; + Dafny.ISet> _106_recIdents; + RAST._IExpr _out54; + Defs._IOwnership _out55; + Dafny.ISet> _out56; + (this).GenExpr(_103_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out54, out _out55, out _out56); + _104_expr = _out54; + _105___v55 = _out55; + _106_recIdents = _out56; + readIdents = _106_recIdents; if (isLast) { - generated = _122_expr; + generated = _104_expr; } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_122_expr)); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_104_expr)); } newEnv = env; } @@ -2844,38 +2878,38 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv { if (_source0.is_EarlyReturn) { { - Std.Wrappers._IOption>> _source5 = earlyReturn; + Std.Wrappers._IOption>> _source2 = earlyReturn; { - if (_source5.is_None) { + if (_source2.is_None) { generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_None()); - goto after_match5; + goto after_match2; } } { - Dafny.ISequence> _125_rustIdents = _source5.dtor_value; - Dafny.ISequence _126_tupleArgs; - _126_tupleArgs = Dafny.Sequence.FromElements(); - BigInteger _hi3 = new BigInteger((_125_rustIdents).Count); - for (BigInteger _127_i = BigInteger.Zero; _127_i < _hi3; _127_i++) { - RAST._IExpr _128_rIdent; - Defs._IOwnership _129___v56; - Dafny.ISet> _130___v57; - RAST._IExpr _out71; - Defs._IOwnership _out72; - Dafny.ISet> _out73; - (this).GenIdent((_125_rustIdents).Select(_127_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out71, out _out72, out _out73); - _128_rIdent = _out71; - _129___v56 = _out72; - _130___v57 = _out73; - _126_tupleArgs = Dafny.Sequence.Concat(_126_tupleArgs, Dafny.Sequence.FromElements(_128_rIdent)); + Dafny.ISequence> _107_rustIdents = _source2.dtor_value; + Dafny.ISequence _108_tupleArgs; + _108_tupleArgs = Dafny.Sequence.FromElements(); + BigInteger _hi3 = new BigInteger((_107_rustIdents).Count); + for (BigInteger _109_i = BigInteger.Zero; _109_i < _hi3; _109_i++) { + RAST._IExpr _110_rIdent; + Defs._IOwnership _111___v56; + Dafny.ISet> _112___v57; + RAST._IExpr _out57; + Defs._IOwnership _out58; + Dafny.ISet> _out59; + (this).GenIdent((_107_rustIdents).Select(_109_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out57, out _out58, out _out59); + _110_rIdent = _out57; + _111___v56 = _out58; + _112___v57 = _out59; + _108_tupleArgs = Dafny.Sequence.Concat(_108_tupleArgs, Dafny.Sequence.FromElements(_110_rIdent)); } - if ((new BigInteger((_126_tupleArgs).Count)) == (BigInteger.One)) { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_126_tupleArgs).Select(BigInteger.Zero))); + if ((new BigInteger((_108_tupleArgs).Count)) == (BigInteger.One)) { + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_108_tupleArgs).Select(BigInteger.Zero))); } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_126_tupleArgs))); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_108_tupleArgs))); } } - after_match5: ; + after_match2: ; readIdents = Dafny.Set>.FromElements(); newEnv = env; } @@ -2893,20 +2927,20 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } } { - DAST._IExpression _131_e = _source0.dtor_Print_a0; + DAST._IExpression _113_e = _source0.dtor_Print_a0; { - RAST._IExpr _132_printedExpr; - Defs._IOwnership _133_recOwnership; - Dafny.ISet> _134_recIdents; - RAST._IExpr _out74; - Defs._IOwnership _out75; - Dafny.ISet> _out76; - (this).GenExpr(_131_e, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out74, out _out75, out _out76); - _132_printedExpr = _out74; - _133_recOwnership = _out75; - _134_recIdents = _out76; - generated = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("print!"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("{}"), false, false), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrintWrapper"))).AsExpr()).Apply1(_132_printedExpr))); - readIdents = _134_recIdents; + RAST._IExpr _114_printedExpr; + Defs._IOwnership _115_recOwnership; + Dafny.ISet> _116_recIdents; + RAST._IExpr _out60; + Defs._IOwnership _out61; + Dafny.ISet> _out62; + (this).GenExpr(_113_e, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out60, out _out61, out _out62); + _114_printedExpr = _out60; + _115_recOwnership = _out61; + _116_recIdents = _out62; + generated = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("print!"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("{}"), false, false), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrintWrapper"))).AsExpr()).Apply1(_114_printedExpr))); + readIdents = _116_recIdents; newEnv = env; } } @@ -5947,247 +5981,107 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _277_typeArgs = _source0.dtor_typeArgs; Dafny.ISequence _278_args = _source0.dtor_args; { - Dafny.ISequence _279_argExprs; - Dafny.ISet> _280_recIdents; - Dafny.ISequence _281_typeExprs; - Std.Wrappers._IOption _282_fullNameQualifier; - Dafny.ISequence _out230; + RAST._IExpr _out230; Dafny.ISet> _out231; - Dafny.ISequence _out232; - Std.Wrappers._IOption _out233; - (this).GenArgs(selfIdent, _276_name, _277_typeArgs, _278_args, env, out _out230, out _out231, out _out232, out _out233); - _279_argExprs = _out230; - _280_recIdents = _out231; - _281_typeExprs = _out232; - _282_fullNameQualifier = _out233; - readIdents = _280_recIdents; - Std.Wrappers._IOption _source8 = _282_fullNameQualifier; - { - if (_source8.is_Some) { - DAST._IResolvedType value0 = _source8.dtor_value; - Dafny.ISequence> _283_path = value0.dtor_path; - Dafny.ISequence _284_onTypeArgs = value0.dtor_typeArgs; - DAST._IResolvedTypeBase _285_base = value0.dtor_kind; - RAST._IExpr _286_fullPath; - RAST._IExpr _out234; - _out234 = (this).GenPathExpr(_283_path, true); - _286_fullPath = _out234; - Dafny.ISequence _287_onTypeExprs; - Dafny.ISequence _out235; - _out235 = (this).GenTypeArgs(_284_onTypeArgs, Defs.GenTypeContext.@default()); - _287_onTypeExprs = _out235; - RAST._IExpr _288_onExpr = RAST.Expr.Default(); - Defs._IOwnership _289_recOwnership = Defs.Ownership.Default(); - Dafny.ISet> _290_recIdents = Dafny.Set>.Empty; - if ((((_285_base).is_Trait) && (((_285_base).dtor_traitType).is_ObjectTrait)) || ((_285_base).is_Class)) { - RAST._IExpr _out236; - Defs._IOwnership _out237; - Dafny.ISet> _out238; - (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out236, out _out237, out _out238); - _288_onExpr = _out236; - _289_recOwnership = _out237; - _290_recIdents = _out238; - _288_onExpr = ((this).read__macro).Apply1(_288_onExpr); - readIdents = Dafny.Set>.Union(readIdents, _290_recIdents); - } else if (((_285_base).is_Trait) && (((_285_base).dtor_traitType).is_GeneralTrait)) { - RAST._IExpr _out239; - Defs._IOwnership _out240; - Dafny.ISet> _out241; - (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out239, out _out240, out _out241); - _288_onExpr = _out239; - _289_recOwnership = _out240; - _290_recIdents = _out241; - if (((_288_onExpr).is_Identifier) && ((env).NeedsAsRefForBorrow((_288_onExpr).dtor_name))) { - _288_onExpr = ((_288_onExpr).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); - } else if ((_288_onExpr).IsBorrow()) { - _288_onExpr = (((_288_onExpr).dtor_underlying).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); - } - readIdents = Dafny.Set>.Union(readIdents, _290_recIdents); - } else if (((_285_base).is_Newtype) && (Defs.__default.IsNewtypeCopy((_285_base).dtor_range))) { - RAST._IExpr _out242; - Defs._IOwnership _out243; - Dafny.ISet> _out244; - (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out242, out _out243, out _out244); - _288_onExpr = _out242; - _289_recOwnership = _out243; - _290_recIdents = _out244; - readIdents = Dafny.Set>.Union(readIdents, _290_recIdents); - } else { - RAST._IExpr _out245; - Defs._IOwnership _out246; - Dafny.ISet> _out247; - (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out245, out _out246, out _out247); - _288_onExpr = _out245; - _289_recOwnership = _out246; - _290_recIdents = _out247; - readIdents = Dafny.Set>.Union(readIdents, _290_recIdents); - } - r = ((((_286_fullPath).ApplyType(_287_onTypeExprs)).FSel(Defs.__default.escapeName((_276_name).dtor_name))).ApplyType(_281_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_288_onExpr), _279_argExprs)); - RAST._IExpr _out248; - Defs._IOwnership _out249; - (this).FromOwned(r, expectedOwnership, out _out248, out _out249); - r = _out248; - resultingOwnership = _out249; - goto after_match8; - } - } - { - RAST._IExpr _291_onExpr; - Defs._IOwnership _292___v129; - Dafny.ISet> _293_recIdents; - RAST._IExpr _out250; - Defs._IOwnership _out251; - Dafny.ISet> _out252; - (this).GenExpr(_275_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out250, out _out251, out _out252); - _291_onExpr = _out250; - _292___v129 = _out251; - _293_recIdents = _out252; - readIdents = Dafny.Set>.Union(readIdents, _293_recIdents); - Dafny.ISequence _294_renderedName; - _294_renderedName = (this).GetMethodName(_275_on, _276_name); - DAST._IExpression _source9 = _275_on; - { - bool disjunctiveMatch0 = false; - if (_source9.is_Companion) { - disjunctiveMatch0 = true; - } - if (_source9.is_ExternCompanion) { - disjunctiveMatch0 = true; - } - if (disjunctiveMatch0) { - { - _291_onExpr = (_291_onExpr).FSel(_294_renderedName); - } - goto after_match9; - } - } - { - { - if (!object.Equals(_291_onExpr, RAST.__default.self)) { - DAST._ICallName _source10 = _276_name; - { - if (_source10.is_CallName) { - Std.Wrappers._IOption onType0 = _source10.dtor_onType; - if (onType0.is_Some) { - DAST._IType _295_tpe = onType0.dtor_value; - RAST._IType _296_typ; - RAST._IType _out253; - _out253 = (this).GenType(_295_tpe, Defs.GenTypeContext.@default()); - _296_typ = _out253; - if ((_296_typ).IsObjectOrPointer()) { - _291_onExpr = ((this).read__macro).Apply1(_291_onExpr); - } - goto after_match10; - } - } - } - { - } - after_match10: ; - } - _291_onExpr = (_291_onExpr).Sel(_294_renderedName); - } - } - after_match9: ; - r = ((_291_onExpr).ApplyType(_281_typeExprs)).Apply(_279_argExprs); - RAST._IExpr _out254; - Defs._IOwnership _out255; - (this).FromOwned(r, expectedOwnership, out _out254, out _out255); - r = _out254; - resultingOwnership = _out255; - return ; - } - after_match8: ; + (this).GenOwnedCallPart(_275_on, selfIdent, _276_name, _277_typeArgs, _278_args, env, out _out230, out _out231); + r = _out230; + readIdents = _out231; + RAST._IExpr _out232; + Defs._IOwnership _out233; + (this).FromOwned(r, expectedOwnership, out _out232, out _out233); + r = _out232; + resultingOwnership = _out233; + return ; } goto after_match0; } } { if (_source0.is_Lambda) { - Dafny.ISequence _297_paramsDafny = _source0.dtor_params; - DAST._IType _298_retType = _source0.dtor_retType; - Dafny.ISequence _299_body = _source0.dtor_body; + Dafny.ISequence _279_paramsDafny = _source0.dtor_params; + DAST._IType _280_retType = _source0.dtor_retType; + Dafny.ISequence _281_body = _source0.dtor_body; { - Dafny.ISequence _300_params; - Dafny.ISequence _out256; - _out256 = (this).GenParams(_297_paramsDafny, true); - _300_params = _out256; - Dafny.ISequence> _301_paramNames; - _301_paramNames = Dafny.Sequence>.FromElements(); - Dafny.IMap,RAST._IType> _302_paramTypesMap; - _302_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); - BigInteger _hi11 = new BigInteger((_300_params).Count); - for (BigInteger _303_i = BigInteger.Zero; _303_i < _hi11; _303_i++) { - Dafny.ISequence _304_name; - _304_name = ((_300_params).Select(_303_i)).dtor_name; - _301_paramNames = Dafny.Sequence>.Concat(_301_paramNames, Dafny.Sequence>.FromElements(_304_name)); - _302_paramTypesMap = Dafny.Map, RAST._IType>.Update(_302_paramTypesMap, _304_name, ((_300_params).Select(_303_i)).dtor_tpe); - } - Defs._IEnvironment _305_subEnv; - _305_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_301_paramNames, _302_paramTypesMap)); - RAST._IExpr _306_recursiveGen; - Dafny.ISet> _307_recIdents; - Defs._IEnvironment _308___v139; - RAST._IExpr _out257; - Dafny.ISet> _out258; - Defs._IEnvironment _out259; - (this).GenStmts(_299_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _305_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out257, out _out258, out _out259); - _306_recursiveGen = _out257; - _307_recIdents = _out258; - _308___v139 = _out259; + Dafny.ISequence _282_params; + Dafny.ISequence _out234; + _out234 = (this).GenParams(_279_paramsDafny, true); + _282_params = _out234; + Dafny.ISequence> _283_paramNames; + _283_paramNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _284_paramTypesMap; + _284_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); + BigInteger _hi11 = new BigInteger((_282_params).Count); + for (BigInteger _285_i = BigInteger.Zero; _285_i < _hi11; _285_i++) { + Dafny.ISequence _286_name; + _286_name = ((_282_params).Select(_285_i)).dtor_name; + _283_paramNames = Dafny.Sequence>.Concat(_283_paramNames, Dafny.Sequence>.FromElements(_286_name)); + _284_paramTypesMap = Dafny.Map, RAST._IType>.Update(_284_paramTypesMap, _286_name, ((_282_params).Select(_285_i)).dtor_tpe); + } + Defs._IEnvironment _287_subEnv; + _287_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_283_paramNames, _284_paramTypesMap)); + RAST._IExpr _288_recursiveGen; + Dafny.ISet> _289_recIdents; + Defs._IEnvironment _290___v125; + RAST._IExpr _out235; + Dafny.ISet> _out236; + Defs._IEnvironment _out237; + (this).GenStmts(_281_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _287_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out235, out _out236, out _out237); + _288_recursiveGen = _out235; + _289_recIdents = _out236; + _290___v125 = _out237; readIdents = Dafny.Set>.FromElements(); - _307_recIdents = Dafny.Set>.Difference(_307_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_309_paramNames) => ((System.Func>>)(() => { + _289_recIdents = Dafny.Set>.Difference(_289_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_291_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); - foreach (Dafny.ISequence _compr_0 in (_309_paramNames).CloneAsArray()) { - Dafny.ISequence _310_name = (Dafny.ISequence)_compr_0; - if ((_309_paramNames).Contains(_310_name)) { - _coll0.Add(_310_name); + foreach (Dafny.ISequence _compr_0 in (_291_paramNames).CloneAsArray()) { + Dafny.ISequence _292_name = (Dafny.ISequence)_compr_0; + if ((_291_paramNames).Contains(_292_name)) { + _coll0.Add(_292_name); } } return Dafny.Set>.FromCollection(_coll0); - }))())(_301_paramNames)); - RAST._IExpr _311_allReadCloned; - _311_allReadCloned = (this).InitEmptyExpr(); - while (!(_307_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _312_next; - foreach (Dafny.ISequence _assign_such_that_1 in (_307_recIdents).Elements) { - _312_next = (Dafny.ISequence)_assign_such_that_1; - if ((_307_recIdents).Contains(_312_next)) { + }))())(_283_paramNames)); + RAST._IExpr _293_allReadCloned; + _293_allReadCloned = (this).InitEmptyExpr(); + while (!(_289_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _294_next; + foreach (Dafny.ISequence _assign_such_that_1 in (_289_recIdents).Elements) { + _294_next = (Dafny.ISequence)_assign_such_that_1; + if ((_289_recIdents).Contains(_294_next)) { goto after__ASSIGN_SUCH_THAT_1; } } throw new System.Exception("assign-such-that search produced no value"); after__ASSIGN_SUCH_THAT_1: ; - if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_312_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { - RAST._IExpr _313_selfCloned; - Defs._IOwnership _314___v140; - Dafny.ISet> _315___v141; - RAST._IExpr _out260; - Defs._IOwnership _out261; - Dafny.ISet> _out262; - (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out260, out _out261, out _out262); - _313_selfCloned = _out260; - _314___v140 = _out261; - _315___v141 = _out262; - _311_allReadCloned = (_311_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_313_selfCloned))); - } else if (!((_301_paramNames).Contains(_312_next))) { - RAST._IExpr _316_copy; - _316_copy = (RAST.Expr.create_Identifier(_312_next)).Clone(); - _311_allReadCloned = (_311_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _312_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_316_copy))); - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_312_next)); + if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_294_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { + RAST._IExpr _295_selfCloned; + Defs._IOwnership _296___v126; + Dafny.ISet> _297___v127; + RAST._IExpr _out238; + Defs._IOwnership _out239; + Dafny.ISet> _out240; + (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out238, out _out239, out _out240); + _295_selfCloned = _out238; + _296___v126 = _out239; + _297___v127 = _out240; + _293_allReadCloned = (_293_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_295_selfCloned))); + } else if (!((_283_paramNames).Contains(_294_next))) { + RAST._IExpr _298_copy; + _298_copy = (RAST.Expr.create_Identifier(_294_next)).Clone(); + _293_allReadCloned = (_293_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _294_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_298_copy))); + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_294_next)); } - _307_recIdents = Dafny.Set>.Difference(_307_recIdents, Dafny.Set>.FromElements(_312_next)); - } - RAST._IType _317_retTypeGen; - RAST._IType _out263; - _out263 = (this).GenType(_298_retType, Defs.GenTypeContext.@default()); - _317_retTypeGen = _out263; - r = RAST.Expr.create_Block((_311_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_300_params, Std.Wrappers.Option.create_Some(_317_retTypeGen), RAST.Expr.create_Block(_306_recursiveGen))))); - RAST._IExpr _out264; - Defs._IOwnership _out265; - (this).FromOwned(r, expectedOwnership, out _out264, out _out265); - r = _out264; - resultingOwnership = _out265; + _289_recIdents = Dafny.Set>.Difference(_289_recIdents, Dafny.Set>.FromElements(_294_next)); + } + RAST._IType _299_retTypeGen; + RAST._IType _out241; + _out241 = (this).GenType(_280_retType, Defs.GenTypeContext.@default()); + _299_retTypeGen = _out241; + r = RAST.Expr.create_Block((_293_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_282_params, Std.Wrappers.Option.create_Some(_299_retTypeGen), RAST.Expr.create_Block(_288_recursiveGen))))); + RAST._IExpr _out242; + Defs._IOwnership _out243; + (this).FromOwned(r, expectedOwnership, out _out242, out _out243); + r = _out242; + resultingOwnership = _out243; return ; } goto after_match0; @@ -6195,72 +6089,72 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_BetaRedex) { - Dafny.ISequence<_System._ITuple2> _318_values = _source0.dtor_values; - DAST._IType _319_retType = _source0.dtor_retType; - DAST._IExpression _320_expr = _source0.dtor_expr; + Dafny.ISequence<_System._ITuple2> _300_values = _source0.dtor_values; + DAST._IType _301_retType = _source0.dtor_retType; + DAST._IExpression _302_expr = _source0.dtor_expr; { - Dafny.ISequence> _321_paramNames; - _321_paramNames = Dafny.Sequence>.FromElements(); - Dafny.ISequence _322_paramFormals; - Dafny.ISequence _out266; - _out266 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_323_value) => { - return (_323_value).dtor__0; - })), _318_values), false); - _322_paramFormals = _out266; - Dafny.IMap,RAST._IType> _324_paramTypes; - _324_paramTypes = Dafny.Map, RAST._IType>.FromElements(); - Dafny.ISet> _325_paramNamesSet; - _325_paramNamesSet = Dafny.Set>.FromElements(); - BigInteger _hi12 = new BigInteger((_318_values).Count); - for (BigInteger _326_i = BigInteger.Zero; _326_i < _hi12; _326_i++) { - Dafny.ISequence _327_name; - _327_name = (((_318_values).Select(_326_i)).dtor__0).dtor_name; - Dafny.ISequence _328_rName; - _328_rName = Defs.__default.escapeVar(_327_name); - _321_paramNames = Dafny.Sequence>.Concat(_321_paramNames, Dafny.Sequence>.FromElements(_328_rName)); - _324_paramTypes = Dafny.Map, RAST._IType>.Update(_324_paramTypes, _328_rName, ((_322_paramFormals).Select(_326_i)).dtor_tpe); - _325_paramNamesSet = Dafny.Set>.Union(_325_paramNamesSet, Dafny.Set>.FromElements(_328_rName)); + Dafny.ISequence> _303_paramNames; + _303_paramNames = Dafny.Sequence>.FromElements(); + Dafny.ISequence _304_paramFormals; + Dafny.ISequence _out244; + _out244 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_305_value) => { + return (_305_value).dtor__0; + })), _300_values), false); + _304_paramFormals = _out244; + Dafny.IMap,RAST._IType> _306_paramTypes; + _306_paramTypes = Dafny.Map, RAST._IType>.FromElements(); + Dafny.ISet> _307_paramNamesSet; + _307_paramNamesSet = Dafny.Set>.FromElements(); + BigInteger _hi12 = new BigInteger((_300_values).Count); + for (BigInteger _308_i = BigInteger.Zero; _308_i < _hi12; _308_i++) { + Dafny.ISequence _309_name; + _309_name = (((_300_values).Select(_308_i)).dtor__0).dtor_name; + Dafny.ISequence _310_rName; + _310_rName = Defs.__default.escapeVar(_309_name); + _303_paramNames = Dafny.Sequence>.Concat(_303_paramNames, Dafny.Sequence>.FromElements(_310_rName)); + _306_paramTypes = Dafny.Map, RAST._IType>.Update(_306_paramTypes, _310_rName, ((_304_paramFormals).Select(_308_i)).dtor_tpe); + _307_paramNamesSet = Dafny.Set>.Union(_307_paramNamesSet, Dafny.Set>.FromElements(_310_rName)); } readIdents = Dafny.Set>.FromElements(); r = (this).InitEmptyExpr(); - BigInteger _hi13 = new BigInteger((_318_values).Count); - for (BigInteger _329_i = BigInteger.Zero; _329_i < _hi13; _329_i++) { - RAST._IType _330_typeGen; - RAST._IType _out267; - _out267 = (this).GenType((((_318_values).Select(_329_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); - _330_typeGen = _out267; - RAST._IExpr _331_valueGen; - Defs._IOwnership _332___v142; - Dafny.ISet> _333_recIdents; - RAST._IExpr _out268; - Defs._IOwnership _out269; - Dafny.ISet> _out270; - (this).GenExpr(((_318_values).Select(_329_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out268, out _out269, out _out270); - _331_valueGen = _out268; - _332___v142 = _out269; - _333_recIdents = _out270; - r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_318_values).Select(_329_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_330_typeGen), Std.Wrappers.Option.create_Some(_331_valueGen))); - readIdents = Dafny.Set>.Union(readIdents, _333_recIdents); - } - Defs._IEnvironment _334_newEnv; - _334_newEnv = Defs.Environment.create(_321_paramNames, _324_paramTypes); - RAST._IExpr _335_recGen; - Defs._IOwnership _336_recOwned; - Dafny.ISet> _337_recIdents; - RAST._IExpr _out271; - Defs._IOwnership _out272; - Dafny.ISet> _out273; - (this).GenExpr(_320_expr, selfIdent, _334_newEnv, expectedOwnership, out _out271, out _out272, out _out273); - _335_recGen = _out271; - _336_recOwned = _out272; - _337_recIdents = _out273; - readIdents = Dafny.Set>.Difference(_337_recIdents, _325_paramNamesSet); - r = RAST.Expr.create_Block((r).Then(_335_recGen)); - RAST._IExpr _out274; - Defs._IOwnership _out275; - (this).FromOwnership(r, _336_recOwned, expectedOwnership, out _out274, out _out275); - r = _out274; - resultingOwnership = _out275; + BigInteger _hi13 = new BigInteger((_300_values).Count); + for (BigInteger _311_i = BigInteger.Zero; _311_i < _hi13; _311_i++) { + RAST._IType _312_typeGen; + RAST._IType _out245; + _out245 = (this).GenType((((_300_values).Select(_311_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); + _312_typeGen = _out245; + RAST._IExpr _313_valueGen; + Defs._IOwnership _314___v128; + Dafny.ISet> _315_recIdents; + RAST._IExpr _out246; + Defs._IOwnership _out247; + Dafny.ISet> _out248; + (this).GenExpr(((_300_values).Select(_311_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out246, out _out247, out _out248); + _313_valueGen = _out246; + _314___v128 = _out247; + _315_recIdents = _out248; + r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_300_values).Select(_311_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_312_typeGen), Std.Wrappers.Option.create_Some(_313_valueGen))); + readIdents = Dafny.Set>.Union(readIdents, _315_recIdents); + } + Defs._IEnvironment _316_newEnv; + _316_newEnv = Defs.Environment.create(_303_paramNames, _306_paramTypes); + RAST._IExpr _317_recGen; + Defs._IOwnership _318_recOwned; + Dafny.ISet> _319_recIdents; + RAST._IExpr _out249; + Defs._IOwnership _out250; + Dafny.ISet> _out251; + (this).GenExpr(_302_expr, selfIdent, _316_newEnv, expectedOwnership, out _out249, out _out250, out _out251); + _317_recGen = _out249; + _318_recOwned = _out250; + _319_recIdents = _out251; + readIdents = Dafny.Set>.Difference(_319_recIdents, _307_paramNamesSet); + r = RAST.Expr.create_Block((r).Then(_317_recGen)); + RAST._IExpr _out252; + Defs._IOwnership _out253; + (this).FromOwnership(r, _318_recOwned, expectedOwnership, out _out252, out _out253); + r = _out252; + resultingOwnership = _out253; return ; } goto after_match0; @@ -6268,45 +6162,45 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IIFE) { - Dafny.ISequence _338_name = _source0.dtor_ident; - DAST._IType _339_tpe = _source0.dtor_typ; - DAST._IExpression _340_value = _source0.dtor_value; - DAST._IExpression _341_iifeBody = _source0.dtor_iifeBody; + Dafny.ISequence _320_name = _source0.dtor_ident; + DAST._IType _321_tpe = _source0.dtor_typ; + DAST._IExpression _322_value = _source0.dtor_value; + DAST._IExpression _323_iifeBody = _source0.dtor_iifeBody; { - RAST._IExpr _342_valueGen; - Defs._IOwnership _343___v143; - Dafny.ISet> _344_recIdents; - RAST._IExpr _out276; - Defs._IOwnership _out277; - Dafny.ISet> _out278; - (this).GenExpr(_340_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out276, out _out277, out _out278); - _342_valueGen = _out276; - _343___v143 = _out277; - _344_recIdents = _out278; - readIdents = _344_recIdents; - RAST._IType _345_valueTypeGen; - RAST._IType _out279; - _out279 = (this).GenType(_339_tpe, Defs.GenTypeContext.@default()); - _345_valueTypeGen = _out279; - Dafny.ISequence _346_iifeVar; - _346_iifeVar = Defs.__default.escapeVar(_338_name); - RAST._IExpr _347_bodyGen; - Defs._IOwnership _348___v144; - Dafny.ISet> _349_bodyIdents; - RAST._IExpr _out280; - Defs._IOwnership _out281; - Dafny.ISet> _out282; - (this).GenExpr(_341_iifeBody, selfIdent, (env).AddAssigned(_346_iifeVar, _345_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out280, out _out281, out _out282); - _347_bodyGen = _out280; - _348___v144 = _out281; - _349_bodyIdents = _out282; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_349_bodyIdents, Dafny.Set>.FromElements(_346_iifeVar))); - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _346_iifeVar, Std.Wrappers.Option.create_Some(_345_valueTypeGen), Std.Wrappers.Option.create_Some(_342_valueGen))).Then(_347_bodyGen)); - RAST._IExpr _out283; - Defs._IOwnership _out284; - (this).FromOwned(r, expectedOwnership, out _out283, out _out284); - r = _out283; - resultingOwnership = _out284; + RAST._IExpr _324_valueGen; + Defs._IOwnership _325___v129; + Dafny.ISet> _326_recIdents; + RAST._IExpr _out254; + Defs._IOwnership _out255; + Dafny.ISet> _out256; + (this).GenExpr(_322_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out254, out _out255, out _out256); + _324_valueGen = _out254; + _325___v129 = _out255; + _326_recIdents = _out256; + readIdents = _326_recIdents; + RAST._IType _327_valueTypeGen; + RAST._IType _out257; + _out257 = (this).GenType(_321_tpe, Defs.GenTypeContext.@default()); + _327_valueTypeGen = _out257; + Dafny.ISequence _328_iifeVar; + _328_iifeVar = Defs.__default.escapeVar(_320_name); + RAST._IExpr _329_bodyGen; + Defs._IOwnership _330___v130; + Dafny.ISet> _331_bodyIdents; + RAST._IExpr _out258; + Defs._IOwnership _out259; + Dafny.ISet> _out260; + (this).GenExpr(_323_iifeBody, selfIdent, (env).AddAssigned(_328_iifeVar, _327_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out258, out _out259, out _out260); + _329_bodyGen = _out258; + _330___v130 = _out259; + _331_bodyIdents = _out260; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_331_bodyIdents, Dafny.Set>.FromElements(_328_iifeVar))); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _328_iifeVar, Std.Wrappers.Option.create_Some(_327_valueTypeGen), Std.Wrappers.Option.create_Some(_324_valueGen))).Then(_329_bodyGen)); + RAST._IExpr _out261; + Defs._IOwnership _out262; + (this).FromOwned(r, expectedOwnership, out _out261, out _out262); + r = _out261; + resultingOwnership = _out262; return ; } goto after_match0; @@ -6314,43 +6208,43 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Apply) { - DAST._IExpression _350_func = _source0.dtor_expr; - Dafny.ISequence _351_args = _source0.dtor_args; + DAST._IExpression _332_func = _source0.dtor_expr; + Dafny.ISequence _333_args = _source0.dtor_args; { - RAST._IExpr _352_funcExpr; - Defs._IOwnership _353___v145; - Dafny.ISet> _354_recIdents; - RAST._IExpr _out285; - Defs._IOwnership _out286; - Dafny.ISet> _out287; - (this).GenExpr(_350_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out285, out _out286, out _out287); - _352_funcExpr = _out285; - _353___v145 = _out286; - _354_recIdents = _out287; - readIdents = _354_recIdents; - Dafny.ISequence _355_rArgs; - _355_rArgs = Dafny.Sequence.FromElements(); - BigInteger _hi14 = new BigInteger((_351_args).Count); - for (BigInteger _356_i = BigInteger.Zero; _356_i < _hi14; _356_i++) { - RAST._IExpr _357_argExpr; - Defs._IOwnership _358_argOwned; - Dafny.ISet> _359_argIdents; - RAST._IExpr _out288; - Defs._IOwnership _out289; - Dafny.ISet> _out290; - (this).GenExpr((_351_args).Select(_356_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out288, out _out289, out _out290); - _357_argExpr = _out288; - _358_argOwned = _out289; - _359_argIdents = _out290; - _355_rArgs = Dafny.Sequence.Concat(_355_rArgs, Dafny.Sequence.FromElements(_357_argExpr)); - readIdents = Dafny.Set>.Union(readIdents, _359_argIdents); - } - r = (_352_funcExpr).Apply(_355_rArgs); - RAST._IExpr _out291; - Defs._IOwnership _out292; - (this).FromOwned(r, expectedOwnership, out _out291, out _out292); - r = _out291; - resultingOwnership = _out292; + RAST._IExpr _334_funcExpr; + Defs._IOwnership _335___v131; + Dafny.ISet> _336_recIdents; + RAST._IExpr _out263; + Defs._IOwnership _out264; + Dafny.ISet> _out265; + (this).GenExpr(_332_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out263, out _out264, out _out265); + _334_funcExpr = _out263; + _335___v131 = _out264; + _336_recIdents = _out265; + readIdents = _336_recIdents; + Dafny.ISequence _337_rArgs; + _337_rArgs = Dafny.Sequence.FromElements(); + BigInteger _hi14 = new BigInteger((_333_args).Count); + for (BigInteger _338_i = BigInteger.Zero; _338_i < _hi14; _338_i++) { + RAST._IExpr _339_argExpr; + Defs._IOwnership _340_argOwned; + Dafny.ISet> _341_argIdents; + RAST._IExpr _out266; + Defs._IOwnership _out267; + Dafny.ISet> _out268; + (this).GenExpr((_333_args).Select(_338_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out266, out _out267, out _out268); + _339_argExpr = _out266; + _340_argOwned = _out267; + _341_argIdents = _out268; + _337_rArgs = Dafny.Sequence.Concat(_337_rArgs, Dafny.Sequence.FromElements(_339_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _341_argIdents); + } + r = (_334_funcExpr).Apply(_337_rArgs); + RAST._IExpr _out269; + Defs._IOwnership _out270; + (this).FromOwned(r, expectedOwnership, out _out269, out _out270); + r = _out269; + resultingOwnership = _out270; return ; } goto after_match0; @@ -6358,31 +6252,31 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TypeTest) { - DAST._IExpression _360_on = _source0.dtor_on; - Dafny.ISequence> _361_dType = _source0.dtor_dType; - Dafny.ISequence _362_variant = _source0.dtor_variant; + DAST._IExpression _342_on = _source0.dtor_on; + Dafny.ISequence> _343_dType = _source0.dtor_dType; + Dafny.ISequence _344_variant = _source0.dtor_variant; { - RAST._IExpr _363_exprGen; - Defs._IOwnership _364___v146; - Dafny.ISet> _365_recIdents; - RAST._IExpr _out293; - Defs._IOwnership _out294; - Dafny.ISet> _out295; - (this).GenExpr(_360_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out293, out _out294, out _out295); - _363_exprGen = _out293; - _364___v146 = _out294; - _365_recIdents = _out295; - RAST._IExpr _366_variantExprPath; - RAST._IExpr _out296; - _out296 = (this).GenPathExpr(Dafny.Sequence>.Concat(_361_dType, Dafny.Sequence>.FromElements(_362_variant)), true); - _366_variantExprPath = _out296; - r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_363_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _366_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); - RAST._IExpr _out297; - Defs._IOwnership _out298; - (this).FromOwned(r, expectedOwnership, out _out297, out _out298); - r = _out297; - resultingOwnership = _out298; - readIdents = _365_recIdents; + RAST._IExpr _345_exprGen; + Defs._IOwnership _346___v132; + Dafny.ISet> _347_recIdents; + RAST._IExpr _out271; + Defs._IOwnership _out272; + Dafny.ISet> _out273; + (this).GenExpr(_342_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out271, out _out272, out _out273); + _345_exprGen = _out271; + _346___v132 = _out272; + _347_recIdents = _out273; + RAST._IExpr _348_variantExprPath; + RAST._IExpr _out274; + _out274 = (this).GenPathExpr(Dafny.Sequence>.Concat(_343_dType, Dafny.Sequence>.FromElements(_344_variant)), true); + _348_variantExprPath = _out274; + r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_345_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _348_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); + RAST._IExpr _out275; + Defs._IOwnership _out276; + (this).FromOwned(r, expectedOwnership, out _out275, out _out276); + r = _out275; + resultingOwnership = _out276; + readIdents = _347_recIdents; return ; } goto after_match0; @@ -6390,42 +6284,42 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Is) { - DAST._IExpression _367_expr = _source0.dtor_expr; - DAST._IType _368_fromType = _source0.dtor_fromType; - DAST._IType _369_toType = _source0.dtor_toType; + DAST._IExpression _349_expr = _source0.dtor_expr; + DAST._IType _350_fromType = _source0.dtor_fromType; + DAST._IType _351_toType = _source0.dtor_toType; { - RAST._IExpr _370_expr; - Defs._IOwnership _371_recOwned; - Dafny.ISet> _372_recIdents; - RAST._IExpr _out299; - Defs._IOwnership _out300; - Dafny.ISet> _out301; - (this).GenExpr(_367_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out299, out _out300, out _out301); - _370_expr = _out299; - _371_recOwned = _out300; - _372_recIdents = _out301; - RAST._IType _373_fromType; - RAST._IType _out302; - _out302 = (this).GenType(_368_fromType, Defs.GenTypeContext.@default()); - _373_fromType = _out302; - RAST._IType _374_toType; - RAST._IType _out303; - _out303 = (this).GenType(_369_toType, Defs.GenTypeContext.@default()); - _374_toType = _out303; - if (((_373_fromType).IsObjectOrPointer()) && ((_374_toType).IsObjectOrPointer())) { - r = (((_370_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_374_toType).ObjectOrPointerUnderlying()))).Apply0(); + RAST._IExpr _352_expr; + Defs._IOwnership _353_recOwned; + Dafny.ISet> _354_recIdents; + RAST._IExpr _out277; + Defs._IOwnership _out278; + Dafny.ISet> _out279; + (this).GenExpr(_349_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out277, out _out278, out _out279); + _352_expr = _out277; + _353_recOwned = _out278; + _354_recIdents = _out279; + RAST._IType _355_fromType; + RAST._IType _out280; + _out280 = (this).GenType(_350_fromType, Defs.GenTypeContext.@default()); + _355_fromType = _out280; + RAST._IType _356_toType; + RAST._IType _out281; + _out281 = (this).GenType(_351_toType, Defs.GenTypeContext.@default()); + _356_toType = _out281; + if (((_355_fromType).IsObjectOrPointer()) && ((_356_toType).IsObjectOrPointer())) { + r = (((_352_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_356_toType).ObjectOrPointerUnderlying()))).Apply0(); } else { - RAST._IExpr _out304; - _out304 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object or Ptr"), (this).InitEmptyExpr()); - r = _out304; + RAST._IExpr _out282; + _out282 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object or Ptr"), (this).InitEmptyExpr()); + r = _out282; readIdents = Dafny.Set>.FromElements(); } - RAST._IExpr _out305; - Defs._IOwnership _out306; - (this).FromOwnership(r, _371_recOwned, expectedOwnership, out _out305, out _out306); - r = _out305; - resultingOwnership = _out306; - readIdents = _372_recIdents; + RAST._IExpr _out283; + Defs._IOwnership _out284; + (this).FromOwnership(r, _353_recOwned, expectedOwnership, out _out283, out _out284); + r = _out283; + resultingOwnership = _out284; + readIdents = _354_recIdents; return ; } goto after_match0; @@ -6435,11 +6329,11 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_BoolBoundedPool) { { r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("[false, true]")); - RAST._IExpr _out307; - Defs._IOwnership _out308; - (this).FromOwned(r, expectedOwnership, out _out307, out _out308); - r = _out307; - resultingOwnership = _out308; + RAST._IExpr _out285; + Defs._IOwnership _out286; + (this).FromOwned(r, expectedOwnership, out _out285, out _out286); + r = _out285; + resultingOwnership = _out286; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6448,25 +6342,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBoundedPool) { - DAST._IExpression _375_of = _source0.dtor_of; + DAST._IExpression _357_of = _source0.dtor_of; { - RAST._IExpr _376_exprGen; - Defs._IOwnership _377___v147; - Dafny.ISet> _378_recIdents; - RAST._IExpr _out309; - Defs._IOwnership _out310; - Dafny.ISet> _out311; - (this).GenExpr(_375_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out309, out _out310, out _out311); - _376_exprGen = _out309; - _377___v147 = _out310; - _378_recIdents = _out311; - r = ((_376_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - RAST._IExpr _out312; - Defs._IOwnership _out313; - (this).FromOwned(r, expectedOwnership, out _out312, out _out313); - r = _out312; - resultingOwnership = _out313; - readIdents = _378_recIdents; + RAST._IExpr _358_exprGen; + Defs._IOwnership _359___v133; + Dafny.ISet> _360_recIdents; + RAST._IExpr _out287; + Defs._IOwnership _out288; + Dafny.ISet> _out289; + (this).GenExpr(_357_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out287, out _out288, out _out289); + _358_exprGen = _out287; + _359___v133 = _out288; + _360_recIdents = _out289; + r = ((_358_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + RAST._IExpr _out290; + Defs._IOwnership _out291; + (this).FromOwned(r, expectedOwnership, out _out290, out _out291); + r = _out290; + resultingOwnership = _out291; + readIdents = _360_recIdents; return ; } goto after_match0; @@ -6474,29 +6368,29 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SeqBoundedPool) { - DAST._IExpression _379_of = _source0.dtor_of; - bool _380_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _361_of = _source0.dtor_of; + bool _362_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _381_exprGen; - Defs._IOwnership _382___v148; - Dafny.ISet> _383_recIdents; - RAST._IExpr _out314; - Defs._IOwnership _out315; - Dafny.ISet> _out316; - (this).GenExpr(_379_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out314, out _out315, out _out316); - _381_exprGen = _out314; - _382___v148 = _out315; - _383_recIdents = _out316; - r = ((_381_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_380_includeDuplicates)) { + RAST._IExpr _363_exprGen; + Defs._IOwnership _364___v134; + Dafny.ISet> _365_recIdents; + RAST._IExpr _out292; + Defs._IOwnership _out293; + Dafny.ISet> _out294; + (this).GenExpr(_361_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out292, out _out293, out _out294); + _363_exprGen = _out292; + _364___v134 = _out293; + _365_recIdents = _out294; + r = ((_363_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_362_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } - RAST._IExpr _out317; - Defs._IOwnership _out318; - (this).FromOwned(r, expectedOwnership, out _out317, out _out318); - r = _out317; - resultingOwnership = _out318; - readIdents = _383_recIdents; + RAST._IExpr _out295; + Defs._IOwnership _out296; + (this).FromOwned(r, expectedOwnership, out _out295, out _out296); + r = _out295; + resultingOwnership = _out296; + readIdents = _365_recIdents; return ; } goto after_match0; @@ -6504,29 +6398,29 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MultisetBoundedPool) { - DAST._IExpression _384_of = _source0.dtor_of; - bool _385_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _366_of = _source0.dtor_of; + bool _367_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _386_exprGen; - Defs._IOwnership _387___v149; - Dafny.ISet> _388_recIdents; - RAST._IExpr _out319; - Defs._IOwnership _out320; - Dafny.ISet> _out321; - (this).GenExpr(_384_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out319, out _out320, out _out321); - _386_exprGen = _out319; - _387___v149 = _out320; - _388_recIdents = _out321; - r = ((_386_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_385_includeDuplicates)) { + RAST._IExpr _368_exprGen; + Defs._IOwnership _369___v135; + Dafny.ISet> _370_recIdents; + RAST._IExpr _out297; + Defs._IOwnership _out298; + Dafny.ISet> _out299; + (this).GenExpr(_366_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out297, out _out298, out _out299); + _368_exprGen = _out297; + _369___v135 = _out298; + _370_recIdents = _out299; + r = ((_368_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_367_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } - RAST._IExpr _out322; - Defs._IOwnership _out323; - (this).FromOwned(r, expectedOwnership, out _out322, out _out323); - r = _out322; - resultingOwnership = _out323; - readIdents = _388_recIdents; + RAST._IExpr _out300; + Defs._IOwnership _out301; + (this).FromOwned(r, expectedOwnership, out _out300, out _out301); + r = _out300; + resultingOwnership = _out301; + readIdents = _370_recIdents; return ; } goto after_match0; @@ -6534,99 +6428,99 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBoundedPool) { - DAST._IExpression _389_of = _source0.dtor_of; + DAST._IExpression _371_of = _source0.dtor_of; { - RAST._IExpr _390_exprGen; - Defs._IOwnership _391___v150; - Dafny.ISet> _392_recIdents; - RAST._IExpr _out324; - Defs._IOwnership _out325; - Dafny.ISet> _out326; - (this).GenExpr(_389_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out324, out _out325, out _out326); - _390_exprGen = _out324; - _391___v150 = _out325; - _392_recIdents = _out326; - r = ((((_390_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - readIdents = _392_recIdents; - RAST._IExpr _out327; - Defs._IOwnership _out328; - (this).FromOwned(r, expectedOwnership, out _out327, out _out328); - r = _out327; - resultingOwnership = _out328; + RAST._IExpr _372_exprGen; + Defs._IOwnership _373___v136; + Dafny.ISet> _374_recIdents; + RAST._IExpr _out302; + Defs._IOwnership _out303; + Dafny.ISet> _out304; + (this).GenExpr(_371_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); + _372_exprGen = _out302; + _373___v136 = _out303; + _374_recIdents = _out304; + r = ((((_372_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + readIdents = _374_recIdents; + RAST._IExpr _out305; + Defs._IOwnership _out306; + (this).FromOwned(r, expectedOwnership, out _out305, out _out306); + r = _out305; + resultingOwnership = _out306; } goto after_match0; } } { if (_source0.is_ExactBoundedPool) { - DAST._IExpression _393_of = _source0.dtor_of; + DAST._IExpression _375_of = _source0.dtor_of; { - RAST._IExpr _394_exprGen; - Defs._IOwnership _395___v151; - Dafny.ISet> _396_recIdents; - RAST._IExpr _out329; - Defs._IOwnership _out330; - Dafny.ISet> _out331; - (this).GenExpr(_393_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out329, out _out330, out _out331); - _394_exprGen = _out329; - _395___v151 = _out330; - _396_recIdents = _out331; - r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_394_exprGen); - readIdents = _396_recIdents; - RAST._IExpr _out332; - Defs._IOwnership _out333; - (this).FromOwned(r, expectedOwnership, out _out332, out _out333); - r = _out332; - resultingOwnership = _out333; + RAST._IExpr _376_exprGen; + Defs._IOwnership _377___v137; + Dafny.ISet> _378_recIdents; + RAST._IExpr _out307; + Defs._IOwnership _out308; + Dafny.ISet> _out309; + (this).GenExpr(_375_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out307, out _out308, out _out309); + _376_exprGen = _out307; + _377___v137 = _out308; + _378_recIdents = _out309; + r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_376_exprGen); + readIdents = _378_recIdents; + RAST._IExpr _out310; + Defs._IOwnership _out311; + (this).FromOwned(r, expectedOwnership, out _out310, out _out311); + r = _out310; + resultingOwnership = _out311; } goto after_match0; } } { if (_source0.is_IntRange) { - DAST._IType _397_typ = _source0.dtor_elemType; - DAST._IExpression _398_lo = _source0.dtor_lo; - DAST._IExpression _399_hi = _source0.dtor_hi; - bool _400_up = _source0.dtor_up; + DAST._IType _379_typ = _source0.dtor_elemType; + DAST._IExpression _380_lo = _source0.dtor_lo; + DAST._IExpression _381_hi = _source0.dtor_hi; + bool _382_up = _source0.dtor_up; { - RAST._IExpr _401_lo; - Defs._IOwnership _402___v152; - Dafny.ISet> _403_recIdentsLo; - RAST._IExpr _out334; - Defs._IOwnership _out335; - Dafny.ISet> _out336; - (this).GenExpr(_398_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); - _401_lo = _out334; - _402___v152 = _out335; - _403_recIdentsLo = _out336; - RAST._IExpr _404_hi; - Defs._IOwnership _405___v153; - Dafny.ISet> _406_recIdentsHi; - RAST._IExpr _out337; - Defs._IOwnership _out338; - Dafny.ISet> _out339; - (this).GenExpr(_399_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); - _404_hi = _out337; - _405___v153 = _out338; - _406_recIdentsHi = _out339; - if (_400_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_401_lo, _404_hi)); + RAST._IExpr _383_lo; + Defs._IOwnership _384___v138; + Dafny.ISet> _385_recIdentsLo; + RAST._IExpr _out312; + Defs._IOwnership _out313; + Dafny.ISet> _out314; + (this).GenExpr(_380_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out312, out _out313, out _out314); + _383_lo = _out312; + _384___v138 = _out313; + _385_recIdentsLo = _out314; + RAST._IExpr _386_hi; + Defs._IOwnership _387___v139; + Dafny.ISet> _388_recIdentsHi; + RAST._IExpr _out315; + Defs._IOwnership _out316; + Dafny.ISet> _out317; + (this).GenExpr(_381_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out315, out _out316, out _out317); + _386_hi = _out315; + _387___v139 = _out316; + _388_recIdentsHi = _out317; + if (_382_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_383_lo, _386_hi)); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_404_hi, _401_lo)); - } - if (!((_397_typ).is_Primitive)) { - RAST._IType _407_tpe; - RAST._IType _out340; - _out340 = (this).GenType(_397_typ, Defs.GenTypeContext.@default()); - _407_tpe = _out340; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_407_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); - } - RAST._IExpr _out341; - Defs._IOwnership _out342; - (this).FromOwned(r, expectedOwnership, out _out341, out _out342); - r = _out341; - resultingOwnership = _out342; - readIdents = Dafny.Set>.Union(_403_recIdentsLo, _406_recIdentsHi); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_386_hi, _383_lo)); + } + if (!((_379_typ).is_Primitive)) { + RAST._IType _389_tpe; + RAST._IType _out318; + _out318 = (this).GenType(_379_typ, Defs.GenTypeContext.@default()); + _389_tpe = _out318; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_389_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); + } + RAST._IExpr _out319; + Defs._IOwnership _out320; + (this).FromOwned(r, expectedOwnership, out _out319, out _out320); + r = _out319; + resultingOwnership = _out320; + readIdents = Dafny.Set>.Union(_385_recIdentsLo, _388_recIdentsHi); return ; } goto after_match0; @@ -6634,30 +6528,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_UnboundedIntRange) { - DAST._IExpression _408_start = _source0.dtor_start; - bool _409_up = _source0.dtor_up; + DAST._IExpression _390_start = _source0.dtor_start; + bool _391_up = _source0.dtor_up; { - RAST._IExpr _410_start; - Defs._IOwnership _411___v154; - Dafny.ISet> _412_recIdentStart; - RAST._IExpr _out343; - Defs._IOwnership _out344; - Dafny.ISet> _out345; - (this).GenExpr(_408_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out343, out _out344, out _out345); - _410_start = _out343; - _411___v154 = _out344; - _412_recIdentStart = _out345; - if (_409_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_410_start); + RAST._IExpr _392_start; + Defs._IOwnership _393___v140; + Dafny.ISet> _394_recIdentStart; + RAST._IExpr _out321; + Defs._IOwnership _out322; + Dafny.ISet> _out323; + (this).GenExpr(_390_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out321, out _out322, out _out323); + _392_start = _out321; + _393___v140 = _out322; + _394_recIdentStart = _out323; + if (_391_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_392_start); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_410_start); - } - RAST._IExpr _out346; - Defs._IOwnership _out347; - (this).FromOwned(r, expectedOwnership, out _out346, out _out347); - r = _out346; - resultingOwnership = _out347; - readIdents = _412_recIdentStart; + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_392_start); + } + RAST._IExpr _out324; + Defs._IOwnership _out325; + (this).FromOwned(r, expectedOwnership, out _out324, out _out325); + r = _out324; + resultingOwnership = _out325; + readIdents = _394_recIdentStart; return ; } goto after_match0; @@ -6665,23 +6559,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBuilder) { - DAST._IType _413_keyType = _source0.dtor_keyType; - DAST._IType _414_valueType = _source0.dtor_valueType; + DAST._IType _395_keyType = _source0.dtor_keyType; + DAST._IType _396_valueType = _source0.dtor_valueType; { - RAST._IType _415_kType; - RAST._IType _out348; - _out348 = (this).GenType(_413_keyType, Defs.GenTypeContext.@default()); - _415_kType = _out348; - RAST._IType _416_vType; - RAST._IType _out349; - _out349 = (this).GenType(_414_valueType, Defs.GenTypeContext.@default()); - _416_vType = _out349; - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_415_kType, _416_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out350; - Defs._IOwnership _out351; - (this).FromOwned(r, expectedOwnership, out _out350, out _out351); - r = _out350; - resultingOwnership = _out351; + RAST._IType _397_kType; + RAST._IType _out326; + _out326 = (this).GenType(_395_keyType, Defs.GenTypeContext.@default()); + _397_kType = _out326; + RAST._IType _398_vType; + RAST._IType _out327; + _out327 = (this).GenType(_396_valueType, Defs.GenTypeContext.@default()); + _398_vType = _out327; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_397_kType, _398_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out328; + Defs._IOwnership _out329; + (this).FromOwned(r, expectedOwnership, out _out328, out _out329); + r = _out328; + resultingOwnership = _out329; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6690,93 +6584,93 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBuilder) { - DAST._IType _417_elemType = _source0.dtor_elemType; + DAST._IType _399_elemType = _source0.dtor_elemType; { - RAST._IType _418_eType; - RAST._IType _out352; - _out352 = (this).GenType(_417_elemType, Defs.GenTypeContext.@default()); - _418_eType = _out352; + RAST._IType _400_eType; + RAST._IType _out330; + _out330 = (this).GenType(_399_elemType, Defs.GenTypeContext.@default()); + _400_eType = _out330; readIdents = Dafny.Set>.FromElements(); - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_418_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out353; - Defs._IOwnership _out354; - (this).FromOwned(r, expectedOwnership, out _out353, out _out354); - r = _out353; - resultingOwnership = _out354; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_400_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out331; + Defs._IOwnership _out332; + (this).FromOwned(r, expectedOwnership, out _out331, out _out332); + r = _out331; + resultingOwnership = _out332; return ; } goto after_match0; } } { - DAST._IType _419_elemType = _source0.dtor_elemType; - DAST._IExpression _420_collection = _source0.dtor_collection; - bool _421_is__forall = _source0.dtor_is__forall; - DAST._IExpression _422_lambda = _source0.dtor_lambda; + DAST._IType _401_elemType = _source0.dtor_elemType; + DAST._IExpression _402_collection = _source0.dtor_collection; + bool _403_is__forall = _source0.dtor_is__forall; + DAST._IExpression _404_lambda = _source0.dtor_lambda; { - RAST._IType _423_tpe; - RAST._IType _out355; - _out355 = (this).GenType(_419_elemType, Defs.GenTypeContext.@default()); - _423_tpe = _out355; - RAST._IExpr _424_collectionGen; - Defs._IOwnership _425___v155; - Dafny.ISet> _426_recIdents; - RAST._IExpr _out356; - Defs._IOwnership _out357; - Dafny.ISet> _out358; - (this).GenExpr(_420_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out356, out _out357, out _out358); - _424_collectionGen = _out356; - _425___v155 = _out357; - _426_recIdents = _out358; - Dafny.ISequence _427_extraAttributes; - _427_extraAttributes = Dafny.Sequence.FromElements(); - if ((((((_420_collection).is_IntRange) || ((_420_collection).is_UnboundedIntRange)) || ((_420_collection).is_SeqBoundedPool)) || ((_420_collection).is_ExactBoundedPool)) || ((_420_collection).is_MultisetBoundedPool)) { - _427_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); - } - if ((_422_lambda).is_Lambda) { - Dafny.ISequence _428_formals; - _428_formals = (_422_lambda).dtor_params; - Dafny.ISequence _429_newFormals; - _429_newFormals = Dafny.Sequence.FromElements(); - BigInteger _hi15 = new BigInteger((_428_formals).Count); - for (BigInteger _430_i = BigInteger.Zero; _430_i < _hi15; _430_i++) { - var _pat_let_tv0 = _427_extraAttributes; - var _pat_let_tv1 = _428_formals; - _429_newFormals = Dafny.Sequence.Concat(_429_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_428_formals).Select(_430_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _431_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_430_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _432_dt__update_hattributes_h0 => DAST.Formal.create((_431_dt__update__tmp_h0).dtor_name, (_431_dt__update__tmp_h0).dtor_typ, _432_dt__update_hattributes_h0))))))); - } - DAST._IExpression _433_newLambda; - DAST._IExpression _434_dt__update__tmp_h1 = _422_lambda; - Dafny.ISequence _435_dt__update_hparams_h0 = _429_newFormals; - _433_newLambda = DAST.Expression.create_Lambda(_435_dt__update_hparams_h0, (_434_dt__update__tmp_h1).dtor_retType, (_434_dt__update__tmp_h1).dtor_body); - RAST._IExpr _436_lambdaGen; - Defs._IOwnership _437___v156; - Dafny.ISet> _438_recLambdaIdents; - RAST._IExpr _out359; - Defs._IOwnership _out360; - Dafny.ISet> _out361; - (this).GenExpr(_433_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out359, out _out360, out _out361); - _436_lambdaGen = _out359; - _437___v156 = _out360; - _438_recLambdaIdents = _out361; - Dafny.ISequence _439_fn; - if (_421_is__forall) { - _439_fn = Dafny.Sequence.UnicodeFromString("all"); + RAST._IType _405_tpe; + RAST._IType _out333; + _out333 = (this).GenType(_401_elemType, Defs.GenTypeContext.@default()); + _405_tpe = _out333; + RAST._IExpr _406_collectionGen; + Defs._IOwnership _407___v141; + Dafny.ISet> _408_recIdents; + RAST._IExpr _out334; + Defs._IOwnership _out335; + Dafny.ISet> _out336; + (this).GenExpr(_402_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); + _406_collectionGen = _out334; + _407___v141 = _out335; + _408_recIdents = _out336; + Dafny.ISequence _409_extraAttributes; + _409_extraAttributes = Dafny.Sequence.FromElements(); + if ((((((_402_collection).is_IntRange) || ((_402_collection).is_UnboundedIntRange)) || ((_402_collection).is_SeqBoundedPool)) || ((_402_collection).is_ExactBoundedPool)) || ((_402_collection).is_MultisetBoundedPool)) { + _409_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); + } + if ((_404_lambda).is_Lambda) { + Dafny.ISequence _410_formals; + _410_formals = (_404_lambda).dtor_params; + Dafny.ISequence _411_newFormals; + _411_newFormals = Dafny.Sequence.FromElements(); + BigInteger _hi15 = new BigInteger((_410_formals).Count); + for (BigInteger _412_i = BigInteger.Zero; _412_i < _hi15; _412_i++) { + var _pat_let_tv0 = _409_extraAttributes; + var _pat_let_tv1 = _410_formals; + _411_newFormals = Dafny.Sequence.Concat(_411_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_410_formals).Select(_412_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _413_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_412_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _414_dt__update_hattributes_h0 => DAST.Formal.create((_413_dt__update__tmp_h0).dtor_name, (_413_dt__update__tmp_h0).dtor_typ, _414_dt__update_hattributes_h0))))))); + } + DAST._IExpression _415_newLambda; + DAST._IExpression _416_dt__update__tmp_h1 = _404_lambda; + Dafny.ISequence _417_dt__update_hparams_h0 = _411_newFormals; + _415_newLambda = DAST.Expression.create_Lambda(_417_dt__update_hparams_h0, (_416_dt__update__tmp_h1).dtor_retType, (_416_dt__update__tmp_h1).dtor_body); + RAST._IExpr _418_lambdaGen; + Defs._IOwnership _419___v142; + Dafny.ISet> _420_recLambdaIdents; + RAST._IExpr _out337; + Defs._IOwnership _out338; + Dafny.ISet> _out339; + (this).GenExpr(_415_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); + _418_lambdaGen = _out337; + _419___v142 = _out338; + _420_recLambdaIdents = _out339; + Dafny.ISequence _421_fn; + if (_403_is__forall) { + _421_fn = Dafny.Sequence.UnicodeFromString("all"); } else { - _439_fn = Dafny.Sequence.UnicodeFromString("any"); + _421_fn = Dafny.Sequence.UnicodeFromString("any"); } - r = ((_424_collectionGen).Sel(_439_fn)).Apply1(((_436_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); - readIdents = Dafny.Set>.Union(_426_recIdents, _438_recLambdaIdents); + r = ((_406_collectionGen).Sel(_421_fn)).Apply1(((_418_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); + readIdents = Dafny.Set>.Union(_408_recIdents, _420_recLambdaIdents); } else { - RAST._IExpr _out362; - _out362 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); - r = _out362; + RAST._IExpr _out340; + _out340 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); + r = _out340; readIdents = Dafny.Set>.FromElements(); } - RAST._IExpr _out363; - Defs._IOwnership _out364; - (this).FromOwned(r, expectedOwnership, out _out363, out _out364); - r = _out363; - resultingOwnership = _out364; + RAST._IExpr _out341; + Defs._IOwnership _out342; + (this).FromOwned(r, expectedOwnership, out _out341, out _out342); + r = _out341; + resultingOwnership = _out342; } } after_match0: ; @@ -6863,15 +6757,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v157; - Dafny.ISet> _2___v158; + Defs._IOwnership _1___v143; + Dafny.ISet> _2___v144; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v157 = _out1; - _2___v158 = _out2; + _1___v143 = _out1; + _2___v144 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index 6d2e2f3c392..fc267756b73 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -3976,36 +3976,6 @@ macro_rules! UpcastObjectFn { }; } -// This is for Box or traits -#[macro_export] -macro_rules! UpcastBoxFn { - (dyn $trait_name:path, $($type_args:ty),*) => { - fn upcast(&self) -> ::std::boxed::Box)> { - $trait_name::<$($type_args), *>::_clone(self.as_ref()) - } - }; - (dyn $trait_name:path) => { - fn upcast(&self) -> ::std::boxed::Box { - $trait_name::_clone(self.as_ref()) - } - }; -} - -// This is for datatypes -#[macro_export] -macro_rules! UpcastStructBoxFn { - (dyn $trait_name:ident<$($type_args:ty),*>) => { - fn upcast(&self) -> ::std::boxed::Box> { - $trait_name::<$($type_args), *>::_clone(self) - } - }; - (dyn $trait_name:ident) => { - fn upcast(&self) -> ::std::boxed::Box { - $trait_name::_clone(self) - } - }; -} - // It works only when there is no type parameters for $A... #[macro_export] macro_rules! UpcastDef { diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index f9296bf2806..6f04042bd62 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -992,10 +992,14 @@ mod tests { } } impl UpcastBox for ADatatype { - UpcastStructBoxFn!(dyn GeneralTrait); + fn upcast(&self) -> ::std::boxed::Box { + GeneralTrait::_clone(self) + } } impl UpcastBox> for ADatatype { - UpcastStructBoxFn!(dyn GeneralTraitSuper); + fn upcast(&self) -> ::std::boxed::Box> { + GeneralTraitSuper::::_clone(self) + } } #[test] fn test_general_traits() { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy index 82cdcc341f7..0dace953dd9 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy @@ -10,6 +10,13 @@ trait DatatypeOps { function ChooseAmong(a: T, b: T): T { if GetBool() then a else b } + method ChooseAmongMethod(a: T, b: T) returns (c: T) { + if GetBool() { + return a; + } else { + c := b; + } + } } datatype {:rust_rc false} ADatatype extends DatatypeOps = ADatatype(i: int) { @@ -24,17 +31,25 @@ method Main() { expect x.GetInt() == 2; expect x.GetBool() == true; expect x.ChooseAmong(8, 9) == 8; + var xm := x.ChooseAmongMethod(8, 9); + expect xm == 8; var y := ADatatype(3); expect y.GetInt() == 3; expect y.GetBool() == false; - expect x.ChooseAmong(8, 9) == 9; + expect y.ChooseAmong(8, 9) == 9; + var ym := y.ChooseAmongMethod(8, 9); + expect ym == 9; var x1 := x.AsDatatypeOps(); // Dynamic dispatch now. expect x1.GetInt() == 2; expect x1.GetBool() == true; expect x1.ChooseAmong(8, 9) == 8; + var x1m := x1.ChooseAmongMethod(8, 9); + expect x1m == 8; var y1 := y.AsDatatypeOps(); expect y1.GetInt() == 3; expect y1.GetBool() == false; expect y1.ChooseAmong(8, 9) == 9; + var y1m := y1.ChooseAmongMethod(8, 9); + expect y1m == 9; print "Main passed all the tests"; } \ No newline at end of file From 596a0d182da557893c0c2d53a79f6950c6669b99 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 29 Nov 2024 14:55:25 +0100 Subject: [PATCH 09/69] Fixed CI tests --- .../LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect | 4 ++-- .../TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect index 2123d1f24c3..f896bad9217 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect @@ -1,3 +1,3 @@ -Dafny program verifier finished with 20 verified, 0 errors -Main passed all the tests +Dafny program verifier finished with 4 verified, 0 errors +Main passed all the tests \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect index 2123d1f24c3..506e5ca1d4c 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect @@ -1,3 +1,3 @@ -Dafny program verifier finished with 20 verified, 0 errors +Dafny program verifier finished with 21 verified, 0 errors Main passed all the tests From 4602d323af2445226196952137244a0d1fd5d62d Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 29 Nov 2024 16:17:26 +0100 Subject: [PATCH 10/69] Fixed proofs --- Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 0f9a4bb0214..ae3644fb849 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -1874,7 +1874,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } + @IsolateAssertions @ResourceLimit("1e6") method GenOwnedCallPart(ghost e: Expression, on: Expression, selfIdent: SelfInfo, name: CallName, typeArgs: seq, args: seq, env: Environment) returns (r: R.Expr, readIdents: set) + requires forall a <- args :: a < e + requires on < e modifies this decreases e, 1, 1 { @@ -2125,7 +2128,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { newEnv := env; } case Call(on, name, typeArgs, args, maybeOutVars) => { - assume {:axiom} (if |args| > 0 then args[0] else Expression.Tuple([])) < stmt; + assume {:axiom} Expression.Call(on, name, typeArgs, args) < stmt; generated, readIdents := GenOwnedCallPart(Expression.Call(on, name, typeArgs, args), on, selfIdent, name, typeArgs, args, env); if maybeOutVars.Some? && |maybeOutVars.value| == 1 { @@ -3057,6 +3060,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { argOwnership := OwnershipOwned; } } + assert args[i] in args; var argExpr, _, argIdents := GenExpr(args[i], selfIdent, env, argOwnership); argExprs := argExprs + [argExpr]; readIdents := readIdents + argIdents; From 31da8a2d9fa355a27cff384d8be8620cebe0d338 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 29 Nov 2024 17:03:28 +0100 Subject: [PATCH 11/69] Update rust module --- .../DafnyRuntimeRust/src/system/mod.rs | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs index d30d8671ec0..c530be0a578 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs @@ -104,8 +104,8 @@ pub mod _System { } impl AsRef> - for &Tuple2 { - fn as_ref(&self) -> Self { + for Tuple2 { + fn as_ref(&self) -> &Self { self } } @@ -164,8 +164,8 @@ pub mod _System { } impl AsRef - for &Tuple0 { - fn as_ref(&self) -> Self { + for Tuple0 { + fn as_ref(&self) -> &Self { self } } @@ -244,8 +244,8 @@ pub mod _System { } impl AsRef> - for &Tuple1 { - fn as_ref(&self) -> Self { + for Tuple1 { + fn as_ref(&self) -> &Self { self } } @@ -346,8 +346,8 @@ pub mod _System { } impl AsRef> - for &Tuple3 { - fn as_ref(&self) -> Self { + for Tuple3 { + fn as_ref(&self) -> &Self { self } } @@ -459,8 +459,8 @@ pub mod _System { } impl AsRef> - for &Tuple4 { - fn as_ref(&self) -> Self { + for Tuple4 { + fn as_ref(&self) -> &Self { self } } @@ -583,8 +583,8 @@ pub mod _System { } impl AsRef> - for &Tuple5 { - fn as_ref(&self) -> Self { + for Tuple5 { + fn as_ref(&self) -> &Self { self } } @@ -718,8 +718,8 @@ pub mod _System { } impl AsRef> - for &Tuple6 { - fn as_ref(&self) -> Self { + for Tuple6 { + fn as_ref(&self) -> &Self { self } } @@ -864,8 +864,8 @@ pub mod _System { } impl AsRef> - for &Tuple7 { - fn as_ref(&self) -> Self { + for Tuple7 { + fn as_ref(&self) -> &Self { self } } @@ -1021,8 +1021,8 @@ pub mod _System { } impl AsRef> - for &Tuple8 { - fn as_ref(&self) -> Self { + for Tuple8 { + fn as_ref(&self) -> &Self { self } } @@ -1189,8 +1189,8 @@ pub mod _System { } impl AsRef> - for &Tuple9 { - fn as_ref(&self) -> Self { + for Tuple9 { + fn as_ref(&self) -> &Self { self } } @@ -1368,8 +1368,8 @@ pub mod _System { } impl AsRef> - for &Tuple10 { - fn as_ref(&self) -> Self { + for Tuple10 { + fn as_ref(&self) -> &Self { self } } @@ -1558,8 +1558,8 @@ pub mod _System { } impl AsRef> - for &Tuple11 { - fn as_ref(&self) -> Self { + for Tuple11 { + fn as_ref(&self) -> &Self { self } } @@ -1759,8 +1759,8 @@ pub mod _System { } impl AsRef> - for &Tuple12 { - fn as_ref(&self) -> Self { + for Tuple12 { + fn as_ref(&self) -> &Self { self } } @@ -1971,8 +1971,8 @@ pub mod _System { } impl AsRef> - for &Tuple13 { - fn as_ref(&self) -> Self { + for Tuple13 { + fn as_ref(&self) -> &Self { self } } @@ -2194,8 +2194,8 @@ pub mod _System { } impl AsRef> - for &Tuple14 { - fn as_ref(&self) -> Self { + for Tuple14 { + fn as_ref(&self) -> &Self { self } } @@ -2428,8 +2428,8 @@ pub mod _System { } impl AsRef> - for &Tuple15 { - fn as_ref(&self) -> Self { + for Tuple15 { + fn as_ref(&self) -> &Self { self } } @@ -2673,8 +2673,8 @@ pub mod _System { } impl AsRef> - for &Tuple16 { - fn as_ref(&self) -> Self { + for Tuple16 { + fn as_ref(&self) -> &Self { self } } @@ -2929,8 +2929,8 @@ pub mod _System { } impl AsRef> - for &Tuple17 { - fn as_ref(&self) -> Self { + for Tuple17 { + fn as_ref(&self) -> &Self { self } } @@ -3196,8 +3196,8 @@ pub mod _System { } impl AsRef> - for &Tuple18 { - fn as_ref(&self) -> Self { + for Tuple18 { + fn as_ref(&self) -> &Self { self } } @@ -3474,8 +3474,8 @@ pub mod _System { } impl AsRef> - for &Tuple19 { - fn as_ref(&self) -> Self { + for Tuple19 { + fn as_ref(&self) -> &Self { self } } @@ -3763,8 +3763,8 @@ pub mod _System { } impl AsRef> - for &Tuple20 { - fn as_ref(&self) -> Self { + for Tuple20 { + fn as_ref(&self) -> &Self { self } } From bc366216814d177c9e9204023ec5486710c532fe Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Sat, 30 Nov 2024 02:39:29 +0100 Subject: [PATCH 12/69] All changes --- .../Backends/Dafny/DafnyCodeGenerator.cs | 17 +- .../Rust/Dafny-compiler-rust-rast.dfy | 29 ++ .../Backends/Rust/Dafny-compiler-rust.dfy | 35 +- .../SinglePassCodeGenerator.cs | 13 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 437 ++++++++++-------- Source/DafnyCore/GeneratedFromDafny/RAST.cs | 93 ++++ .../LitTest/comp/rust/traits-datatypes.dfy | 10 +- 7 files changed, 414 insertions(+), 220 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 3b01e93706a..15e8454a3ce 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -22,7 +22,12 @@ class DafnyCodeGenerator : SinglePassCodeGenerator { public string internalFieldPrefix; public bool preventShadowing; - protected override bool InstanceMethodsAllowedToCallTraitMethods => false; + // In a language like Rust, trait methods with bodies don't need to be called by + // the class or datatype extending it with overriding functions or methods that call into the trait. + // However, if a method is declared in a trait A, and another trait B implements it, + // then any class or datatype extending that last trait B must also explicitly implement the first trait A + // by calling the trait implementation in B + protected override bool InstanceMethodsCanOnlyCallOverridenTraitMethods => true; public void Start() { if (items != null) { @@ -189,10 +194,12 @@ protected override IClassWriter CreateClass(string moduleName, string name, bool if (currentBuilder is ClassContainer builder) { List typeParams = typeParameters.Select(tp => GenTypeArgDecl(tp)).ToList(); - return new ClassWriter(this, typeParams.Count > 0, builder.Class( + var classWriter = new ClassWriter(this, typeParams.Count > 0, builder.Class( name, moduleName, typeParams, superClasses.Select(t => GenType(t)).ToList(), ParseAttributes(cls.Attributes)) ); + + return classWriter; } else { throw new InvalidOperationException(); } @@ -301,7 +308,7 @@ from arg in ctor.Formals var superClasses = dt.ParentTypeInformation.UniqueParentTraits(); var superTraitTypes = superClasses.Select(GenType).ToList(); - return new ClassWriter(this, typeParams.Count > 0, builder.Datatype( + var datatypeBuilder = builder.Datatype( dt.GetCompileName(Options), dt.EnclosingModuleDefinition.GetCompileName(Options), typeParams, @@ -309,7 +316,9 @@ from arg in ctor.Formals dt is CoDatatypeDecl, ParseAttributes(dt.Attributes), superTraitTypes - )); + ); + + return new ClassWriter(this, typeParams.Count > 0, datatypeBuilder); } else { throw new InvalidOperationException("Cannot declare datatype outside of a module: " + currentBuilder); } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index f487a715b68..b3b97d32a63 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -693,6 +693,22 @@ module RAST | TSynonym(display: Type, base: Type) | TMetaData(display: Type, nameonly copySemantics: bool, nameonly overflow: bool) { + /** Converts Name (the type) to Name:: (the expr) */ + function ToExpr(): Option { + match this { + case TypeFromPath(path) => Some(ExprFromPath(path)) + case TypeApp(baseName, arguments) => + var baseNameExpr :- baseName.ToExpr(); + Some(baseNameExpr.ApplyType(arguments)) + case TSynonym(display, base) => + display.ToExpr() + case TMetaData(display, _, _) => + display.ToExpr() + case TIdentifier(name) => + Some(Identifier(name)) + case _ => None + } + } function Expand(): (r: Type) ensures !r.TSynonym? && !r.TMetaData? && (!TSynonym? && !TMetaData? ==> r == this) { @@ -1887,4 +1903,17 @@ module RAST } } } + predicate IsBorrowUpcastBox(r: Expr) { + match r { + case UnaryOp("&", Call(Call(CallType(name, targs0), args0), args1), _) => + name == dafny_runtime.MSel("upcast_box").AsExpr() && |args0| == 0 && + |args1| == 1 && + match args1[0] { + case Call(Select(Identifier("self"), clone), args2) => + |args2| == 0 + case _ => false + } + case _ => false + } + } } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index ae3644fb849..97c2c3a22b5 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -267,21 +267,22 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var superTraitType := superTraitTypes[i]; match superTraitType { case UserDefined(ResolvedType(traitPath, typeArgs, Trait(traitType), _, properMethods, _)) => { - var pathStr := GenPathType(traitPath); + var path := GenPath(traitPath); + var pathType := path.AsType(); var typeArgs := GenTypeArgs(typeArgs, GenTypeContext.default()); var body: seq := []; if traitPath in traitBodies { body := traitBodies[traitPath]; } - var fullTraitPath := R.TypeApp(pathStr, typeArgs); + var fullTraitPath := R.TypeApp(pathType, typeArgs); if !extern.NoExtern? { // An extern of some kind // Either the Dafny code implements all the methods of the trait or none, if |body| == 0 && |properMethods| != 0 { continue; // We assume everything is implemented externally } if |body| != |properMethods| { - error := Some("Error: In the "+kind+" " + R.SeqToString(path, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + + error := Some("Error: In the "+kind+" " + R.SeqToString(traitPath, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + fullTraitPath.ToString("") + " are marked {:extern} and some are not." + " For the Rust compiler, please make all methods (" + R.SeqToString(properMethods, (s: Name) => s.dafny_name, ", ") + ") bodiless and mark as {:extern} and implement them in a Rust file, "+ @@ -338,7 +339,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(fullTraitPath))), "", - Some(genPathExpr.ApplyType(rTypeParams).FSel("_clone").Apply1(R.self))) // Difference with UpcastStructBox is that there is no .as_ref() + Some(path.AsExpr().ApplyType(typeArgs).FSel("_clone").Apply1(R.self))) // Difference with UpcastStructBox is that there is no .as_ref() ) ])) ]; } else { @@ -523,7 +524,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var name := escapeName(t.name); var traitFulltype := R.TIdentifier(name).Apply(typeParams); var traitFullExpr := R.Identifier(name).ApplyType(typeParams); - var implBody, _ := GenClassImplBody( + var implBody, implBodyImplementingOtherTraits := GenClassImplBody( t.body, true, UserDefined( ResolvedType( @@ -543,11 +544,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { )) ]; } + while |implBodyImplementingOtherTraits| > 0 { + var otherTrait :| otherTrait in implBodyImplementingOtherTraits; + var otherMethods := implBodyImplementingOtherTraits[otherTrait]; + for i := 0 to |otherMethods| { + implBody := implBody + [otherMethods[i]]; // Defined in the trait, but not overriding. Implementations would have to ensure they call into that trait + } + implBodyImplementingOtherTraits := implBodyImplementingOtherTraits - {otherTrait}; + } var parents := []; var upcastImplemented := []; for i := 0 to |t.parents| { var parentTyp := t.parents[i]; var parentTpe := GenType(parentTyp, GenTypeContext.ForTraitParents()); + var parentTpeExprMaybe := parentTpe.ToExpr(); + var parentTpeExpr; + if parentTpeExprMaybe.None? { + parentTpeExpr := Error("Cannot convert " + parentTpe.ToString("") + " to an expression"); + } else { + parentTpeExpr := parentTpeExprMaybe.value; + } parents := parents + [parentTpe]; var upcastTrait := if parentTyp.IsGeneralTrait() then "UpcastBox" else Upcast; parents := parents + [R.dafny_runtime.MSel(upcastTrait).AsType().Apply1(R.DynType(parentTpe))]; @@ -570,7 +586,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(parentTpe))), "", - Some(traitFullExpr.FSel("_clone").Apply1(R.self.FSel("as_ref").Apply0())) + Some(parentTpeExpr.FSel("_clone").Apply1(R.self.Sel("as_ref").Apply0())) ) )])) ]; @@ -1884,6 +1900,11 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var argExprs, recIdents, typeExprs, fullNameQualifier := GenArgs(e, selfIdent, name, typeArgs, args, env); readIdents := recIdents; + if selfIdent.IsSelf() && name.CallName? && name.receiverArg.Some? && |argExprs| > 0 && R.IsBorrowUpcastBox(argExprs[0]) { + // The first argument is self and should not need conversion if it was applied as it should be passed raw. + argExprs := [R.Identifier("self")] + argExprs[1..]; + } + match fullNameQualifier { // Trait calls are fully specified as we can't guarantee traits will be in context case Some(ResolvedType(path, onTypeArgs, base, _, _, _)) => @@ -1920,7 +1941,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := readIdents + recIdents; } r := fullPath.ApplyType(onTypeExprs).FSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); - case _ => // Infix call on.name(args) + case _ => // Infix call on.name(args) or Companion::name(args) var onExpr, _, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); readIdents := readIdents + recIdents; var renderedName := GetMethodName(on, name); diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index cb586355535..91ec4d5e527 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -217,7 +217,7 @@ protected interface IClassWriter { protected virtual bool IncludeExternMembers { get => false; } protected virtual bool SupportsStaticsInGenericClasses => true; protected virtual bool TraitRepeatsInheritedDeclarations => false; - protected virtual bool InstanceMethodsAllowedToCallTraitMethods => true; + protected virtual bool InstanceMethodsCanOnlyCallOverridenTraitMethods => false; protected IClassWriter CreateClass(string moduleName, string name, TopLevelDecl cls, ConcreteSyntaxTree wr) { return CreateClass(moduleName, name, false, null, cls.TypeArgs, cls, (cls as TopLevelDeclWithMembers)?.ParentTypeInformation.UniqueParentTraits(), null, wr); @@ -2063,7 +2063,7 @@ seqType.Arg.AsSeqType is not { } subSeqType || return true; } - void OrderedBySCC(List decls, TopLevelDeclWithMembers c) { + protected void OrderedBySCC(List decls, TopLevelDeclWithMembers c) { List consts = new List(); foreach (var decl in decls) { if (decl is ConstantField) { @@ -2147,9 +2147,9 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite if (c is not TraitDecl || TraitRepeatsInheritedDeclarations) { thisContext = c; - var canRedeclareMemberDefinedInTrait = c is not ClassLikeDecl and not DatatypeDecl and not NewtypeDecl || - InstanceMethodsAllowedToCallTraitMethods; foreach (var member in inheritedMembers.Select(memberx => (memberx as Function)?.ByMethodDecl ?? memberx)) { + var canRedeclareMemberDefinedInTrait = c is not ClassLikeDecl and not DatatypeDecl and not NewtypeDecl || + !InstanceMethodsCanOnlyCallOverridenTraitMethods || member.IsOverrideThatAddsBody; enclosingDeclaration = member; Contract.Assert(!member.IsStatic); // only instance members should ever be added to .InheritedMembers if (member.IsGhost) { @@ -2200,7 +2200,10 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite } else if (member is Function fn) { if (!Attributes.Contains(fn.Attributes, "extern") && canRedeclareMemberDefinedInTrait) { Contract.Assert(fn.Body != null); - var w = classWriter.CreateFunction(IdName(fn), CombineAllTypeArguments(fn), fn.Ins, fn.ResultType, fn.tok, fn.IsStatic, true, fn, true, false); + var typeArguments = InstanceMethodsCanOnlyCallOverridenTraitMethods ? + new List() + : CombineAllTypeArguments(fn); + var w = classWriter.CreateFunction(IdName(fn), typeArguments, fn.Ins, fn.ResultType, fn.tok, fn.IsStatic, true, fn, true, false); w = EmitReturnExpr(w); EmitCallToInheritedFunction(fn, null, w); } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index f58d79e1c67..91e9d5e298e 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -305,56 +305,58 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc DAST._ITraitType _7_traitType = kind0.dtor_traitType; Dafny.ISequence> _8_properMethods = resolved0.dtor_properMethods; { - RAST._IType _9_pathStr; - RAST._IType _out1; - _out1 = (this).GenPathType(_5_traitPath); - _9_pathStr = _out1; - Dafny.ISequence _10_typeArgs; + RAST._IPath _9_path; + RAST._IPath _out1; + _out1 = (this).GenPath(_5_traitPath, true); + _9_path = _out1; + RAST._IType _10_pathType; + _10_pathType = (_9_path).AsType(); + Dafny.ISequence _11_typeArgs; Dafny.ISequence _out2; _out2 = (this).GenTypeArgs(_6_typeArgs, Defs.GenTypeContext.@default()); - _10_typeArgs = _out2; - Dafny.ISequence _11_body; - _11_body = Dafny.Sequence.FromElements(); + _11_typeArgs = _out2; + Dafny.ISequence _12_body; + _12_body = Dafny.Sequence.FromElements(); if ((traitBodies).Contains(_5_traitPath)) { - _11_body = Dafny.Map>, Dafny.ISequence>.Select(traitBodies,_5_traitPath); + _12_body = Dafny.Map>, Dafny.ISequence>.Select(traitBodies,_5_traitPath); } - RAST._IType _12_fullTraitPath; - _12_fullTraitPath = RAST.Type.create_TypeApp(_9_pathStr, _10_typeArgs); + RAST._IType _13_fullTraitPath; + _13_fullTraitPath = RAST.Type.create_TypeApp(_10_pathType, _11_typeArgs); if (!((@extern).is_NoExtern)) { - if (((new BigInteger((_11_body).Count)).Sign == 0) && ((new BigInteger((_8_properMethods).Count)).Sign != 0)) { + if (((new BigInteger((_12_body).Count)).Sign == 0) && ((new BigInteger((_8_properMethods).Count)).Sign != 0)) { goto continue_0; } - if ((new BigInteger((_11_body).Count)) != (new BigInteger((_8_properMethods).Count))) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the "), kind), Dafny.Sequence.UnicodeFromString(" ")), RAST.__default.SeqToString>(path, ((System.Func, Dafny.ISequence>)((_13_s) => { - return ((_13_s)); -})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_12_fullTraitPath)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" are marked {:extern} and some are not.")), Dafny.Sequence.UnicodeFromString(" For the Rust compiler, please make all methods (")), RAST.__default.SeqToString>(_8_properMethods, ((System.Func, Dafny.ISequence>)((_14_s) => { - return (_14_s); + if ((new BigInteger((_12_body).Count)) != (new BigInteger((_8_properMethods).Count))) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the "), kind), Dafny.Sequence.UnicodeFromString(" ")), RAST.__default.SeqToString>(_5_traitPath, ((System.Func, Dafny.ISequence>)((_14_s) => { + return ((_14_s)); +})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_13_fullTraitPath)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" are marked {:extern} and some are not.")), Dafny.Sequence.UnicodeFromString(" For the Rust compiler, please make all methods (")), RAST.__default.SeqToString>(_8_properMethods, ((System.Func, Dafny.ISequence>)((_15_s) => { + return (_15_s); })), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(") bodiless and mark as {:extern} and implement them in a Rust file, ")), Dafny.Sequence.UnicodeFromString("or mark none of them as {:extern} and implement them in Dafny. ")), Dafny.Sequence.UnicodeFromString("Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible."))); } } if ((_7_traitType).is_GeneralTrait) { - _11_body = Dafny.Sequence.Concat(_11_body, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_12_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))))); + _12_body = Dafny.Sequence.Concat(_12_body, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_13_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))))); } else { if (((kind).Equals(Dafny.Sequence.UnicodeFromString("datatype"))) || ((kind).Equals(Dafny.Sequence.UnicodeFromString("newtype")))) { - RAST._IExpr _15_dummy; + RAST._IExpr _16_dummy; RAST._IExpr _out3; _out3 = (this).Error(Dafny.Sequence.UnicodeFromString("Cannot extend non-general traits"), (this).InitEmptyExpr()); - _15_dummy = _out3; + _16_dummy = _out3; } } - RAST._IModDecl _16_x; - _16_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _12_fullTraitPath, RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), _11_body)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_16_x)); - Dafny.ISequence _17_upcastTraitToImplement = Dafny.Sequence.Empty; - Dafny.ISequence _18_upcastTraitFn = Dafny.Sequence.Empty; + RAST._IModDecl _17_x; + _17_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _13_fullTraitPath, RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), _12_body)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_17_x)); + Dafny.ISequence _18_upcastTraitToImplement = Dafny.Sequence.Empty; + Dafny.ISequence _19_upcastTraitFn = Dafny.Sequence.Empty; if ((_7_traitType).is_GeneralTrait) { Dafny.ISequence _rhs0 = Dafny.Sequence.UnicodeFromString("UpcastBox"); Dafny.ISequence _rhs1 = Dafny.Sequence.UnicodeFromString("UpcastStructBoxFn!"); - _17_upcastTraitToImplement = _rhs0; - _18_upcastTraitFn = _rhs1; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_12_fullTraitPath)), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_12_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((_2_genPathExpr).ApplyType(rTypeParams)).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(RAST.__default.self))))))))); + _18_upcastTraitToImplement = _rhs0; + _19_upcastTraitFn = _rhs1; + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_13_fullTraitPath)), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_13_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((_9_path).AsExpr()).ApplyType(_11_typeArgs)).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(RAST.__default.self))))))))); } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_12_fullTraitPath))), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_12_fullTraitPath))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_13_fullTraitPath))), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_13_fullTraitPath))))))))); } } goto after_match0; @@ -544,44 +546,72 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc RAST._IExpr _11_traitFullExpr; _11_traitFullExpr = (RAST.Expr.create_Identifier(_9_name)).ApplyType(_2_typeParams); Dafny.ISequence _12_implBody; - Dafny.IMap>,Dafny.ISequence> _13___v5; + Dafny.IMap>,Dafny.ISequence> _13_implBodyImplementingOtherTraits; Dafny.ISequence _out3; Dafny.IMap>,Dafny.ISequence> _out4; (this).GenClassImplBody((t).dtor_body, true, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_8_fullPath, Dafny.Sequence.FromElements(), DAST.ResolvedTypeBase.create_Trait((t).dtor_traitType), (t).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out3, out _out4); _12_implBody = _out3; - _13___v5 = _out4; + _13_implBodyImplementingOtherTraits = _out4; if (((t).dtor_traitType).is_GeneralTrait) { _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())))); } - Dafny.ISequence _14_parents; - _14_parents = Dafny.Sequence.FromElements(); - Dafny.ISequence _15_upcastImplemented; - _15_upcastImplemented = Dafny.Sequence.FromElements(); - BigInteger _hi1 = new BigInteger(((t).dtor_parents).Count); - for (BigInteger _16_i = BigInteger.Zero; _16_i < _hi1; _16_i++) { - DAST._IType _17_parentTyp; - _17_parentTyp = ((t).dtor_parents).Select(_16_i); - RAST._IType _18_parentTpe; + while ((new BigInteger((_13_implBodyImplementingOtherTraits).Count)).Sign == 1) { + Dafny.ISequence> _14_otherTrait; + foreach (Dafny.ISequence> _assign_such_that_0 in (_13_implBodyImplementingOtherTraits).Keys.Elements) { + _14_otherTrait = (Dafny.ISequence>)_assign_such_that_0; + if ((_13_implBodyImplementingOtherTraits).Contains(_14_otherTrait)) { + goto after__ASSIGN_SUCH_THAT_0; + } + } + throw new System.Exception("assign-such-that search produced no value"); + after__ASSIGN_SUCH_THAT_0: ; + Dafny.ISequence _15_otherMethods; + _15_otherMethods = Dafny.Map>, Dafny.ISequence>.Select(_13_implBodyImplementingOtherTraits,_14_otherTrait); + BigInteger _hi1 = new BigInteger((_15_otherMethods).Count); + for (BigInteger _16_i = BigInteger.Zero; _16_i < _hi1; _16_i++) { + _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements((_15_otherMethods).Select(_16_i))); + } + _13_implBodyImplementingOtherTraits = Dafny.Map>, Dafny.ISequence>.Subtract(_13_implBodyImplementingOtherTraits, Dafny.Set>>.FromElements(_14_otherTrait)); + } + Dafny.ISequence _17_parents; + _17_parents = Dafny.Sequence.FromElements(); + Dafny.ISequence _18_upcastImplemented; + _18_upcastImplemented = Dafny.Sequence.FromElements(); + BigInteger _hi2 = new BigInteger(((t).dtor_parents).Count); + for (BigInteger _19_i = BigInteger.Zero; _19_i < _hi2; _19_i++) { + DAST._IType _20_parentTyp; + _20_parentTyp = ((t).dtor_parents).Select(_19_i); + RAST._IType _21_parentTpe; RAST._IType _out5; - _out5 = (this).GenType(_17_parentTyp, Defs.GenTypeContext.ForTraitParents()); - _18_parentTpe = _out5; - _14_parents = Dafny.Sequence.Concat(_14_parents, Dafny.Sequence.FromElements(_18_parentTpe)); - Dafny.ISequence _19_upcastTrait; - if ((_17_parentTyp).IsGeneralTrait()) { - _19_upcastTrait = Dafny.Sequence.UnicodeFromString("UpcastBox"); + _out5 = (this).GenType(_20_parentTyp, Defs.GenTypeContext.ForTraitParents()); + _21_parentTpe = _out5; + Std.Wrappers._IOption _22_parentTpeExprMaybe; + _22_parentTpeExprMaybe = (_21_parentTpe).ToExpr(); + RAST._IExpr _23_parentTpeExpr = RAST.Expr.Default(); + if ((_22_parentTpeExprMaybe).is_None) { + RAST._IExpr _out6; + _out6 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Cannot convert "), (_21_parentTpe)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); + _23_parentTpeExpr = _out6; } else { - _19_upcastTrait = (this).Upcast; + _23_parentTpeExpr = (_22_parentTpeExprMaybe).dtor_value; } - _14_parents = Dafny.Sequence.Concat(_14_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_19_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)))); - if ((_17_parentTyp).IsGeneralTrait()) { - _15_upcastImplemented = Dafny.Sequence.Concat(_15_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_18_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_18_parentTpe))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); + _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements(_21_parentTpe)); + Dafny.ISequence _24_upcastTrait; + if ((_20_parentTyp).IsGeneralTrait()) { + _24_upcastTrait = Dafny.Sequence.UnicodeFromString("UpcastBox"); + } else { + _24_upcastTrait = (this).Upcast; + } + _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_24_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_21_parentTpe)))); + if ((_20_parentTyp).IsGeneralTrait()) { + _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_21_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_21_parentTpe))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_23_parentTpeExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); } } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_rTypeParamsDecls, _10_traitFulltype, _14_parents, _12_implBody))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_rTypeParamsDecls, _10_traitFulltype, _17_parents, _12_implBody))); if (((t).dtor_traitType).is_GeneralTrait) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); } - s = Dafny.Sequence.Concat(s, _15_upcastImplemented); + s = Dafny.Sequence.Concat(s, _18_upcastImplemented); return s; } public Dafny.ISequence GenNewtype(DAST._INewtype c, Dafny.ISequence> path) @@ -631,15 +661,15 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc DAST._IExpression _12_e; _12_e = DAST.Expression.create_Convert(_11_e, (c).dtor_base, _6_newtypeType); RAST._IExpr _13_r; - Defs._IOwnership _14___v6; - Dafny.ISet> _15___v7; + Defs._IOwnership _14___v5; + Dafny.ISet> _15___v6; RAST._IExpr _out4; Defs._IOwnership _out5; Dafny.ISet> _out6; (this).GenExpr(_12_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out4, out _out5, out _out6); _13_r = _out4; - _14___v6 = _out5; - _15___v7 = _out6; + _14___v5 = _out5; + _15___v6 = _out6; _10_fnBody = _13_r; } goto after_match0; @@ -664,14 +694,14 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc DAST._IFormal _17_formal = value0.dtor_variable; Dafny.ISequence _18_constraintStmts = value0.dtor_constraintStmts; RAST._IExpr _19_rStmts; - Dafny.ISet> _20___v8; + Dafny.ISet> _20___v7; Defs._IEnvironment _21_newEnv; RAST._IExpr _out7; Dafny.ISet> _out8; Defs._IEnvironment _out9; (this).GenStmts(_18_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out7, out _out8, out _out9); _19_rStmts = _out7; - _20___v8 = _out8; + _20___v7 = _out8; _21_newEnv = _out9; Dafny.ISequence _22_rFormals; Dafny.ISequence _out10; @@ -736,25 +766,25 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc DAST._IExpression _6_e = _source0.dtor_value; { RAST._IExpr _7_rStmts; - Dafny.ISet> _8___v9; + Dafny.ISet> _8___v8; Defs._IEnvironment _9_newEnv; RAST._IExpr _out4; Dafny.ISet> _out5; Defs._IEnvironment _out6; (this).GenStmts((c).dtor_witnessStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out4, out _out5, out _out6); _7_rStmts = _out4; - _8___v9 = _out5; + _8___v8 = _out5; _9_newEnv = _out6; RAST._IExpr _10_rExpr; - Defs._IOwnership _11___v10; - Dafny.ISet> _12___v11; + Defs._IOwnership _11___v9; + Dafny.ISet> _12___v10; RAST._IExpr _out7; Defs._IOwnership _out8; Dafny.ISet> _out9; (this).GenExpr(_6_e, Defs.SelfInfo.create_NoSelf(), _9_newEnv, Defs.Ownership.create_OwnershipOwned(), out _out7, out _out8, out _out9); _10_rExpr = _out7; - _11___v10 = _out8; - _12___v11 = _out9; + _11___v9 = _out8; + _12___v10 = _out9; Dafny.ISequence _13_constantName; _13_constantName = Defs.__default.escapeName(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_init_"), ((c).dtor_name))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_13_constantName, _5_defaultConstrainedTypeParams, Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_4_resultingType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((_7_rStmts).Then(_10_rExpr))))))); @@ -1971,15 +2001,15 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e after_match1: ; _32_env = Defs.Environment.create(Dafny.Sequence>.Concat(_34_preAssignNames, _1_paramNames), Dafny.Map, RAST._IType>.Merge(_35_preAssignTypes, _2_paramTypes)); RAST._IExpr _50_body; - Dafny.ISet> _51___v20; - Defs._IEnvironment _52___v21; + Dafny.ISet> _51___v19; + Defs._IEnvironment _52___v20; RAST._IExpr _out6; Dafny.ISet> _out7; Defs._IEnvironment _out8; (this).GenStmts((m).dtor_body, _8_selfIdent, _32_env, true, _36_earlyReturn, out _out6, out _out7, out _out8); _50_body = _out6; - _51___v20 = _out7; - _52___v21 = _out8; + _51___v19 = _out7; + _52___v20 = _out8; _31_fBody = Std.Wrappers.Option.create_Some((_33_preBody).Then(_50_body)); } else { _32_env = Defs.Environment.create(_1_paramNames, _2_paramTypes); @@ -2206,14 +2236,14 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Defs._ISelfInfo BigInteger _hi0 = new BigInteger((_12_indices).Count); for (BigInteger _18_i = BigInteger.Zero; _18_i < _hi0; _18_i++) { RAST._IExpr _19_idx; - Defs._IOwnership _20___v30; + Defs._IOwnership _20___v29; Dafny.ISet> _21_recIdentsIdx; RAST._IExpr _out6; Defs._IOwnership _out7; Dafny.ISet> _out8; (this).GenExpr((_12_indices).Select(_18_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out6, out _out7, out _out8); _19_idx = _out6; - _20___v30 = _out7; + _20___v29 = _out7; _21_recIdentsIdx = _out8; Dafny.ISequence _22_varName; _22_varName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("__idx"), Std.Strings.__default.OfNat(_18_i)); @@ -2248,6 +2278,9 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D _2_typeExprs = _out2; _3_fullNameQualifier = _out3; readIdents = _1_recIdents; + if ((((((selfIdent).IsSelf()) && ((name).is_CallName)) && (((name).dtor_receiverArg).is_Some)) && ((new BigInteger((_0_argExprs).Count)).Sign == 1)) && (RAST.__default.IsBorrowUpcastBox((_0_argExprs).Select(BigInteger.Zero)))) { + _0_argExprs = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))), (_0_argExprs).Drop(BigInteger.One)); + } Std.Wrappers._IOption _source0 = _3_fullNameQualifier; { if (_source0.is_Some) { @@ -2315,14 +2348,14 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D } { RAST._IExpr _12_onExpr; - Defs._IOwnership _13___v35; + Defs._IOwnership _13___v34; Dafny.ISet> _14_recIdents; RAST._IExpr _out18; Defs._IOwnership _out19; Dafny.ISet> _out20; (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out18, out _out19, out _out20); _12_onExpr = _out18; - _13___v35 = _out19; + _13___v34 = _out19; _14_recIdents = _out20; readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); Dafny.ISequence _15_renderedName; @@ -2402,15 +2435,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _5_isAssignedVar = Defs.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { RAST._IExpr _6_rhs; - Defs._IOwnership _7___v45; - Dafny.ISet> _8___v46; + Defs._IOwnership _7___v44; + Dafny.ISet> _8___v45; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr(DAST.Expression.create_InitializationValue(((_2_field).dtor_formal).dtor_typ), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); _6_rhs = _out1; - _7___v45 = _out2; - _8___v46 = _out3; + _7___v44 = _out2; + _8___v45 = _out3; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); Dafny.ISequence _9_update__if__uninit; if ((_2_field).dtor_isConstant) { @@ -2503,14 +2536,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _23_expression = _source0.dtor_value; { RAST._IExpr _24_exprGen; - Defs._IOwnership _25___v47; + Defs._IOwnership _25___v46; Dafny.ISet> _26_exprIdents; RAST._IExpr _out11; Defs._IOwnership _out12; Dafny.ISet> _out13; (this).GenExpr(_23_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out11, out _out12, out _out13); _24_exprGen = _out11; - _25___v47 = _out12; + _25___v46 = _out12; _26_exprIdents = _out13; if ((_22_lhs).is_Ident) { Dafny.ISequence _27_rustId; @@ -2560,14 +2593,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _37_elsDafny = _source0.dtor_els; { RAST._IExpr _38_cond; - Defs._IOwnership _39___v48; + Defs._IOwnership _39___v47; Dafny.ISet> _40_recIdents; RAST._IExpr _out18; Defs._IOwnership _out19; Dafny.ISet> _out20; (this).GenExpr(_35_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out18, out _out19, out _out20); _38_cond = _out18; - _39___v48 = _out19; + _39___v47 = _out19; _40_recIdents = _out20; Dafny.ISequence _41_condString; _41_condString = (_38_cond)._ToString(Defs.__default.IND); @@ -2628,14 +2661,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _54_body = _source0.dtor_body; { RAST._IExpr _55_cond; - Defs._IOwnership _56___v49; + Defs._IOwnership _56___v48; Dafny.ISet> _57_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr(_53_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _55_cond = _out30; - _56___v49 = _out31; + _56___v48 = _out31; _57_recIdents = _out32; readIdents = _57_recIdents; RAST._IExpr _58_bodyExpr; @@ -2663,14 +2696,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _64_body = _source0.dtor_body; { RAST._IExpr _65_over; - Defs._IOwnership _66___v50; + Defs._IOwnership _66___v49; Dafny.ISet> _67_recIdents; RAST._IExpr _out36; Defs._IOwnership _out37; Dafny.ISet> _out38; (this).GenExpr(_63_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out36, out _out37, out _out38); _65_over = _out36; - _66___v50 = _out37; + _66___v49 = _out37; _67_recIdents = _out38; if (((_63_overExpr).is_MapBoundedPool) || ((_63_overExpr).is_SetBoundedPool)) { _65_over = ((_65_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); @@ -2734,15 +2767,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _76_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { RAST._IExpr _77_selfClone; - Defs._IOwnership _78___v51; - Dafny.ISet> _79___v52; + Defs._IOwnership _78___v50; + Dafny.ISet> _79___v51; RAST._IExpr _out43; Defs._IOwnership _out44; Dafny.ISet> _out45; (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out43, out _out44, out _out45); _77_selfClone = _out43; - _78___v51 = _out44; - _79___v52 = _out45; + _78___v50 = _out44; + _79___v51 = _out45; generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_77_selfClone))); if (((_76_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { _76_oldEnv = (_76_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); @@ -2759,15 +2792,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv goto continue_4_0; } RAST._IExpr _83_paramInit; - Defs._IOwnership _84___v53; - Dafny.ISet> _85___v54; + Defs._IOwnership _84___v52; + Dafny.ISet> _85___v53; RAST._IExpr _out46; Defs._IOwnership _out47; Dafny.ISet> _out48; (this).GenIdent(_82_param, selfIdent, _76_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out46, out _out47, out _out48); _83_paramInit = _out46; - _84___v53 = _out47; - _85___v54 = _out48; + _84___v52 = _out47; + _85___v53 = _out48; Dafny.ISequence _86_recVar; _86_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_81_paramI)); generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _86_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_83_paramInit))); @@ -2858,14 +2891,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _103_exprDafny = _source0.dtor_expr; { RAST._IExpr _104_expr; - Defs._IOwnership _105___v55; + Defs._IOwnership _105___v54; Dafny.ISet> _106_recIdents; RAST._IExpr _out54; Defs._IOwnership _out55; Dafny.ISet> _out56; (this).GenExpr(_103_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out54, out _out55, out _out56); _104_expr = _out54; - _105___v55 = _out55; + _105___v54 = _out55; _106_recIdents = _out56; readIdents = _106_recIdents; if (isLast) { @@ -2895,15 +2928,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv BigInteger _hi3 = new BigInteger((_107_rustIdents).Count); for (BigInteger _109_i = BigInteger.Zero; _109_i < _hi3; _109_i++) { RAST._IExpr _110_rIdent; - Defs._IOwnership _111___v56; - Dafny.ISet> _112___v57; + Defs._IOwnership _111___v55; + Dafny.ISet> _112___v56; RAST._IExpr _out57; Defs._IOwnership _out58; Dafny.ISet> _out59; (this).GenIdent((_107_rustIdents).Select(_109_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out57, out _out58, out _out59); _110_rIdent = _out57; - _111___v56 = _out58; - _112___v57 = _out59; + _111___v55 = _out58; + _112___v56 = _out59; _108_tupleArgs = Dafny.Sequence.Concat(_108_tupleArgs, Dafny.Sequence.FromElements(_110_rIdent)); } if ((new BigInteger((_108_tupleArgs).Count)) == (BigInteger.One)) { @@ -3299,24 +3332,24 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ _10_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); } RAST._IExpr _11_left; - Defs._IOwnership _12___v58; + Defs._IOwnership _12___v57; Dafny.ISet> _13_recIdentsL; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(_4_lExpr, selfIdent, env, _9_expectedLeftOwnership, out _out0, out _out1, out _out2); _11_left = _out0; - _12___v58 = _out1; + _12___v57 = _out1; _13_recIdentsL = _out2; RAST._IExpr _14_right; - Defs._IOwnership _15___v59; + Defs._IOwnership _15___v58; Dafny.ISet> _16_recIdentsR; RAST._IExpr _out3; Defs._IOwnership _out4; Dafny.ISet> _out5; (this).GenExpr(_5_rExpr, selfIdent, env, _10_expectedRightOwnership, out _out3, out _out4, out _out5); _14_right = _out3; - _15___v59 = _out4; + _15___v58 = _out4; _16_recIdentsR = _out5; DAST._IBinOp _source0 = _0_op; { @@ -4331,14 +4364,14 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v76; + Defs._IOwnership _5___v75; Dafny.ISet> _6_argIdents; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); _4_argExpr = _out1; - _5___v76 = _out2; + _5___v75 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -4536,14 +4569,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi1 = new BigInteger((_9_values).Count); for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13___v86; + Defs._IOwnership _13___v85; Dafny.ISet> _14_recIdents; RAST._IExpr _out16; Defs._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); _12_recursiveGen = _out16; - _13___v86 = _out17; + _13___v85 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -4592,14 +4625,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi3 = new BigInteger((_17_args).Count); for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { RAST._IExpr _23_recursiveGen; - Defs._IOwnership _24___v87; + Defs._IOwnership _24___v86; Dafny.ISet> _25_recIdents; RAST._IExpr _out23; Defs._IOwnership _out24; Dafny.ISet> _out25; (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); _23_recursiveGen = _out23; - _24___v87 = _out24; + _24___v86 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -4637,14 +4670,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi4 = new BigInteger((_26_dims).Count); for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { RAST._IExpr _31_recursiveGen; - Defs._IOwnership _32___v88; + Defs._IOwnership _32___v87; Dafny.ISet> _33_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr((_26_dims).Select(_30_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _31_recursiveGen = _out30; - _32___v88 = _out31; + _32___v87 = _out31; _33_recIdents = _out32; _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); @@ -4671,14 +4704,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _35_underlying = _source0.dtor_value; { RAST._IExpr _36_recursiveGen; - Defs._IOwnership _37___v89; + Defs._IOwnership _37___v88; Dafny.ISet> _38_recIdents; RAST._IExpr _out35; Defs._IOwnership _out36; Dafny.ISet> _out37; (this).GenExpr(_35_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out35, out _out36, out _out37); _36_recursiveGen = _out35; - _37___v89 = _out36; + _37___v88 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -4701,14 +4734,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out40 = (this).GenType(_40_typ, Defs.GenTypeContext.@default()); _41_tpe = _out40; RAST._IExpr _42_recursiveGen; - Defs._IOwnership _43___v90; + Defs._IOwnership _43___v89; Dafny.ISet> _44_recIdents; RAST._IExpr _out41; Defs._IOwnership _out42; Dafny.ISet> _out43; (this).GenExpr(_39_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); _42_recursiveGen = _out41; - _43___v90 = _out42; + _43___v89 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -4774,14 +4807,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; if (_50_isCo) { RAST._IExpr _59_recursiveGen; - Defs._IOwnership _60___v91; + Defs._IOwnership _60___v90; Dafny.ISet> _61_recIdents; RAST._IExpr _out50; Defs._IOwnership _out51; Dafny.ISet> _out52; (this).GenExpr(_58_value, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); _59_recursiveGen = _out50; - _60___v91 = _out51; + _60___v90 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -4804,14 +4837,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _64_wasAssigned))); } else { RAST._IExpr _65_recursiveGen; - Defs._IOwnership _66___v92; + Defs._IOwnership _66___v91; Dafny.ISet> _67_recIdents; RAST._IExpr _out53; Defs._IOwnership _out54; Dafny.ISet> _out55; (this).GenExpr(_58_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out53, out _out54, out _out55); _65_recursiveGen = _out53; - _66___v92 = _out54; + _66___v91 = _out54; _67_recIdents = _out55; _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _65_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); @@ -4851,24 +4884,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _69_expr = _source0.dtor_elem; { RAST._IExpr _70_recursiveGen; - Defs._IOwnership _71___v96; + Defs._IOwnership _71___v95; Dafny.ISet> _72_recIdents; RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; (this).GenExpr(_69_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); _70_recursiveGen = _out61; - _71___v96 = _out62; + _71___v95 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v97; + Defs._IOwnership _74___v96; Dafny.ISet> _75_lengthIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_68_length, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); _73_lengthGen = _out64; - _74___v97 = _out65; + _74___v96 = _out65; _75_lengthIdents = _out66; r = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("_initializer"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_70_recursiveGen)); RAST._IExpr _76_range; @@ -4907,14 +4940,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _82_args = Dafny.Sequence.FromElements(); while ((_81_i) < (new BigInteger((_78_exprs).Count))) { RAST._IExpr _83_recursiveGen; - Defs._IOwnership _84___v98; + Defs._IOwnership _84___v97; Dafny.ISet> _85_recIdents; RAST._IExpr _out70; Defs._IOwnership _out71; Dafny.ISet> _out72; (this).GenExpr((_78_exprs).Select(_81_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out70, out _out71, out _out72); _83_recursiveGen = _out70; - _84___v98 = _out71; + _84___v97 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -4945,14 +4978,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _88_i = BigInteger.Zero; while ((_88_i) < (new BigInteger((_86_exprs).Count))) { RAST._IExpr _89_recursiveGen; - Defs._IOwnership _90___v99; + Defs._IOwnership _90___v98; Dafny.ISet> _91_recIdents; RAST._IExpr _out75; Defs._IOwnership _out76; Dafny.ISet> _out77; (this).GenExpr((_86_exprs).Select(_88_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out75, out _out76, out _out77); _89_recursiveGen = _out75; - _90___v99 = _out76; + _90___v98 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -4980,14 +5013,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _94_i = BigInteger.Zero; while ((_94_i) < (new BigInteger((_92_exprs).Count))) { RAST._IExpr _95_recursiveGen; - Defs._IOwnership _96___v100; + Defs._IOwnership _96___v99; Dafny.ISet> _97_recIdents; RAST._IExpr _out80; Defs._IOwnership _out81; Dafny.ISet> _out82; (this).GenExpr((_92_exprs).Select(_94_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out80, out _out81, out _out82); _95_recursiveGen = _out80; - _96___v100 = _out81; + _96___v99 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -5009,14 +5042,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _98_expr = _source0.dtor_ToMultiset_a0; { RAST._IExpr _99_recursiveGen; - Defs._IOwnership _100___v101; + Defs._IOwnership _100___v100; Dafny.ISet> _101_recIdents; RAST._IExpr _out85; Defs._IOwnership _out86; Dafny.ISet> _out87; (this).GenExpr(_98_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out85, out _out86, out _out87); _99_recursiveGen = _out85; - _100___v101 = _out86; + _100___v100 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -5041,24 +5074,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _104_i = BigInteger.Zero; while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v102; + Defs._IOwnership _106___v101; Dafny.ISet> _107_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); _105_recursiveGenKey = _out90; - _106___v102 = _out91; + _106___v101 = _out91; _107_recIdentsKey = _out92; RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v103; + Defs._IOwnership _109___v102; Dafny.ISet> _110_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); _108_recursiveGenValue = _out93; - _109___v103 = _out94; + _109___v102 = _out94; _110_recIdentsValue = _out95; _103_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_103_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_105_recursiveGenKey, _108_recursiveGenValue))); readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _107_recIdentsKey), _110_recIdentsValue); @@ -5093,14 +5126,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _116_value = _source0.dtor_value; { RAST._IExpr _117_exprR; - Defs._IOwnership _118___v104; + Defs._IOwnership _118___v103; Dafny.ISet> _119_exprIdents; RAST._IExpr _out98; Defs._IOwnership _out99; Dafny.ISet> _out100; (this).GenExpr(_114_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out98, out _out99, out _out100); _117_exprR = _out98; - _118___v104 = _out99; + _118___v103 = _out99; _119_exprIdents = _out100; RAST._IExpr _120_indexR; Defs._IOwnership _121_indexOwnership; @@ -5141,14 +5174,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _128_value = _source0.dtor_value; { RAST._IExpr _129_exprR; - Defs._IOwnership _130___v105; + Defs._IOwnership _130___v104; Dafny.ISet> _131_exprIdents; RAST._IExpr _out109; Defs._IOwnership _out110; Dafny.ISet> _out111; (this).GenExpr(_126_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out109, out _out110, out _out111); _129_exprR = _out109; - _130___v105 = _out110; + _130___v104 = _out110; _131_exprIdents = _out111; RAST._IExpr _132_indexR; Defs._IOwnership _133_indexOwnership; @@ -5229,14 +5262,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _143_f = _source0.dtor_els; { RAST._IExpr _144_cond; - Defs._IOwnership _145___v106; + Defs._IOwnership _145___v105; Dafny.ISet> _146_recIdentsCond; RAST._IExpr _out126; Defs._IOwnership _out127; Dafny.ISet> _out128; (this).GenExpr(_141_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out126, out _out127, out _out128); _144_cond = _out126; - _145___v106 = _out127; + _145___v105 = _out127; _146_recIdentsCond = _out128; RAST._IExpr _147_fExpr; Defs._IOwnership _148_fOwned; @@ -5249,14 +5282,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _148_fOwned = _out130; _149_recIdentsF = _out131; RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v107; + Defs._IOwnership _151___v106; Dafny.ISet> _152_recIdentsT; RAST._IExpr _out132; Defs._IOwnership _out133; Dafny.ISet> _out134; (this).GenExpr(_142_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); _150_tExpr = _out132; - _151___v107 = _out133; + _151___v106 = _out133; _152_recIdentsT = _out134; r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); RAST._IExpr _out135; @@ -5278,14 +5311,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; { RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v108; + Defs._IOwnership _156___v107; Dafny.ISet> _157_recIdents; RAST._IExpr _out137; Defs._IOwnership _out138; Dafny.ISet> _out139; (this).GenExpr(_153_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out137, out _out138, out _out139); _155_recursiveGen = _out137; - _156___v108 = _out138; + _156___v107 = _out138; _157_recIdents = _out139; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); RAST._IExpr _out140; @@ -5308,14 +5341,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; { RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v109; + Defs._IOwnership _161___v108; Dafny.ISet> _162_recIdents; RAST._IExpr _out142; Defs._IOwnership _out143; Dafny.ISet> _out144; (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out142, out _out143, out _out144); _160_recursiveGen = _out142; - _161___v109 = _out143; + _161___v108 = _out143; _162_recIdents = _out144; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); RAST._IExpr _out145; @@ -5380,14 +5413,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _171_native = _source0.dtor_native; { RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v114; + Defs._IOwnership _173___v113; Dafny.ISet> _174_recIdents; RAST._IExpr _out155; Defs._IOwnership _out156; Dafny.ISet> _out157; (this).GenExpr(_168_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out155, out _out156, out _out157); _172_recursiveGen = _out155; - _173___v114 = _out156; + _173___v113 = _out156; _174_recIdents = _out157; RAST._IType _175_arrayType; RAST._IType _out158; @@ -5429,14 +5462,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _177_expr = _source0.dtor_expr; { RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v115; + Defs._IOwnership _179___v114; Dafny.ISet> _180_recIdents; RAST._IExpr _out162; Defs._IOwnership _out163; Dafny.ISet> _out164; (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); _178_recursiveGen = _out162; - _179___v115 = _out163; + _179___v114 = _out163; _180_recIdents = _out164; readIdents = _180_recIdents; r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); @@ -5455,14 +5488,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _181_expr = _source0.dtor_expr; { RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v116; + Defs._IOwnership _183___v115; Dafny.ISet> _184_recIdents; RAST._IExpr _out167; Defs._IOwnership _out168; Dafny.ISet> _out169; (this).GenExpr(_181_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); _182_recursiveGen = _out167; - _183___v116 = _out168; + _183___v115 = _out168; _184_recIdents = _out169; readIdents = _184_recIdents; r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); @@ -5481,14 +5514,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _185_expr = _source0.dtor_expr; { RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v117; + Defs._IOwnership _187___v116; Dafny.ISet> _188_recIdents; RAST._IExpr _out172; Defs._IOwnership _out173; Dafny.ISet> _out174; (this).GenExpr(_185_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out172, out _out173, out _out174); _186_recursiveGen = _out172; - _187___v117 = _out173; + _187___v116 = _out173; _188_recIdents = _out174; readIdents = _188_recIdents; r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); @@ -5560,15 +5593,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _209_name = _let_tmp_rhs1.dtor__0; RAST._IType _210_ty = _let_tmp_rhs1.dtor__1; RAST._IExpr _211_rIdent; - Defs._IOwnership _212___v118; - Dafny.ISet> _213___v119; + Defs._IOwnership _212___v117; + Dafny.ISet> _213___v118; RAST._IExpr _out181; Defs._IOwnership _out182; Dafny.ISet> _out183; (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((!(_193_isConstant)) && ((_210_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); _211_rIdent = _out181; - _212___v118 = _out182; - _213___v119 = _out183; + _212___v117 = _out182; + _213___v118 = _out183; _207_onExprArgs = Dafny.Sequence.Concat(_207_onExprArgs, Dafny.Sequence.FromElements(_211_rIdent)); } _206_body = (_206_body).Apply(_207_onExprArgs); @@ -5859,14 +5892,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _258_l = _source5.dtor_value; { RAST._IExpr _259_lExpr; - Defs._IOwnership _260___v122; + Defs._IOwnership _260___v121; Dafny.ISet> _261_recIdentsL; RAST._IExpr _out217; Defs._IOwnership _out218; Dafny.ISet> _out219; (this).GenExpr(_258_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out217, out _out218, out _out219); _259_lExpr = _out217; - _260___v122 = _out218; + _260___v121 = _out218; _261_recIdentsL = _out219; _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_259_lExpr)); readIdents = Dafny.Set>.Union(readIdents, _261_recIdentsL); @@ -5883,14 +5916,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _262_h = _source6.dtor_value; { RAST._IExpr _263_hExpr; - Defs._IOwnership _264___v123; + Defs._IOwnership _264___v122; Dafny.ISet> _265_recIdentsH; RAST._IExpr _out220; Defs._IOwnership _out221; Dafny.ISet> _out222; (this).GenExpr(_262_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out220, out _out221, out _out222); _263_hExpr = _out220; - _264___v123 = _out221; + _264___v122 = _out221; _265_recIdentsH = _out222; _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_263_hExpr)); readIdents = Dafny.Set>.Union(readIdents, _265_recIdentsH); @@ -6020,14 +6053,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _287_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_283_paramNames, _284_paramTypesMap)); RAST._IExpr _288_recursiveGen; Dafny.ISet> _289_recIdents; - Defs._IEnvironment _290___v125; + Defs._IEnvironment _290___v124; RAST._IExpr _out235; Dafny.ISet> _out236; Defs._IEnvironment _out237; (this).GenStmts(_281_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _287_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out235, out _out236, out _out237); _288_recursiveGen = _out235; _289_recIdents = _out236; - _290___v125 = _out237; + _290___v124 = _out237; readIdents = Dafny.Set>.FromElements(); _289_recIdents = Dafny.Set>.Difference(_289_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_291_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); @@ -6053,15 +6086,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir after__ASSIGN_SUCH_THAT_1: ; if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_294_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { RAST._IExpr _295_selfCloned; - Defs._IOwnership _296___v126; - Dafny.ISet> _297___v127; + Defs._IOwnership _296___v125; + Dafny.ISet> _297___v126; RAST._IExpr _out238; Defs._IOwnership _out239; Dafny.ISet> _out240; (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out238, out _out239, out _out240); _295_selfCloned = _out238; - _296___v126 = _out239; - _297___v127 = _out240; + _296___v125 = _out239; + _297___v126 = _out240; _293_allReadCloned = (_293_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_295_selfCloned))); } else if (!((_283_paramNames).Contains(_294_next))) { RAST._IExpr _298_copy; @@ -6123,14 +6156,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out245 = (this).GenType((((_300_values).Select(_311_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); _312_typeGen = _out245; RAST._IExpr _313_valueGen; - Defs._IOwnership _314___v128; + Defs._IOwnership _314___v127; Dafny.ISet> _315_recIdents; RAST._IExpr _out246; Defs._IOwnership _out247; Dafny.ISet> _out248; (this).GenExpr(((_300_values).Select(_311_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out246, out _out247, out _out248); _313_valueGen = _out246; - _314___v128 = _out247; + _314___v127 = _out247; _315_recIdents = _out248; r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_300_values).Select(_311_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_312_typeGen), Std.Wrappers.Option.create_Some(_313_valueGen))); readIdents = Dafny.Set>.Union(readIdents, _315_recIdents); @@ -6167,14 +6200,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _323_iifeBody = _source0.dtor_iifeBody; { RAST._IExpr _324_valueGen; - Defs._IOwnership _325___v129; + Defs._IOwnership _325___v128; Dafny.ISet> _326_recIdents; RAST._IExpr _out254; Defs._IOwnership _out255; Dafny.ISet> _out256; (this).GenExpr(_322_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out254, out _out255, out _out256); _324_valueGen = _out254; - _325___v129 = _out255; + _325___v128 = _out255; _326_recIdents = _out256; readIdents = _326_recIdents; RAST._IType _327_valueTypeGen; @@ -6184,14 +6217,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _328_iifeVar; _328_iifeVar = Defs.__default.escapeVar(_320_name); RAST._IExpr _329_bodyGen; - Defs._IOwnership _330___v130; + Defs._IOwnership _330___v129; Dafny.ISet> _331_bodyIdents; RAST._IExpr _out258; Defs._IOwnership _out259; Dafny.ISet> _out260; (this).GenExpr(_323_iifeBody, selfIdent, (env).AddAssigned(_328_iifeVar, _327_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out258, out _out259, out _out260); _329_bodyGen = _out258; - _330___v130 = _out259; + _330___v129 = _out259; _331_bodyIdents = _out260; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_331_bodyIdents, Dafny.Set>.FromElements(_328_iifeVar))); r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _328_iifeVar, Std.Wrappers.Option.create_Some(_327_valueTypeGen), Std.Wrappers.Option.create_Some(_324_valueGen))).Then(_329_bodyGen)); @@ -6211,14 +6244,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _333_args = _source0.dtor_args; { RAST._IExpr _334_funcExpr; - Defs._IOwnership _335___v131; + Defs._IOwnership _335___v130; Dafny.ISet> _336_recIdents; RAST._IExpr _out263; Defs._IOwnership _out264; Dafny.ISet> _out265; (this).GenExpr(_332_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out263, out _out264, out _out265); _334_funcExpr = _out263; - _335___v131 = _out264; + _335___v130 = _out264; _336_recIdents = _out265; readIdents = _336_recIdents; Dafny.ISequence _337_rArgs; @@ -6256,14 +6289,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _344_variant = _source0.dtor_variant; { RAST._IExpr _345_exprGen; - Defs._IOwnership _346___v132; + Defs._IOwnership _346___v131; Dafny.ISet> _347_recIdents; RAST._IExpr _out271; Defs._IOwnership _out272; Dafny.ISet> _out273; (this).GenExpr(_342_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out271, out _out272, out _out273); _345_exprGen = _out271; - _346___v132 = _out272; + _346___v131 = _out272; _347_recIdents = _out273; RAST._IExpr _348_variantExprPath; RAST._IExpr _out274; @@ -6344,14 +6377,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _357_of = _source0.dtor_of; { RAST._IExpr _358_exprGen; - Defs._IOwnership _359___v133; + Defs._IOwnership _359___v132; Dafny.ISet> _360_recIdents; RAST._IExpr _out287; Defs._IOwnership _out288; Dafny.ISet> _out289; (this).GenExpr(_357_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out287, out _out288, out _out289); _358_exprGen = _out287; - _359___v133 = _out288; + _359___v132 = _out288; _360_recIdents = _out289; r = ((_358_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out290; @@ -6371,14 +6404,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _362_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _363_exprGen; - Defs._IOwnership _364___v134; + Defs._IOwnership _364___v133; Dafny.ISet> _365_recIdents; RAST._IExpr _out292; Defs._IOwnership _out293; Dafny.ISet> _out294; (this).GenExpr(_361_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out292, out _out293, out _out294); _363_exprGen = _out292; - _364___v134 = _out293; + _364___v133 = _out293; _365_recIdents = _out294; r = ((_363_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_362_includeDuplicates)) { @@ -6401,14 +6434,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _367_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _368_exprGen; - Defs._IOwnership _369___v135; + Defs._IOwnership _369___v134; Dafny.ISet> _370_recIdents; RAST._IExpr _out297; Defs._IOwnership _out298; Dafny.ISet> _out299; (this).GenExpr(_366_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out297, out _out298, out _out299); _368_exprGen = _out297; - _369___v135 = _out298; + _369___v134 = _out298; _370_recIdents = _out299; r = ((_368_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_367_includeDuplicates)) { @@ -6430,14 +6463,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _371_of = _source0.dtor_of; { RAST._IExpr _372_exprGen; - Defs._IOwnership _373___v136; + Defs._IOwnership _373___v135; Dafny.ISet> _374_recIdents; RAST._IExpr _out302; Defs._IOwnership _out303; Dafny.ISet> _out304; (this).GenExpr(_371_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); _372_exprGen = _out302; - _373___v136 = _out303; + _373___v135 = _out303; _374_recIdents = _out304; r = ((((_372_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); readIdents = _374_recIdents; @@ -6455,14 +6488,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _375_of = _source0.dtor_of; { RAST._IExpr _376_exprGen; - Defs._IOwnership _377___v137; + Defs._IOwnership _377___v136; Dafny.ISet> _378_recIdents; RAST._IExpr _out307; Defs._IOwnership _out308; Dafny.ISet> _out309; (this).GenExpr(_375_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out307, out _out308, out _out309); _376_exprGen = _out307; - _377___v137 = _out308; + _377___v136 = _out308; _378_recIdents = _out309; r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_376_exprGen); readIdents = _378_recIdents; @@ -6483,24 +6516,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _382_up = _source0.dtor_up; { RAST._IExpr _383_lo; - Defs._IOwnership _384___v138; + Defs._IOwnership _384___v137; Dafny.ISet> _385_recIdentsLo; RAST._IExpr _out312; Defs._IOwnership _out313; Dafny.ISet> _out314; (this).GenExpr(_380_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out312, out _out313, out _out314); _383_lo = _out312; - _384___v138 = _out313; + _384___v137 = _out313; _385_recIdentsLo = _out314; RAST._IExpr _386_hi; - Defs._IOwnership _387___v139; + Defs._IOwnership _387___v138; Dafny.ISet> _388_recIdentsHi; RAST._IExpr _out315; Defs._IOwnership _out316; Dafny.ISet> _out317; (this).GenExpr(_381_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out315, out _out316, out _out317); _386_hi = _out315; - _387___v139 = _out316; + _387___v138 = _out316; _388_recIdentsHi = _out317; if (_382_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_383_lo, _386_hi)); @@ -6531,14 +6564,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _391_up = _source0.dtor_up; { RAST._IExpr _392_start; - Defs._IOwnership _393___v140; + Defs._IOwnership _393___v139; Dafny.ISet> _394_recIdentStart; RAST._IExpr _out321; Defs._IOwnership _out322; Dafny.ISet> _out323; (this).GenExpr(_390_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out321, out _out322, out _out323); _392_start = _out321; - _393___v140 = _out322; + _393___v139 = _out322; _394_recIdentStart = _out323; if (_391_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_392_start); @@ -6612,14 +6645,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out333 = (this).GenType(_401_elemType, Defs.GenTypeContext.@default()); _405_tpe = _out333; RAST._IExpr _406_collectionGen; - Defs._IOwnership _407___v141; + Defs._IOwnership _407___v140; Dafny.ISet> _408_recIdents; RAST._IExpr _out334; Defs._IOwnership _out335; Dafny.ISet> _out336; (this).GenExpr(_402_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); _406_collectionGen = _out334; - _407___v141 = _out335; + _407___v140 = _out335; _408_recIdents = _out336; Dafny.ISequence _409_extraAttributes; _409_extraAttributes = Dafny.Sequence.FromElements(); @@ -6642,14 +6675,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _417_dt__update_hparams_h0 = _411_newFormals; _415_newLambda = DAST.Expression.create_Lambda(_417_dt__update_hparams_h0, (_416_dt__update__tmp_h1).dtor_retType, (_416_dt__update__tmp_h1).dtor_body); RAST._IExpr _418_lambdaGen; - Defs._IOwnership _419___v142; + Defs._IOwnership _419___v141; Dafny.ISet> _420_recLambdaIdents; RAST._IExpr _out337; Defs._IOwnership _out338; Dafny.ISet> _out339; (this).GenExpr(_415_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); _418_lambdaGen = _out337; - _419___v142 = _out338; + _419___v141 = _out338; _420_recLambdaIdents = _out339; Dafny.ISequence _421_fn; if (_403_is__forall) { @@ -6756,15 +6789,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v143; - Dafny.ISet> _2___v144; + Defs._IOwnership _1___v142; + Dafny.ISet> _2___v143; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v143 = _out1; - _2___v144 = _out2; + _1___v142 = _out1; + _2___v143 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index 5f2fbfec458..86045b8317a 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -165,6 +165,54 @@ public static RAST._IExpr RcNew(RAST._IExpr underlying) { public static RAST._IExpr IntoUsize(RAST._IExpr underlying) { return (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyUsize"))).FSel(Dafny.Sequence.UnicodeFromString("into_usize"))).Apply1(underlying); } + public static bool IsBorrowUpcastBox(RAST._IExpr r) { + RAST._IExpr _source0 = r; + { + if (_source0.is_UnaryOp) { + Dafny.ISequence op10 = _source0.dtor_op1; + if (object.Equals(op10, Dafny.Sequence.UnicodeFromString("&"))) { + RAST._IExpr underlying0 = _source0.dtor_underlying; + if (underlying0.is_Call) { + RAST._IExpr obj0 = underlying0.dtor_obj; + if (obj0.is_Call) { + RAST._IExpr obj1 = obj0.dtor_obj; + if (obj1.is_CallType) { + RAST._IExpr _0_name = obj1.dtor_obj; + Dafny.ISequence _1_targs0 = obj1.dtor_typeArguments; + Dafny.ISequence _2_args0 = obj0.dtor_arguments; + Dafny.ISequence _3_args1 = underlying0.dtor_arguments; + return (((object.Equals(_0_name, ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("upcast_box"))).AsExpr())) && ((new BigInteger((_2_args0).Count)).Sign == 0)) && ((new BigInteger((_3_args1).Count)) == (BigInteger.One))) && (((System.Func)(() => { + RAST._IExpr _source1 = (_3_args1).Select(BigInteger.Zero); + { + if (_source1.is_Call) { + RAST._IExpr obj2 = _source1.dtor_obj; + if (obj2.is_Select) { + RAST._IExpr obj3 = obj2.dtor_obj; + if (obj3.is_Identifier) { + Dafny.ISequence name0 = obj3.dtor_name; + if (object.Equals(name0, Dafny.Sequence.UnicodeFromString("self"))) { + Dafny.ISequence _4_clone = obj2.dtor_name; + Dafny.ISequence _5_args2 = _source1.dtor_arguments; + return (new BigInteger((_5_args2).Count)).Sign == 0; + } + } + } + } + } + { + return false; + } + }))()); + } + } + } + } + } + } + { + return false; + } + } public static RAST._IType SelfOwned { get { return (RAST.Path.create_Self()).AsType(); } } @@ -2763,6 +2811,7 @@ public interface _IType { bool dtor_copySemantics { get; } bool dtor_overflow { get; } _IType DowncastClone(); + Std.Wrappers._IOption ToExpr(); RAST._IType Expand(); bool EndsWithNameThatCanAcceptGenerics(); RAST._IType ReplaceMap(Dafny.IMap mapping); @@ -2993,6 +3042,50 @@ public bool dtor_overflow { } } public abstract _IType DowncastClone(); + public Std.Wrappers._IOption ToExpr() { + RAST._IType _source0 = this; + { + if (_source0.is_TypeFromPath) { + RAST._IPath _0_path = _source0.dtor_path; + return Std.Wrappers.Option.create_Some(RAST.Expr.create_ExprFromPath(_0_path)); + } + } + { + if (_source0.is_TypeApp) { + RAST._IType _1_baseName = _source0.dtor_baseName; + Dafny.ISequence _2_arguments = _source0.dtor_arguments; + Std.Wrappers._IOption _3_valueOrError0 = (_1_baseName).ToExpr(); + if ((_3_valueOrError0).IsFailure()) { + return (_3_valueOrError0).PropagateFailure(); + } else { + RAST._IExpr _4_baseNameExpr = (_3_valueOrError0).Extract(); + return Std.Wrappers.Option.create_Some((_4_baseNameExpr).ApplyType(_2_arguments)); + } + } + } + { + if (_source0.is_TSynonym) { + RAST._IType _5_display = _source0.dtor_display; + RAST._IType _6_base = _source0.dtor_base; + return (_5_display).ToExpr(); + } + } + { + if (_source0.is_TMetaData) { + RAST._IType _7_display = _source0.dtor_display; + return (_7_display).ToExpr(); + } + } + { + if (_source0.is_TIdentifier) { + Dafny.ISequence _8_name = _source0.dtor_name; + return Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_8_name)); + } + } + { + return Std.Wrappers.Option.create_None(); + } + } public RAST._IType Expand() { _IType _this = this; TAIL_CALL_START: ; diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy index 0dace953dd9..d8566ea8827 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy @@ -1,8 +1,10 @@ // NONUNIFORM: Rust-specific tests // RUN: %baredafny run --target=rs --type-system-refresh --general-traits=datatype "%s" > "%t" // RUN: %diff "%s.expect" "%t" - -trait DatatypeOps { +trait SuperTrait { + function GetBool(): bool +} +trait DatatypeOps extends SuperTrait { function GetInt(): int function GetBool(): bool { GetInt() % 2 == 0 @@ -51,5 +53,9 @@ method Main() { expect y1.ChooseAmong(8, 9) == 9; var y1m := y1.ChooseAmongMethod(8, 9); expect y1m == 9; + var zy := y as SuperTrait; + var zx := x as SuperTrait; + expect zx.GetBool(); + expect !zy.GetBool(); print "Main passed all the tests"; } \ No newline at end of file From 11fe1ea116092647bd02c34db1a3a09357ada614 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 2 Dec 2024 05:47:09 +0100 Subject: [PATCH 13/69] Support for formatting --- .../Backends/Dafny/DafnyCodeGenerator.cs | 13 +--- .../Rust/Dafny-compiler-rust-definitions.dfy | 16 +++-- .../Backends/Rust/Dafny-compiler-rust.dfy | 63 ++++++++++++++----- .../SinglePassCodeGenerator.cs | 5 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 8 +-- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 6 ++ .../LitTest/comp/rust/traits-datatypes.dfy | 22 +++++++ .../comp/rust/traits-datatypes.dfy.expect | 1 + 8 files changed, 99 insertions(+), 35 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 15e8454a3ce..7dea1b4d4a6 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -536,12 +536,7 @@ public ClassWriter(DafnyCodeGenerator compiler, bool hasTypeArgs, ClassLike buil public ConcreteSyntaxTree CreateMethod(Method m, List typeArgs, bool createBody, bool forBodyInheritance, bool lookasideBody) { - if (m.IsStatic && this.hasTypeArgs) { - compiler.AddUnsupported(m.tok, "Static methods with type arguments"); - return new BuilderSyntaxTree(new StatementBuffer(), this.compiler); - } - - var astTypeArgs = typeArgs.Select(typeArg => compiler.GenTypeArgDecl(typeArg.Formal)).ToList(); + var astTypeArgs = m.TypeArgs.Select(typeArg => compiler.GenTypeArgDecl(typeArg)).ToList(); var params_ = compiler.GenFormals(m.Ins); @@ -601,12 +596,8 @@ public ConcreteSyntaxTree SynthesizeMethod(Method m, List typeArgs, List formals, Type resultType, IToken tok, bool isStatic, bool createBody, MemberDecl member, bool forBodyInheritance, bool lookasideBody) { - if (isStatic && this.hasTypeArgs) { - compiler.AddUnsupported(tok, "Static functions with type arguments"); - return new BuilderSyntaxTree(new StatementBuffer(), this.compiler); - } - var astTypeArgs = typeArgs.Select(typeArg => compiler.GenTypeArgDecl(typeArg.Formal)).ToList(); + var astTypeArgs = ((Function)member).TypeArgs.Select(typeArg => compiler.GenTypeArgDecl(typeArg)).ToList(); var params_ = compiler.GenFormals(formals); diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index d933d16979f..96f2723721e 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -695,11 +695,19 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { Some(R.std.MSel("option").MSel("Option").AsType().Apply1(R.std.MSel("cmp").MSel("Ordering").AsType())), "", Some( - R.std.MSel("cmp").MSel("PartialOrd").AsExpr().FSel("partial_cmp").Apply([ - R.Borrow(R.self.Sel("0")), - R.Borrow(R.Identifier("other").Sel("0")) - ])) + R.std.MSel("cmp").MSel("PartialOrd").AsExpr().FSel("partial_cmp").Apply( + [ + R.Borrow(R.self.Sel("0")), + R.Borrow(R.Identifier("other").Sel("0")) + ])) )) ])) } + + const fmt_print_parameters := [ + R.Formal.selfBorrowed, + R.Formal("_formatter", R.BorrowedMut(R.std.MSel("fmt").MSel("Formatter").AsType())), + R.Formal("in_seq", R.Type.Bool)] + + const fmt_print_result := R.std.MSel("fmt").MSel("Result").AsType() } \ No newline at end of file diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 97c2c3a22b5..7d4823a80a9 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -294,11 +294,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // Extern type, we assume } if traitType.GeneralTrait? { - // One more method: Cloning when boxed + // Two more methods: Cloning when boxed and printing when boxed /*impl Test for Wrapper { + ... fn _clone(&self) -> Box { Box::new(self.clone()) } + fn _fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { + self.fmt_print(f, in_seq) + } }*/ body := body + [ R.FnDecl( @@ -306,7 +310,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Fn( "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(fullTraitPath))), "", - Some(R.BoxNew(R.self.Sel("clone").Apply0())))) + Some(R.BoxNew(R.self.Sel("clone").Apply0())))), + R.FnDecl( + R.PRIV, + R.Fn( + "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), + "", + Some(R.self.Sel("fmt_print").Apply([R.Identifier("_formatter"), R.Identifier("in_seq")])))) ]; } else { if kind == "datatype" || kind == "newtype" { @@ -541,7 +551,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(traitFulltype))), "", None - )) + )), + R.FnDecl( + R.PRIV, + R.Fn( + "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), "", None + ) + ) ]; } while |implBodyImplementingOtherTraits| > 0 { @@ -604,7 +620,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { fn clone(&self) -> Box { Test::_clone(self.as_ref()) } - }*/ + } + impl DafnyPrint for Box { + fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { + self._fmt_print(f, in_seq) + } + } + */ s := s + [ R.ImplDecl( R.ImplFor( @@ -618,7 +640,20 @@ module {:extern "DCOMP"} DafnyToRustCompiler { Some(R.SelfOwned), "", Some(traitFullExpr.FSel("_clone").Apply1(R.self.Sel("as_ref").Apply0())) - ))]))]; + ))])), + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.DafnyPrint, + R.Box(R.DynType(traitFulltype)), + [R.FnDecl( + R.PRIV, + R.Fn("fmt_print", [], fmt_print_parameters, + Some(fmt_print_result), + "", + Some(traitFullExpr.FSel("_fmt_print").Apply([R.self.Sel("as_ref").Apply0(), R.Identifier("_formatter"), R.Identifier("in_seq")])) + ))])) + ]; } s := s + upcastImplemented; } @@ -722,10 +757,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { [R.FnDecl( R.PRIV, R.Fn("fmt_print", [], - [ R.Formal.selfBorrowed, - R.Formal("_formatter", R.BorrowedMut(R.std.MSel("fmt").MSel("Formatter").AsType())), - R.Formal("in_seq", R.Type.Bool)], - Some(R.std.MSel("fmt").MSel("Result").AsType()), + fmt_print_parameters, + Some(fmt_print_result), "", Some(R.dafny_runtime.MSel("DafnyPrint").AsExpr().FSel("fmt_print").Apply( [ R.Borrow(R.self.Sel("0")), @@ -1137,11 +1170,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { writeStr("") else R.UnaryOp("?", - R.dafny_runtime.MSel("DafnyPrint").AsExpr().FSel("fmt_print").Apply([ - R.Identifier(patternName), - R.Identifier("_formatter"), - R.LiteralBool(false) - ]), Format.UnaryOpFormat.NoFormat) + R.dafny_runtime.MSel("DafnyPrint").AsExpr().FSel("fmt_print").Apply( + [ + R.Identifier(patternName), + R.Identifier("_formatter"), + R.LiteralBool(false) + ]), Format.UnaryOpFormat.NoFormat) ); var coerceRhsArg: R.Expr; @@ -1890,7 +1924,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - @IsolateAssertions @ResourceLimit("1e6") method GenOwnedCallPart(ghost e: Expression, on: Expression, selfIdent: SelfInfo, name: CallName, typeArgs: seq, args: seq, env: Environment) returns (r: R.Expr, readIdents: set) requires forall a <- args :: a < e requires on < e diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index 91ec4d5e527..3312ed7a766 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -2211,7 +2211,10 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite if (!Attributes.Contains(method.Attributes, "extern") && canRedeclareMemberDefinedInTrait) { Contract.Assert(method.Body != null); - var w = classWriter.CreateMethod(method, CombineAllTypeArguments(member), true, true, false); + var typeArguments = InstanceMethodsCanOnlyCallOverridenTraitMethods ? + new List() + : CombineAllTypeArguments(member); + var w = classWriter.CreateMethod(method, typeArguments, true, true, false); var wBefore = w.Fork(); var wCall = w.Fork(); var wAfter = w; diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 91e9d5e298e..a7df066a6de 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -335,7 +335,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } } if ((_7_traitType).is_GeneralTrait) { - _12_body = Dafny.Sequence.Concat(_12_body, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_13_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))))); + _12_body = Dafny.Sequence.Concat(_12_body, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_13_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq"))))))))); } else { if (((kind).Equals(Dafny.Sequence.UnicodeFromString("datatype"))) || ((kind).Equals(Dafny.Sequence.UnicodeFromString("newtype")))) { RAST._IExpr _16_dummy; @@ -553,7 +553,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _12_implBody = _out3; _13_implBodyImplementingOtherTraits = _out4; if (((t).dtor_traitType).is_GeneralTrait) { - _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())))); + _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())))); } while ((new BigInteger((_13_implBodyImplementingOtherTraits).Count)).Sign == 1) { Dafny.ISequence> _14_otherTrait; @@ -609,7 +609,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_rTypeParamsDecls, _10_traitFulltype, _17_parents, _12_implBody))); if (((t).dtor_traitType).is_GeneralTrait) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); } s = Dafny.Sequence.Concat(s, _18_upcastImplemented); return s; @@ -711,7 +711,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } after_match1: ; s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _8_resultingType, Dafny.Sequence.FromElements(_16_body))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsType(), _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Target"), _4_wrappedType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("deref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(((RAST.Path.create_Self()).MSel(Dafny.Sequence.UnicodeFromString("Target"))).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_from_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("o"), RAST.Type.create_Borrowed(_4_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("transmute"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("o"))))))))))))); Dafny.ISequence _23_rTypeParamsDeclsWithHash; diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index a8768c459ef..c0636c9e99a 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -561,6 +561,12 @@ public static Dafny.ISequence DAFNY__EXTERN__MODULE { get { public static Dafny.IMap> OpTable { get { return Dafny.Map>.FromElements(new Dafny.Pair>(DAST.BinOp.create_Mod(), Dafny.Sequence.UnicodeFromString("%")), new Dafny.Pair>(DAST.BinOp.create_And(), Dafny.Sequence.UnicodeFromString("&&")), new Dafny.Pair>(DAST.BinOp.create_Or(), Dafny.Sequence.UnicodeFromString("||")), new Dafny.Pair>(DAST.BinOp.create_Div(false), Dafny.Sequence.UnicodeFromString("/")), new Dafny.Pair>(DAST.BinOp.create_Lt(), Dafny.Sequence.UnicodeFromString("<")), new Dafny.Pair>(DAST.BinOp.create_LtChar(), Dafny.Sequence.UnicodeFromString("<")), new Dafny.Pair>(DAST.BinOp.create_Plus(false), Dafny.Sequence.UnicodeFromString("+")), new Dafny.Pair>(DAST.BinOp.create_Minus(false), Dafny.Sequence.UnicodeFromString("-")), new Dafny.Pair>(DAST.BinOp.create_Times(false), Dafny.Sequence.UnicodeFromString("*")), new Dafny.Pair>(DAST.BinOp.create_BitwiseAnd(), Dafny.Sequence.UnicodeFromString("&")), new Dafny.Pair>(DAST.BinOp.create_BitwiseOr(), Dafny.Sequence.UnicodeFromString("|")), new Dafny.Pair>(DAST.BinOp.create_BitwiseXor(), Dafny.Sequence.UnicodeFromString("^")), new Dafny.Pair>(DAST.BinOp.create_BitwiseShiftRight(), Dafny.Sequence.UnicodeFromString(">>")), new Dafny.Pair>(DAST.BinOp.create_BitwiseShiftLeft(), Dafny.Sequence.UnicodeFromString("<<"))); } } + public static Dafny.ISequence fmt__print__parameters { get { + return Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("in_seq"), RAST.Type.create_Bool())); + } } + public static RAST._IType fmt__print__result { get { + return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType(); + } } } public interface _IOwnership { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy index d8566ea8827..48972db20ff 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy @@ -28,6 +28,19 @@ datatype {:rust_rc false} ADatatype extends DatatypeOps = ADatatype(i: int) function GetInt(): int { i } } +method StaticWithGenerics(c: bool, a: T, b: T) returns (t: T){ + if c { + t := a; + } else { + t := b; + } +} +function StaticWithGenericsFn(c: bool, a: T, b: T): (t: T){ + if c then a else b +} + +//datatype TraitWrapper = TraitWrapper(d: DatatypeOps) {} + method Main() { var x := ADatatype(2); expect x.GetInt() == 2; @@ -57,5 +70,14 @@ method Main() { var zx := x as SuperTrait; expect zx.GetBool(); expect !zy.GetBool(); + var xory1a := StaticWithGenerics(true, x, y); + var xory1b := StaticWithGenerics(false, x, y); + var xory1c := StaticWithGenericsFn(true, x, y); + var xory1d := StaticWithGenericsFn(false, x, y); + expect xory1a == x == xory1c; + //expect xory1b == y == xory1d; + print x1, "\n"; // Ensure we can print even if behind trait + //print TraitWrapper(x1) == TraitWrapper(x1), "\n"; // True + //print TraitWrapper(x1) == TraitWrapper(y1), "\n"; // False print "Main passed all the tests"; } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect index f896bad9217..27a4040c29a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect @@ -1,3 +1,4 @@ Dafny program verifier finished with 4 verified, 0 errors +ADatatype.ADatatype(2) Main passed all the tests \ No newline at end of file From 69cfd0b2e1ced4be3df95e44c92939f90c643585 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 2 Dec 2024 08:45:00 +0100 Subject: [PATCH 14/69] Removed support for default Fixed support for hashing and equality for traits overrides Support for static functions and methods --- .../Rust/Dafny-compiler-rust-definitions.dfy | 83 ++++++++++- .../Backends/Rust/Dafny-compiler-rust.dfy | 131 ++++++++++++++---- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 40 +++--- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 35 ++++- .../LitTest/comp/rust/traits-datatypes.dfy | 18 +-- .../comp/rust/traits-datatypes.dfy.expect | 2 + 6 files changed, 239 insertions(+), 70 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 96f2723721e..c46a5213733 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -536,7 +536,6 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { coerceTypes: seq, coerceImplBody: R.Expr ): R.ModDecl { - R.ImplDecl( R.Impl( rTypeParamsDecls, @@ -595,14 +594,90 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { [R.FnDecl( R.PRIV, R.Fn( - "hash", [R.TypeParamDecl("_H", [R.std.MSel("hash").MSel("Hasher").AsType()])], - [R.Formal.selfBorrowed, - R.Formal("_state", R.BorrowedMut(R.TIdentifier("_H")))], + "hash", hash_type_parameters, + hash_parameters, None, "", Some(hashImplBody)))] )) } + const hash_type_parameters := [R.TypeParamDecl("_H", [R.std.MSel("hash").MSel("Hasher").AsType()])] + const hash_parameters := [ + R.Formal.selfBorrowed, + R.Formal("_state", R.BorrowedMut(R.TIdentifier("_H")))] + const hash_function := R.std.MSel("hash").MSel("Hash").AsExpr().FSel("hash") + /** + fn _hash(&self) -> u64 { + let mut hasher = ::std::hash::DefaultHasher::new(); + self.hash(&mut hasher); + hasher.finish() + } */ + const hasher_trait := + R.FnDecl( + R.PRIV, + R.Fn( + "_hash", [], [R.Formal.selfBorrowed], Some(R.Type.U64), + "", + Some( + R.DeclareVar(R.MUT, "hasher", None, Some(R.std.MSel("hash").MSel("DefaultHasher").AsExpr().FSel("new").Apply0())).Then( + R.self.Sel("hash").Apply1(R.UnaryOp("&mut", R.Identifier("hasher"), Format.UnaryOpFormat.NoFormat)).Then( + R.Identifier("hasher").Sel("finish").Apply0() + ) + ) + ))) + + /** + fn _eq(&self, other: &Box) -> bool { + Test::_as_any(other.as_ref()).downcast_ref::().map_or(false, |x| self == x) + } */ + function eq_trait(fullTraitPath: R.Type, fullTraitExpr: R.Expr): R.ImplMember { + R.FnDecl( + R.PRIV, + R.Fn( + "_eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.Borrowed(R.Box(R.DynType(fullTraitPath))))], Some(R.Type.Bool), + "", + Some( + fullTraitExpr.FSel("_as_any").Apply1(R.Identifier("other").Sel("as_ref").Apply0()).Sel("downcast_ref").ApplyType([R.SelfOwned]).Apply0().Sel("map_or").Apply( + [ + R.LiteralBool(false), + R.Lambda([R.Formal("x", R.RawType("_"))], None, R.BinaryOp("==", R.self, R.Identifier("x"), Format.BinaryOpFormat.NoFormat)) + ] + ) + ))) + } + + function clone_trait(fullTraitPath: R.Type): R.ImplMember { + R.FnDecl( + R.PRIV, + R.Fn( + "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(fullTraitPath))), + "", + Some(R.BoxNew(R.self.Sel("clone").Apply0())))) + } + + /** + fn _fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { + self.fmt_print(f, in_seq) + } */ + const print_trait := + R.FnDecl( + R.PRIV, + R.Fn( + "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), + "", + Some(R.self.Sel("fmt_print").Apply([R.Identifier("_formatter"), R.Identifier("in_seq")])))) + + /** + fn _as_any(&self) -> &dyn ::std::any::Any { + self + } */ + const as_any_trait := + R.FnDecl( + R.PRIV, + R.Fn( + "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.std.MSel("any").MSel("Any").AsType()))), + "", + Some(R.self))) function UnaryOpsImpl( op: char, diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 7d4823a80a9..5eceb0ae63f 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -276,6 +276,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var fullTraitPath := R.TypeApp(pathType, typeArgs); + var fullTraitExpr := path.AsExpr().ApplyType(typeArgs); if !extern.NoExtern? { // An extern of some kind // Either the Dafny code implements all the methods of the trait or none, if |body| == 0 && |properMethods| != 0 { @@ -294,7 +295,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // Extern type, we assume } if traitType.GeneralTrait? { - // Two more methods: Cloning when boxed and printing when boxed + // More methods: Cloning, printing, hashing, equality when boxed /*impl Test for Wrapper { ... fn _clone(&self) -> Box { @@ -303,20 +304,24 @@ module {:extern "DCOMP"} DafnyToRustCompiler { fn _fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { self.fmt_print(f, in_seq) } + fn _hash(&self) -> u64 { + let mut hasher = ::std::hash::DefaultHasher::new(); + self.hash(&mut hasher); + hasher.finish() + } + fn _eq(&self, other: &Box>) -> bool { + other._as_any().downcast_ref::().map_or(false, |x| self == x) + } + fn _as_any(&self) -> &dyn ::std::any::Any { + self + } }*/ body := body + [ - R.FnDecl( - R.PRIV, - R.Fn( - "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(fullTraitPath))), - "", - Some(R.BoxNew(R.self.Sel("clone").Apply0())))), - R.FnDecl( - R.PRIV, - R.Fn( - "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), - "", - Some(R.self.Sel("fmt_print").Apply([R.Identifier("_formatter"), R.Identifier("in_seq")])))) + clone_trait(fullTraitPath), + print_trait, + hasher_trait, + eq_trait(fullTraitPath, fullTraitExpr), + as_any_trait ]; } else { if kind == "datatype" || kind == "newtype" { @@ -333,9 +338,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { )); s := s + [x]; - var upcastTraitToImplement, upcastTraitFn; if traitType.GeneralTrait? { - upcastTraitToImplement, upcastTraitFn := "UpcastBox", "UpcastStructBoxFn!"; s := s + [ R.ImplDecl( R.ImplFor( @@ -557,6 +560,25 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Fn( "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), "", None ) + ), + R.FnDecl( + R.PRIV, + R.Fn( + "_hash", [], [R.Formal.selfBorrowed], Some(R.Type.U64), "", None + ) + ), + R.FnDecl( + R.PRIV, + R.Fn( + "_eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.Borrowed(R.Box(R.DynType(traitFulltype))))], + Some(R.Bool), "", None + ) + ), + R.FnDecl( + R.PRIV, + R.Fn( + "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.std.MSel("any").MSel("Any").AsType()))), "", None + ) ) ]; } @@ -616,18 +638,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { implBody ))]; if t.traitType.GeneralTrait? { - /*impl Clone for Box { - fn clone(&self) -> Box { - Test::_clone(self.as_ref()) - } - } - impl DafnyPrint for Box { - fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { - self._fmt_print(f, in_seq) - } - } - */ s := s + [ + /*impl Clone for Box { + fn clone(&self) -> Box { + Test::_clone(self.as_ref()) + } + }*/ R.ImplDecl( R.ImplFor( rTypeParamsDecls, @@ -641,6 +657,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { "", Some(traitFullExpr.FSel("_clone").Apply1(R.self.Sel("as_ref").Apply0())) ))])), + /* + impl DafnyPrint for Box { + fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result { + self._fmt_print(f, in_seq) + } + }*/ R.ImplDecl( R.ImplFor( rTypeParamsDecls, @@ -652,6 +674,55 @@ module {:extern "DCOMP"} DafnyToRustCompiler { Some(fmt_print_result), "", Some(traitFullExpr.FSel("_fmt_print").Apply([R.self.Sel("as_ref").Apply0(), R.Identifier("_formatter"), R.Identifier("in_seq")])) + ))])), + /* + impl PartialEq for Box { + fn eq(&self, other: &Self) -> bool { + Test::_eq(self.as_ref(), other) + } + } + impl Eq for Box {} + */ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.std.MSel("cmp").MSel("PartialEq").AsType(), + R.Box(R.DynType(traitFulltype)), + [R.FnDecl( + R.PRIV, + R.Fn("eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.SelfBorrowed)], + Some(R.Bool), + "", + Some(traitFullExpr.FSel("_eq").Apply([R.self.Sel("as_ref").Apply0(), R.Identifier("other")])) + ))])), + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.std.MSel("cmp").MSel("Eq").AsType(), + R.Box(R.DynType(traitFulltype)), + [])), + /* + impl Hash + for Box { + fn hash<_H: Hasher>(&self, _state: &mut _H) { + Test::_hash(self.as_ref()).hash(_state) + Hash::hash(&Test::_hash(self.as_ref()), _state) + } + } + */ + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.Hash, + R.Box(R.DynType(traitFulltype)), + [R.FnDecl( + R.PRIV, + R.Fn( + "hash", hash_type_parameters, + hash_parameters, + None, + "", + Some(hash_function.Apply([R.Borrow(traitFullExpr.FSel("_hash").Apply1(R.self.Sel("as_ref").Apply0())), R.Identifier("_state")])) ))])) ]; } @@ -804,7 +875,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { HashImpl( rTypeParamsDeclsWithHash, resultingType, - R.Identifier("self").Sel("0").Sel("hash").Apply1(R.Identifier("_state")) + hash_function.Apply([R.Borrow(R.Identifier("self").Sel("0")), R.Identifier("_state")]) )]; if c.range.HasArithmeticOperations() { s := s + [ @@ -880,7 +951,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { match t case UserDefined(_) => true // ResolvedTypes are assumed to support equality case Tuple(ts) => forall t <- ts :: TypeIsEq(t) - case Array(t, _) => TypeIsEq(t) + case Array(t, _) => true // Reference equality case Seq(t) => TypeIsEq(t) case Set(t) => TypeIsEq(t) case Multiset(t) => TypeIsEq(t) @@ -1157,7 +1228,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if formalType.Arrow? then hashRhs.Then(R.LiteralInt("0").Sel("hash").Apply1(R.Identifier("_state"))) else - hashRhs.Then(R.std.MSel("hash").MSel("Hash").AsExpr().FSel("hash").Apply([R.Identifier(patternName), R.Identifier("_state")])); + hashRhs.Then(hash_function.Apply([R.Identifier(patternName), R.Identifier("_state")])); ctorMatchInner := ctorMatchInner + patternName + ", "; @@ -1316,7 +1387,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var fullType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); // Implementation of Default trait when c supports equality - if cIsEq { + if false && cIsEq { s := s + [R.ImplDecl( R.ImplFor( diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index a7df066a6de..35b825af86c 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -322,38 +322,34 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } RAST._IType _13_fullTraitPath; _13_fullTraitPath = RAST.Type.create_TypeApp(_10_pathType, _11_typeArgs); + RAST._IExpr _14_fullTraitExpr; + _14_fullTraitExpr = ((_9_path).AsExpr()).ApplyType(_11_typeArgs); if (!((@extern).is_NoExtern)) { if (((new BigInteger((_12_body).Count)).Sign == 0) && ((new BigInteger((_8_properMethods).Count)).Sign != 0)) { goto continue_0; } if ((new BigInteger((_12_body).Count)) != (new BigInteger((_8_properMethods).Count))) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the "), kind), Dafny.Sequence.UnicodeFromString(" ")), RAST.__default.SeqToString>(_5_traitPath, ((System.Func, Dafny.ISequence>)((_14_s) => { - return ((_14_s)); -})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_13_fullTraitPath)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" are marked {:extern} and some are not.")), Dafny.Sequence.UnicodeFromString(" For the Rust compiler, please make all methods (")), RAST.__default.SeqToString>(_8_properMethods, ((System.Func, Dafny.ISequence>)((_15_s) => { - return (_15_s); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the "), kind), Dafny.Sequence.UnicodeFromString(" ")), RAST.__default.SeqToString>(_5_traitPath, ((System.Func, Dafny.ISequence>)((_15_s) => { + return ((_15_s)); +})), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_13_fullTraitPath)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" are marked {:extern} and some are not.")), Dafny.Sequence.UnicodeFromString(" For the Rust compiler, please make all methods (")), RAST.__default.SeqToString>(_8_properMethods, ((System.Func, Dafny.ISequence>)((_16_s) => { + return (_16_s); })), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(") bodiless and mark as {:extern} and implement them in a Rust file, ")), Dafny.Sequence.UnicodeFromString("or mark none of them as {:extern} and implement them in Dafny. ")), Dafny.Sequence.UnicodeFromString("Alternatively, you can insert an intermediate trait that performs the partial implementation if feasible."))); } } if ((_7_traitType).is_GeneralTrait) { - _12_body = Dafny.Sequence.Concat(_12_body, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_13_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq"))))))))); + _12_body = Dafny.Sequence.Concat(_12_body, Dafny.Sequence.FromElements(Defs.__default.clone__trait(_13_fullTraitPath), Defs.__default.print__trait, Defs.__default.hasher__trait, Defs.__default.eq__trait(_13_fullTraitPath, _14_fullTraitExpr), Defs.__default.as__any__trait)); } else { if (((kind).Equals(Dafny.Sequence.UnicodeFromString("datatype"))) || ((kind).Equals(Dafny.Sequence.UnicodeFromString("newtype")))) { - RAST._IExpr _16_dummy; + RAST._IExpr _17_dummy; RAST._IExpr _out3; _out3 = (this).Error(Dafny.Sequence.UnicodeFromString("Cannot extend non-general traits"), (this).InitEmptyExpr()); - _16_dummy = _out3; + _17_dummy = _out3; } } - RAST._IModDecl _17_x; - _17_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _13_fullTraitPath, RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), _12_body)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_17_x)); - Dafny.ISequence _18_upcastTraitToImplement = Dafny.Sequence.Empty; - Dafny.ISequence _19_upcastTraitFn = Dafny.Sequence.Empty; + RAST._IModDecl _18_x; + _18_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _13_fullTraitPath, RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), _12_body)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_18_x)); if ((_7_traitType).is_GeneralTrait) { - Dafny.ISequence _rhs0 = Dafny.Sequence.UnicodeFromString("UpcastBox"); - Dafny.ISequence _rhs1 = Dafny.Sequence.UnicodeFromString("UpcastStructBoxFn!"); - _18_upcastTraitToImplement = _rhs0; - _19_upcastTraitFn = _rhs1; s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_13_fullTraitPath)), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_13_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((_9_path).AsExpr()).ApplyType(_11_typeArgs)).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(RAST.__default.self))))))))); } else { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_13_fullTraitPath))), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_13_fullTraitPath))))))))); @@ -553,7 +549,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _12_implBody = _out3; _13_implBodyImplementingOtherTraits = _out4; if (((t).dtor_traitType).is_GeneralTrait) { - _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())))); + _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), 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.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType()))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())))); } while ((new BigInteger((_13_implBodyImplementingOtherTraits).Count)).Sign == 1) { Dafny.ISequence> _14_otherTrait; @@ -609,7 +605,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_rTypeParamsDecls, _10_traitFulltype, _17_parents, _12_implBody))); if (((t).dtor_traitType).is_GeneralTrait) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialEq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.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(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_eq"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Eq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.Hash, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_hash"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))))))))); } s = Dafny.Sequence.Concat(s, _18_upcastImplemented); return s; @@ -716,7 +712,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_from_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("o"), RAST.Type.create_Borrowed(_4_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("transmute"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("o"))))))))))))); Dafny.ISequence _23_rTypeParamsDeclsWithHash; _23_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_23_rTypeParamsDeclsWithHash, _8_resultingType, (((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))).Sel(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_23_rTypeParamsDeclsWithHash, _8_resultingType, (Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))))); if (((c).dtor_range).HasArithmeticOperations()) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.OpsImpl(new Dafny.Rune('+'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('-'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('*'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('/'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.PartialOrdImpl(_2_rTypeParamsDecls, _8_resultingType, _7_newtypeName))); } @@ -816,7 +812,7 @@ public bool TypeIsEq(DAST._IType t) { { if (_source0.is_Array) { DAST._IType _3_t = _source0.dtor_element; - return (this).TypeIsEq(_3_t); + return true; } } { @@ -1200,7 +1196,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) if ((_84_formalType).is_Arrow) { _77_hashRhs = (_77_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); } else { - _77_hashRhs = (_77_hashRhs).Then((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hash"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("hash"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_83_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); + _77_hashRhs = (_77_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_83_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); } _80_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_80_ctorMatchInner, _83_patternName), Dafny.Sequence.UnicodeFromString(", ")); if ((_81_j).Sign == 1) { @@ -1296,7 +1292,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _105_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); RAST._IType _106_fullType; _106_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams); - if (_67_cIsEq) { + if ((false) && (_67_cIsEq)) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_105_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, _106_fullType, 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(_106_fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_101_structName, _102_structAssignments))))))))); } s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsType()).Apply1(_106_fullType), _106_fullType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfBorrowed), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self)))))))); diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index c0636c9e99a..6028ecc89bd 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -486,7 +486,14 @@ public static RAST._IModDecl SingletonsImpl(Dafny.ISequence rTypeParamsDeclsWithHash, RAST._IType datatypeOrNewtypeType, RAST._IExpr hashImplBody) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithHash, RAST.__default.Hash, datatypeOrNewtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Dafny.Sequence.FromElements(RAST.TypeParamDecl.create(Dafny.Sequence.UnicodeFromString("_H"), Dafny.Sequence.FromElements((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hasher"))).AsType()))), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_state"), RAST.Type.create_BorrowedMut(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_H"))))), Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(hashImplBody)))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithHash, RAST.__default.Hash, datatypeOrNewtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(hashImplBody)))))); + } + public static RAST._IImplMember eq__trait(RAST._IType fullTraitPath, RAST._IExpr fullTraitExpr) + { + return 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.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(fullTraitPath))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((((((fullTraitExpr).FSel(Dafny.Sequence.UnicodeFromString("_as_any"))).Apply1(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())).Sel(Dafny.Sequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(RAST.__default.SelfOwned))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("map_or"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralBool(false), RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("x"), RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("_")))), Std.Wrappers.Option.create_None(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), DAST.Format.BinaryOpFormat.create_NoFormat()))))))); + } + public static RAST._IImplMember clone__trait(RAST._IType fullTraitPath) { + return RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))); } public static RAST._IModDecl UnaryOpsImpl(Dafny.Rune op, Dafny.ISequence rTypeParamsDecls, RAST._IType newtypeType, Dafny.ISequence newtypeConstructor) { @@ -543,6 +550,21 @@ public static Dafny.ISet> reserved__vars { get { public static Dafny.ISequence ASSIGNED__PREFIX { get { return Dafny.Sequence.UnicodeFromString("_set"); } } + public static Dafny.ISequence hash__type__parameters { get { + return Dafny.Sequence.FromElements(RAST.TypeParamDecl.create(Dafny.Sequence.UnicodeFromString("_H"), Dafny.Sequence.FromElements((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hasher"))).AsType()))); + } } + public static Dafny.ISequence hash__parameters { get { + return Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_state"), RAST.Type.create_BorrowedMut(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_H"))))); + } } + public static Dafny.ISequence fmt__print__parameters { get { + return Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("in_seq"), RAST.Type.create_Bool())); + } } + public static RAST._IType fmt__print__result { get { + return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType(); + } } + public static RAST._IImplMember print__trait { get { + return RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq"))))))); + } } public static Dafny.ISequence IND { get { return RAST.__default.IND; } } @@ -561,11 +583,14 @@ public static Dafny.ISequence DAFNY__EXTERN__MODULE { get { public static Dafny.IMap> OpTable { get { return Dafny.Map>.FromElements(new Dafny.Pair>(DAST.BinOp.create_Mod(), Dafny.Sequence.UnicodeFromString("%")), new Dafny.Pair>(DAST.BinOp.create_And(), Dafny.Sequence.UnicodeFromString("&&")), new Dafny.Pair>(DAST.BinOp.create_Or(), Dafny.Sequence.UnicodeFromString("||")), new Dafny.Pair>(DAST.BinOp.create_Div(false), Dafny.Sequence.UnicodeFromString("/")), new Dafny.Pair>(DAST.BinOp.create_Lt(), Dafny.Sequence.UnicodeFromString("<")), new Dafny.Pair>(DAST.BinOp.create_LtChar(), Dafny.Sequence.UnicodeFromString("<")), new Dafny.Pair>(DAST.BinOp.create_Plus(false), Dafny.Sequence.UnicodeFromString("+")), new Dafny.Pair>(DAST.BinOp.create_Minus(false), Dafny.Sequence.UnicodeFromString("-")), new Dafny.Pair>(DAST.BinOp.create_Times(false), Dafny.Sequence.UnicodeFromString("*")), new Dafny.Pair>(DAST.BinOp.create_BitwiseAnd(), Dafny.Sequence.UnicodeFromString("&")), new Dafny.Pair>(DAST.BinOp.create_BitwiseOr(), Dafny.Sequence.UnicodeFromString("|")), new Dafny.Pair>(DAST.BinOp.create_BitwiseXor(), Dafny.Sequence.UnicodeFromString("^")), new Dafny.Pair>(DAST.BinOp.create_BitwiseShiftRight(), Dafny.Sequence.UnicodeFromString(">>")), new Dafny.Pair>(DAST.BinOp.create_BitwiseShiftLeft(), Dafny.Sequence.UnicodeFromString("<<"))); } } - public static Dafny.ISequence fmt__print__parameters { get { - return Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("in_seq"), RAST.Type.create_Bool())); + public static RAST._IExpr hash__function { get { + return ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hash"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("hash")); } } - public static RAST._IType fmt__print__result { get { - return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType(); + public static RAST._IImplMember hasher__trait { get { + return RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("hasher"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("DefaultHasher"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0()))).Then((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&mut"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher")), DAST.Format.UnaryOpFormat.create_NoFormat()))).Then(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher"))).Sel(Dafny.Sequence.UnicodeFromString("finish"))).Apply0()))))); + } } + public static RAST._IImplMember as__any__trait { get { + return RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType()))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self))); } } } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy index 48972db20ff..2666f953c2a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy @@ -39,7 +39,7 @@ function StaticWithGenericsFn(c: bool, a: T, b: T): (t: T){ if c then a else b } -//datatype TraitWrapper = TraitWrapper(d: DatatypeOps) {} +datatype TW = TW(d: DatatypeOps) {} method Main() { var x := ADatatype(2); @@ -70,14 +70,14 @@ method Main() { var zx := x as SuperTrait; expect zx.GetBool(); expect !zy.GetBool(); - var xory1a := StaticWithGenerics(true, x, y); - var xory1b := StaticWithGenerics(false, x, y); - var xory1c := StaticWithGenericsFn(true, x, y); - var xory1d := StaticWithGenericsFn(false, x, y); - expect xory1a == x == xory1c; - //expect xory1b == y == xory1d; + var xory1a := StaticWithGenerics(true, x1, y1); + var xory1b := StaticWithGenerics(false, x1, y1); + var xory1c := StaticWithGenericsFn(true, x1, y1); + var xory1d := StaticWithGenericsFn(false, x1, y1); + expect TW(xory1a) == TW(x1) == TW(xory1c) != TW(y1); // If not wrapped, Dafny complains + expect TW(xory1b) == TW(y1) == TW(xory1d) != TW(x1); print x1, "\n"; // Ensure we can print even if behind trait - //print TraitWrapper(x1) == TraitWrapper(x1), "\n"; // True - //print TraitWrapper(x1) == TraitWrapper(y1), "\n"; // False + print TW(x1) == TW(x1), "\n"; // True + print TW(x1) == TW(y1), "\n"; // False print "Main passed all the tests"; } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect index 27a4040c29a..e70b51fd2b7 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect @@ -1,4 +1,6 @@ Dafny program verifier finished with 4 verified, 0 errors ADatatype.ADatatype(2) +true +false Main passed all the tests \ No newline at end of file From 215f2e3f49109cc2b34d5621bbd94431cabc5aa4 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 2 Dec 2024 09:00:41 +0100 Subject: [PATCH 15/69] Fixed null pointer exception and formatting --- .../Backends/Dafny/DafnyCodeGenerator.cs | 2 +- .../Rust/Dafny-compiler-rust-definitions.dfy | 4 ++-- .../Backends/Rust/Dafny-compiler-rust.dfy | 20 ++++++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 7dea1b4d4a6..3f7046c3d4d 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -597,7 +597,7 @@ public ConcreteSyntaxTree CreateFunction(string name, List formals, Type resultType, IToken tok, bool isStatic, bool createBody, MemberDecl member, bool forBodyInheritance, bool lookasideBody) { - var astTypeArgs = ((Function)member).TypeArgs.Select(typeArg => compiler.GenTypeArgDecl(typeArg)).ToList(); + var astTypeArgs = (member is Function fun ? fun.TypeArgs : Enumerable.Empty()).Select(typeArg => compiler.GenTypeArgDecl(typeArg)).ToList(); var params_ = compiler.GenFormals(formals); diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index c46a5213733..537c5200ce4 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -666,7 +666,7 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), "", Some(R.self.Sel("fmt_print").Apply([R.Identifier("_formatter"), R.Identifier("in_seq")])))) - + /** fn _as_any(&self) -> &dyn ::std::any::Any { self @@ -783,6 +783,6 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { R.Formal.selfBorrowed, R.Formal("_formatter", R.BorrowedMut(R.std.MSel("fmt").MSel("Formatter").AsType())), R.Formal("in_seq", R.Type.Bool)] - + const fmt_print_result := R.std.MSel("fmt").MSel("Result").AsType() } \ No newline at end of file diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 5eceb0ae63f..c0efecffa47 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -700,7 +700,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.std.MSel("cmp").MSel("Eq").AsType(), R.Box(R.DynType(traitFulltype)), - [])), + [])), /* impl Hash for Box { @@ -718,11 +718,11 @@ module {:extern "DCOMP"} DafnyToRustCompiler { [R.FnDecl( R.PRIV, R.Fn( - "hash", hash_type_parameters, - hash_parameters, - None, - "", - Some(hash_function.Apply([R.Borrow(traitFullExpr.FSel("_hash").Apply1(R.self.Sel("as_ref").Apply0())), R.Identifier("_state")])) + "hash", hash_type_parameters, + hash_parameters, + None, + "", + Some(hash_function.Apply([R.Borrow(traitFullExpr.FSel("_hash").Apply1(R.self.Sel("as_ref").Apply0())), R.Identifier("_state")])) ))])) ]; } @@ -1387,7 +1387,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var fullType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); // Implementation of Default trait when c supports equality - if false && cIsEq { + if false && cIsEq { // We don't emit default because datatype defaults are broken. + // - There should be no default when an argument is a lambda + // - There is no possiblity to define witness for datatypes so that we know if it's (0) or (00) + // - General traits don't have defaults but can be wrapped in datatypes and datatypes are assumed to have default values always + // Default values are not used in --enforce-determinism anyway, only placebos values are useful and they are implemented with + // a custom option type. + // Leaving this code here for when datatypes' defaults will be fixed s := s + [R.ImplDecl( R.ImplFor( From ad565332ab6edae3daa458db23979ed7a0352bdb Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 2 Dec 2024 12:31:43 +0100 Subject: [PATCH 16/69] Support for more cases in the first argument --- Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy | 8 ++++---- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 2 +- .../LitTests/LitTest/comp/rust/traits-datatypes.dfy | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index c0efecffa47..4d7c6d6bcc9 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -2032,12 +2032,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // 'on' is going to return an owned version of this box. onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); if onExpr.Identifier? && env.NeedsAsRefForBorrow(onExpr.name) { - onExpr := onExpr.Sel("as_ref").Apply0(); - } else if onExpr.IsBorrow() { - // If the resulting expression is a borrow, e.g. &something(), it means the trait was owned. + onExpr := onExpr.Sel("as_ref").Apply0(); // It's not necessarily the trait, it's usually Box::as_ref or Rc::as_ref + } else if recOwnership.OwnershipBorrowed? && onExpr != R.self { + // If the resulting expression is a borrow, e.g. &something() or datatype.field(), it means the trait was owned. // In our case we want dynamic dispatch, so we need to get the bare reference. // Because "on" is a general trait, we need to call as_ref() instead to get the bare expression - // If the onExpr is an identifier but not "self", we apply the same treatment + // If "on" was a field extraction, then the field is borrowed as well. onExpr := R.std.MSel("convert").MSel("AsRef").AsExpr().FSel("as_ref").Apply1(onExpr); } readIdents := readIdents + recIdents; diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 35b825af86c..473343b466f 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -2315,7 +2315,7 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D _11_recIdents = _out11; if (((_9_onExpr).is_Identifier) && ((env).NeedsAsRefForBorrow((_9_onExpr).dtor_name))) { _9_onExpr = ((_9_onExpr).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); - } else if ((_9_onExpr).IsBorrow()) { + } else if (((_10_recOwnership).is_OwnershipBorrowed) && (!object.Equals(_9_onExpr, RAST.__default.self))) { _9_onExpr = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(_9_onExpr); } readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy index 2666f953c2a..de204551a68 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy @@ -74,6 +74,8 @@ method Main() { var xory1b := StaticWithGenerics(false, x1, y1); var xory1c := StaticWithGenericsFn(true, x1, y1); var xory1d := StaticWithGenericsFn(false, x1, y1); + var tw := TW(x1); + expect tw.d.GetInt() == 2; expect TW(xory1a) == TW(x1) == TW(xory1c) != TW(y1); // If not wrapped, Dafny complains expect TW(xory1b) == TW(y1) == TW(xory1d) != TW(x1); print x1, "\n"; // Ensure we can print even if behind trait From 7786869ae1b72fa3d7fefddd29234ce9c947615e Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 2 Dec 2024 23:04:33 +0100 Subject: [PATCH 17/69] Tested library model for downcasting --- .../DafnyRuntimeRust/src/tests/mod.rs | 74 ++++++++++--------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index 6f04042bd62..866d93b2138 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -925,13 +925,21 @@ mod tests { assert_eq!(resulting_message, message); } + + trait _Downcast_GeneralTrait { + fn _is(&self) -> bool; + fn _as(&self) -> Box; // For trait objects, Object or Ptr instead of Box + } + + + trait _Downcast_ADatatype { + fn _is(&self) -> bool; + fn _as(&self) -> ADatatype; // For trait objects, Object or Ptr instead of Box + } + // Every general trait must declare how to clone a Box of itself - trait GeneralTraitSuper { + trait GeneralTraitSuper: _Downcast_GeneralTrait + _Downcast_ADatatype { fn _clone(&self) -> Box>; - fn _is_GeneralTrait(&self) -> bool; - fn _as_GeneralTrait(&self) -> Box; - fn _is_Datatype(&self) -> bool; - fn _as_Datatype(&self) -> ADatatype; } impl Clone for Box> { fn clone(&self) -> Self { @@ -970,25 +978,25 @@ mod tests { Box::new(self.clone()) as Box } } - impl GeneralTraitSuper for ADatatype { - fn _clone(&self) -> Box> { - Box::new(self.clone()) - } - - fn _is_GeneralTrait(&self) -> bool { + impl _Downcast_ADatatype for ADatatype { + fn _is(&self) -> bool { true } - - fn _as_GeneralTrait(&self) -> Box { - GeneralTrait::_clone(self) + fn _as(&self) -> ADatatype { + self.clone() } - - fn _is_Datatype(&self) -> bool { + } + impl _Downcast_GeneralTrait for ADatatype { + fn _is(&self) -> bool { true } - - fn _as_Datatype(&self) -> ADatatype { - self.clone() + fn _as(&self) -> Box { + GeneralTrait::_clone(self) + } + } + impl GeneralTraitSuper for ADatatype { + fn _clone(&self) -> Box> { + Box::new(self.clone()) } } impl UpcastBox for ADatatype { @@ -1007,20 +1015,20 @@ mod tests { let gt = upcast_box::()(x.clone()); let gts = upcast_box::>()(x.clone()); let gtgts = upcast_box_box::>()(gt.clone()); - assert!(gt._is_Datatype()); - assert!(gts._is_Datatype()); - assert!(gtgts._is_Datatype()); - assert!(gts._is_GeneralTrait()); - assert!(gtgts._is_GeneralTrait()); - assert_eq!(gt._as_Datatype(), x); - assert_eq!(gts._as_Datatype(), x); - assert_eq!(gtgts._as_Datatype(), x); - let gtsgt = gts._as_GeneralTrait(); - let gtgtsgt = gtgts._as_GeneralTrait(); - assert!(gtsgt._is_Datatype()); - assert!(gtgtsgt._is_Datatype()); - assert_eq!(gtsgt._as_Datatype(), x); - assert_eq!(gtsgt._as_Datatype(), x); + assert!(_Downcast_ADatatype::_is(AsRef::as_ref(>))); + assert!(_Downcast_ADatatype::_is(AsRef::as_ref(>s))); + assert!(_Downcast_ADatatype::_is(AsRef::as_ref(>gts))); + assert!(_Downcast_GeneralTrait::_is(AsRef::as_ref(>s))); + assert!(_Downcast_GeneralTrait::_is(AsRef::as_ref(>gts))); + assert_eq!(_Downcast_ADatatype::_as(AsRef::as_ref(>)), x); + assert_eq!(_Downcast_ADatatype::_as(AsRef::as_ref(>s)), x); + assert_eq!(_Downcast_ADatatype::_as(AsRef::as_ref(>gts)), x); + let gtsgt = _Downcast_GeneralTrait::_as(AsRef::as_ref(>s)); + let gtgtsgt = _Downcast_GeneralTrait::_as(AsRef::as_ref(>gts)); + assert!(_Downcast_ADatatype::_is(AsRef::as_ref(>sgt))); + assert!(_Downcast_ADatatype::_is(AsRef::as_ref(>gtsgt))); + assert_eq!(_Downcast_ADatatype::_as(AsRef::as_ref(>sgt)), x); + assert_eq!(_Downcast_ADatatype::_as(AsRef::as_ref(>sgt)), x); } /*impl GeneralTrait for Rc { fn _clone(&self) -> Box { From 7afb3876c6f811a54983c38c028442dc6a44a234 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Wed, 4 Dec 2024 17:59:48 +0100 Subject: [PATCH 18/69] WIP to include all traits --- Makefile | 6 +- Source/DafnyCore/Backends/Dafny/AST.dfy | 53 + .../Rust/Dafny-compiler-rust-definitions.dfy | 96 + .../Rust/Dafny-compiler-rust-rast.dfy | 60 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 164 +- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 96 + Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 1670 +++++++++-------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 24 + Source/DafnyCore/GeneratedFromDafny/RAST.cs | 105 ++ .../DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 28 +- .../DafnyRuntimeRust/src/tests/mod.rs | 5 - .../LitTest/comp/rust/traits-datatypes.dfy | 79 +- .../comp/rust/traits-datatypes.dfy.expect | 3 + 13 files changed, 1584 insertions(+), 805 deletions(-) diff --git a/Makefile b/Makefile index 12aff383063..07389337b05 100644 --- a/Makefile +++ b/Makefile @@ -39,12 +39,12 @@ test: test-dafny: name="$(name)"; \ files=$$(cd "${DIR}"/Source/IntegrationTests/TestFiles/LitTests/LitTest; find . -type f -wholename "*$$name*" | grep -E '\.dfy$$'); \ - count=$$(echo "$$files" | wc -l); \ - echo "$${files}"; \ - if [ "$$count" -eq 0 ]; then \ + if [ -z "$files" ]; then \ echo "No files found matching pattern: $$name"; \ exit 1; \ else \ + count=$$(echo "$$files" | wc -l); \ + echo "$${files}"; \ echo "$$count test files found."; \ for file in $$files; do \ filedir=$$(dirname "$$file"); \ diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 8fae0e88c7b..319a01674c5 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -137,6 +137,59 @@ module {:extern "DAST"} DAST { case _ => false } } + + function GetGeneralTraitType(): (r: Type) + requires IsGeneralTrait() + ensures r.UserDefined? && r.resolved.kind == ResolvedTypeBase.Trait(GeneralTrait) + { + match this { + case UserDefined(ResolvedType(_, _, typeKind, _, _, _)) => + match typeKind { + case SynonymType(typ) => + typ.GetGeneralTraitType() + case _ => this + } + } + } + + predicate IsDatatype() { + match this { + case UserDefined(ResolvedType(_, _, typeKind, _, _, _)) => + match typeKind { + case SynonymType(typ) => + typ.IsDatatype() + case Datatype(_) => true + case _ => false + } + case _ => false + } + } + + function GetDatatypeType(): (r: Type) + requires IsDatatype() + ensures r.UserDefined? && r.resolved.kind.Datatype? + { + match this { + case UserDefined(ResolvedType(_, _, typeKind, _, _, _)) => + match typeKind { + case SynonymType(typ) => + typ.GetDatatypeType() + case _ => this + } + } + } + + // Works well without diamond inheritance. If the case arise, we will need to memoize this function + // or ensure extendedTypes contains all supertypes. + predicate Extends(other: Type) + ensures this.Extends(other) ==> other < this + { + match this { + case UserDefined(ResolvedType(_, _, _, _, _, extendedTypes)) => + other in extendedTypes || exists i | 0 <= i < |extendedTypes| :: extendedTypes[i].Extends(other) + case _ => false + } + } } datatype Variance = diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 537c5200ce4..f4d0153753a 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -785,4 +785,100 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { R.Formal("in_seq", R.Type.Bool)] const fmt_print_result := R.std.MSel("fmt").MSel("Result").AsType() + + /* + pub trait _Downcast_BDatatype { + fn _is(&self) -> bool; + fn _as(&self) -> Rc>; + } */ + function DowncastTraitDeclFor( + rTypeParamsDecls: seq, + fullType: R.Type + ): Option { + var downcast_type :- fullType.ToDowncast(); + Some( + R.TraitDecl( + R.Trait( + rTypeParamsDecls, + downcast_type, + [], + [ R.FnDecl( + R.PRIV, + R.Fn( + "_is", [], + [R.Formal.selfBorrowed], + Some(R.Bool), + "", + None)), + R.FnDecl( + R.PRIV, + R.Fn( + "_as", [], + [R.Formal.selfBorrowed], + Some(fullType), + "", + None)) + ]))) + } + + /* + impl _Downcast_ADatatype for ADatatype { + fn _is(&self) -> bool { + true + } + fn _as(&self) -> ADatatype { + self.clone() + } + } + + impl _Downcast_BDatatype for ADatatype { + fn _is(&self) -> bool { + false + } + fn _as(&self) -> Rc { + panic!("ADatatype is not a BDatatype") + } + } */ + function DowncastImplFor( + rTypeParamsDecls: seq, + typeToDowncastTo: R.Type, + forType: R.Type + ): Option { + var downcast_type :- typeToDowncastTo.ToDowncast(); + var forTypeRaw := if forType.IsRc() then forType.RcUnderlying() else forType; + var sameType := typeToDowncastTo == forType; + var asBody := + if sameType then + var body := R.self.Clone(); + if forType.IsRc() then + R.RcNew(body) + else + body + else + R.Identifier("panic!").Apply1(R.LiteralString(forTypeRaw.ToString("")+" is not a "+typeToDowncastTo.ToString(""), false, true)); + Some( + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + downcast_type, + forType, + [ R.FnDecl( + R.PRIV, + R.Fn( + "_is", [], + [R.Formal.selfBorrowed], + Some(R.Bool), + "", + Some(R.LiteralBool(sameType)))), + R.FnDecl( + R.PRIV, + R.Fn( + "_as", [], + [R.Formal.selfBorrowed], + Some(forType), + "", + Some(asBody))) + ])) + ) + } } \ No newline at end of file diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index b3b97d32a63..dca2144d678 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -596,6 +596,8 @@ module RAST const BoxPath := std.MSel("boxed").MSel("Box") + const BoxType := BoxPath.AsType() + const Ptr := PtrPath.AsExpr() function PtrType(underlying: Type): Type { @@ -638,6 +640,13 @@ module RAST | Self() // Self::... | PMemberSelect(base: Path, name: string) { + static const DowncastPrefix := "_Downcast_" + function ToDowncast(): Path { + match this { + case PMemberSelect(base, name) => PMemberSelect(base, DowncastPrefix + name) + case _ => this + } + } function MSel(name: string): Path { PMemberSelect(this, name) } @@ -693,6 +702,39 @@ module RAST | TSynonym(display: Type, base: Type) | TMetaData(display: Type, nameonly copySemantics: bool, nameonly overflow: bool) { + /** Removes the synonym and metadata elements of a type */ + function RemoveSynonyms(): (t: Type) + ensures t == this || t < this + { + match this { + case TSynonym(display, base) => + display.RemoveSynonyms() + case TMetaData(display, _, _) => + display.RemoveSynonyms() + case _ => + this + } + } + /** Given a type, returns the _Downcast_* prefix version of that type */ + function ToDowncast(): Option { + var t := this.RemoveSynonyms(); + if t.IsRc() then t.RcUnderlying().ToDowncast() else // For Rc-wrapped datatypes + if t.IsBoxDyn() then t.BoxDynUnderlying().ToDowncast() else // For general traits + match t { + case TypeFromPath(path) => Some(TypeFromPath(path.ToDowncast())) + case TypeApp(baseName, arguments) => + var baseNameExpr :- baseName.ToDowncast(); + Some(baseNameExpr.Apply(arguments)) + case TIdentifier(name) => + Some(TIdentifier(Path.DowncastPrefix + name)) + case _ => None + } + } + /** Given a type, returns the _Downcast_* prefix version of that type but suitable to call methods */ + function ToDowncastExpr(): Option { + var tpe :- this.ToDowncast(); + tpe.ToExpr() + } /** Converts Name (the type) to Name:: (the expr) */ function ToExpr(): Option { match this { @@ -1042,14 +1084,30 @@ module RAST } } + /** Returns true if the type has the shape Rc, so that one can extract T = .arguments[0] + * Useful to detect rc-wrapped datatypes */ predicate IsRc() { this.TypeApp? && this.baseName == RcType && |arguments| == 1 } - function RcUnderlying(): Type + function RcUnderlying(): (t: Type) requires IsRc() + ensures t < this { arguments[0] } + + /** Returns true if the type has the shape Box, so that one can extract T = .arguments[0].underlying + * Useful to detect general traits */ + predicate IsBoxDyn() { + this.TypeApp? && this.baseName == BoxType && |arguments| == 1 && arguments[0].DynType? + } + + function BoxDynUnderlying(): (t: Type) + requires IsBoxDyn() + ensures t < this + { + arguments[0].underlying + } } function SystemTupleType(elements: seq): Type { diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 4d7c6d6bcc9..a54a893671f 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -535,7 +535,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var fullPath := containingPath + [Ident.Ident(t.name)]; var name := escapeName(t.name); - var traitFulltype := R.TIdentifier(name).Apply(typeParams); + var traitFullType := R.TIdentifier(name).Apply(typeParams); var traitFullExpr := R.Identifier(name).ApplyType(typeParams); var implBody, implBodyImplementingOtherTraits := GenClassImplBody( t.body, true, @@ -551,7 +551,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.FnDecl( R.PRIV, R.Fn( - "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(traitFulltype))), + "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(traitFullType))), "", None )), @@ -570,7 +570,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.FnDecl( R.PRIV, R.Fn( - "_eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.Borrowed(R.Box(R.DynType(traitFulltype))))], + "_eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.Borrowed(R.Box(R.DynType(traitFullType))))], Some(R.Bool), "", None ) ), @@ -616,7 +616,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplFor( rTypeParamsDecls, R.dafny_runtime.MSel("UpcastBox").AsType().Apply1(R.DynType(parentTpe)), - R.Box(R.DynType(traitFulltype)), + R.Box(R.DynType(traitFullType)), [ R.FnDecl( R.PRIV, R.Fn( @@ -633,10 +633,19 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := [ R.TraitDecl( R.Trait( - rTypeParamsDecls, traitFulltype, + rTypeParamsDecls, traitFullType, parents, implBody ))]; + if |t.parents| > 0 { // We will need to downcast + var instantiatedFullType := R.Box(R.DynType(traitFullType)); + var downcastDefinitionOpt := DowncastTraitDeclFor(rTypeParamsDecls, instantiatedFullType); + if downcastDefinitionOpt.None? { + var dummy := Error("Could not generate downcast definition for " + instantiatedFullType.ToString("")); + } else { + s := s + [downcastDefinitionOpt.value]; + } + } if t.traitType.GeneralTrait? { s := s + [ /*impl Clone for Box { @@ -648,7 +657,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplFor( rTypeParamsDecls, R.std.MSel("clone").MSel("Clone").AsType(), - R.Box(R.DynType(traitFulltype)), + R.Box(R.DynType(traitFullType)), [R.FnDecl( R.PRIV, R.Fn("clone", [], @@ -667,7 +676,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplFor( rTypeParamsDecls, R.DafnyPrint, - R.Box(R.DynType(traitFulltype)), + R.Box(R.DynType(traitFullType)), [R.FnDecl( R.PRIV, R.Fn("fmt_print", [], fmt_print_parameters, @@ -687,7 +696,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplFor( rTypeParamsDecls, R.std.MSel("cmp").MSel("PartialEq").AsType(), - R.Box(R.DynType(traitFulltype)), + R.Box(R.DynType(traitFullType)), [R.FnDecl( R.PRIV, R.Fn("eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.SelfBorrowed)], @@ -699,7 +708,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplFor( rTypeParamsDecls, R.std.MSel("cmp").MSel("Eq").AsType(), - R.Box(R.DynType(traitFulltype)), + R.Box(R.DynType(traitFullType)), [])), /* impl Hash @@ -714,7 +723,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplFor( rTypeParamsDecls, R.Hash, - R.Box(R.DynType(traitFulltype)), + R.Box(R.DynType(traitFullType)), [R.FnDecl( R.PRIV, R.Fn( @@ -987,6 +996,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenDatatype(c: Datatype, path: seq) returns (s: seq) modifies this { + var isRcWrapped := IsRcWrapped(c.attributes); var typeParamsSeq, rTypeParams, rTypeParamsDecls := GenTypeParameters(c.typeParams); var datatypeName, extern := GetName(c.attributes, c.name, "datatypes"); var ctors: seq := []; @@ -999,7 +1009,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var isNumeric := false; if |ctor.args| == 0 { var instantiation := R.StructBuild(R.Identifier(datatypeName).FSel(escapeName(ctor.name)), []); - if IsRcWrapped(c.attributes) { + if isRcWrapped { instantiation := R.RcNew(instantiation); } singletonConstructors := singletonConstructors + [ @@ -1175,6 +1185,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var cIsEq := DatatypeIsEq(c); + var datatypeType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); // Derive PartialEq when c supports equality / derive Clone in all cases s := @@ -1191,9 +1202,25 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.ImplDecl( R.Impl( rTypeParamsDecls, - R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), + datatypeType, implBody ))]; + if |c.superTraitTypes| > 0 { // We will need to downcast + var fullType := if isRcWrapped then R.Rc(datatypeType) else datatypeType; + var downcastDefinitionOpt := DowncastTraitDeclFor(rTypeParamsDecls, fullType); + if downcastDefinitionOpt.None? { + var dummy := Error("Could not generate downcast definition for " + fullType.ToString("")); + } else { + s := s + [downcastDefinitionOpt.value]; + } + var downcastImplementationsOpt := DowncastImplFor(rTypeParamsDecls, fullType, fullType); + if downcastImplementationsOpt.None? { + var dummy := Error("Could not generate downcast implementation for " + fullType.ToString("")); + // TODO: Do all cousin types + } else { + s := s + [downcastImplementationsOpt.value]; + } + } var printImplBodyCases: seq := []; var hashImplBodyCases: seq := []; @@ -1326,7 +1353,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ); // Implementation of Debug and Print traits - var datatypeType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); s := s + [ DebugImpl(rTypeParamsDecls, datatypeType, rTypeParams), PrintImpl(rTypeParamsDecls, datatypeType, rTypeParams, printImplBody) @@ -1342,7 +1368,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if |singletonConstructors| == |c.ctors| { var instantiationType := - if IsRcWrapped(c.attributes) then + if isRcWrapped then R.Rc(datatypeType) else datatypeType; @@ -2001,6 +2027,20 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } + // General borrow include &Box, but for dynamic dispatch we need &dyn Type + function FromGeneralBorrowToSelfBorrow(onExpr: R.Expr, onExprOwnership: Ownership, env: Environment): R.Expr { + if onExpr.Identifier? && env.NeedsAsRefForBorrow(onExpr.name) then + onExpr.Sel("as_ref").Apply0() // It's not necessarily the trait, it's usually Box::as_ref or Rc::as_ref + else if onExprOwnership.OwnershipBorrowed? && onExpr != R.self then + // If the resulting expression is a borrow, e.g. &something() or datatype.field(), it means the trait was owned. + // In our case we want dynamic dispatch, so we need to get the bare reference. + // Because "on" is a general trait, we need to call as_ref() instead to get the bare expression + // If "on" was a field extraction, then the field is borrowed as well. + R.std.MSel("convert").MSel("AsRef").AsExpr().FSel("as_ref").Apply1(onExpr) + else + onExpr + } + method GenOwnedCallPart(ghost e: Expression, on: Expression, selfIdent: SelfInfo, name: CallName, typeArgs: seq, args: seq, env: Environment) returns (r: R.Expr, readIdents: set) requires forall a <- args :: a < e requires on < e @@ -2031,15 +2071,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // The underlying type is a Box, self: Datatype or Rc // 'on' is going to return an owned version of this box. onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); - if onExpr.Identifier? && env.NeedsAsRefForBorrow(onExpr.name) { - onExpr := onExpr.Sel("as_ref").Apply0(); // It's not necessarily the trait, it's usually Box::as_ref or Rc::as_ref - } else if recOwnership.OwnershipBorrowed? && onExpr != R.self { - // If the resulting expression is a borrow, e.g. &something() or datatype.field(), it means the trait was owned. - // In our case we want dynamic dispatch, so we need to get the bare reference. - // Because "on" is a general trait, we need to call as_ref() instead to get the bare expression - // If "on" was a field extraction, then the field is borrowed as well. - onExpr := R.std.MSel("convert").MSel("AsRef").AsExpr().FSel("as_ref").Apply1(onExpr); - } + onExpr := FromGeneralBorrowToSelfBorrow(onExpr, recOwnership, env); readIdents := readIdents + recIdents; } else if base.Newtype? && IsNewtypeCopy(base.range) { // The self type of a newtype that is copy is also copy @@ -3017,12 +3049,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { underlying.Clone() // Auto-borrow allows for implicit code case _ => expr.Clone() } - + method GenExprConvertOther( expr: R.Expr, exprOwnership: Ownership, - fromTpe: Type, - toTpe: Type, + fromTyp: Type, + toTyp: Type, env: Environment, expectedOwnership: Ownership ) returns (r: R.Expr, resultingOwnership: Ownership) @@ -3030,9 +3062,51 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) { r := expr; - var fromTpeGen := GenType(fromTpe, GenTypeContext.default()); - var toTpeGen := GenType(toTpe, GenTypeContext.default()); - var upcastConverter := UpcastConversionLambda(fromTpe, fromTpeGen, toTpe, toTpeGen, map[]); + var fromTpeGen := GenType(fromTyp, GenTypeContext.default()); + var toTpeGen := GenType(toTyp, GenTypeContext.default()); + + var isDatatype := toTyp.IsDatatype(); + var isGeneralTrait := !isDatatype && toTyp.IsGeneralTrait(); + if isDatatype || isGeneralTrait { + var isDowncast := toTyp.Extends(fromTyp); + if isDowncast { + var underlyingType := if isDatatype then toTyp.GetDatatypeType() else toTyp.GetGeneralTraitType(); + var toTpeRaw := GenType(underlyingType, GenTypeContext.default()); + var toTpeRawDowncastOpt: Option := toTpeRaw.ToDowncastExpr(); + if toTpeRawDowncastOpt.Some? { + var newExpr := expr; + if exprOwnership.OwnershipOwned? { + match newExpr { + case Call(Select(Identifier(name), "clone"), arguments) => + if |arguments| == 0 { + newExpr := R.Identifier(name); + if !env.IsBorrowed(name) { + newExpr := R.Borrow(newExpr); + } + } else { + newExpr, resultingOwnership := FromOwnership(newExpr, OwnershipOwned, OwnershipBorrowed); + } + case _ => { + newExpr, resultingOwnership := FromOwnership(newExpr, OwnershipOwned, OwnershipBorrowed); + } + } + } + newExpr := FromGeneralBorrowToSelfBorrow(expr, OwnershipBorrowed, env); + r := toTpeRawDowncastOpt.value.FSel("_as").Apply1(newExpr); + r, resultingOwnership := FromOwnership(r, OwnershipOwned, expectedOwnership); + return; + } else { + r := Error("Could not convert " + toTpeRaw.ToString("") + " to a Downcast trait"); + r, resultingOwnership := FromOwned(r, expectedOwnership); + return; + } + } + } else { + r := Error("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"); + r, resultingOwnership := FromOwned(r, expectedOwnership); + return; + } + var upcastConverter := UpcastConversionLambda(fromTyp, fromTpeGen, toTyp, toTpeGen, map[]); if upcastConverter.Success? { var conversionLambda := upcastConverter.value; if exprOwnership == OwnershipBorrowed { @@ -4008,15 +4082,33 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := recIdents; return; } - case Is(expr, fromType, toType) => { + case Is(expr, fromTyp, toTyp) => { var expr, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); - var fromType := GenType(fromType, GenTypeContext.default()); - var toType := GenType(toType, GenTypeContext.default()); - if fromType.IsObjectOrPointer() && toType.IsObjectOrPointer() { - r := expr.Sel("is_instance_of").ApplyType([toType.ObjectOrPointerUnderlying()]).Apply0(); + var fromTpe := GenType(fromTyp, GenTypeContext.default()); + var toTpe := GenType(toTyp, GenTypeContext.default()); + if fromTpe.IsObjectOrPointer() && toTpe.IsObjectOrPointer() { + r := expr.Sel("is_instance_of").ApplyType([toTpe.ObjectOrPointerUnderlying()]).Apply0(); } else { - r := Error("Source and/or target types of type test is/are not Object or Ptr"); - readIdents := {}; + var isDatatype := toTyp.IsDatatype(); + var isGeneralTrait := !isDatatype && toTyp.IsGeneralTrait(); + if isDatatype || isGeneralTrait { // TODO: Detect downcast/upcast + var isDowncast := toTyp.Extends(fromTyp); + if isDowncast { + var underlyingType := if isDatatype then toTyp.GetDatatypeType() else toTyp.GetGeneralTraitType(); + var toTpeRaw := GenType(underlyingType, GenTypeContext.default()); + var toTpeRawDowncastOpt: Option := toTpeRaw.ToDowncastExpr(); + if toTpeRawDowncastOpt.Some? { + r := toTpeRawDowncastOpt.value.FSel("_is").Apply1(expr); + recOwned := OwnershipOwned(); + } else { + r := Error("Could not convert " + toTpeRaw.ToString("") + " to a Downcast trait"); + } + } else { + r := Error("Needs support for upcasting general traits"); + } + } else { + r := Error("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"); + } } r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); readIdents := recIdents; diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 43a70d575a8..b9f348d558c 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -560,6 +560,10 @@ public interface _IType { DAST._IType Replace(Dafny.IMap mapping); bool IsPrimitiveInt(); bool IsGeneralTrait(); + DAST._IType GetGeneralTraitType(); + bool IsDatatype(); + DAST._IType GetDatatypeType(); + bool Extends(DAST._IType other); } public abstract class Type : _IType { public Type() { @@ -843,6 +847,98 @@ public bool IsGeneralTrait() { return false; } } + public DAST._IType GetGeneralTraitType() { + _IType _this = this; + TAIL_CALL_START: ; + DAST._IType _source0 = _this; + { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase _0_typeKind = resolved0.dtor_kind; + DAST._IResolvedTypeBase _source1 = _0_typeKind; + { + if (_source1.is_SynonymType) { + DAST._IType _1_typ = _source1.dtor_baseType; + DAST._IType _in0 = _1_typ; + _this = _in0; + ; + goto TAIL_CALL_START; + } + } + { + return _this; + } + } + } + public bool IsDatatype() { + _IType _this = this; + TAIL_CALL_START: ; + DAST._IType _source0 = _this; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase _0_typeKind = resolved0.dtor_kind; + DAST._IResolvedTypeBase _source1 = _0_typeKind; + { + if (_source1.is_SynonymType) { + DAST._IType _1_typ = _source1.dtor_baseType; + DAST._IType _in0 = _1_typ; + _this = _in0; + ; + goto TAIL_CALL_START; + } + } + { + if (_source1.is_Datatype) { + return true; + } + } + { + return false; + } + } + } + { + return false; + } + } + public DAST._IType GetDatatypeType() { + _IType _this = this; + TAIL_CALL_START: ; + DAST._IType _source0 = _this; + { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase _0_typeKind = resolved0.dtor_kind; + DAST._IResolvedTypeBase _source1 = _0_typeKind; + { + if (_source1.is_SynonymType) { + DAST._IType _1_typ = _source1.dtor_baseType; + DAST._IType _in0 = _1_typ; + _this = _in0; + ; + goto TAIL_CALL_START; + } + } + { + return _this; + } + } + } + public bool Extends(DAST._IType other) { + DAST._IType _source0 = this; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + Dafny.ISequence _0_extendedTypes = resolved0.dtor_extendedTypes; + return ((_0_extendedTypes).Contains(other)) || (Dafny.Helpers.Id, DAST._IType, bool>>((_1_extendedTypes, _2_other) => Dafny.Helpers.Quantifier(Dafny.Helpers.IntegerRange(BigInteger.Zero, new BigInteger((_1_extendedTypes).Count)), false, (((_exists_var_0) => { + BigInteger _3_i = (BigInteger)_exists_var_0; + return (((_3_i).Sign != -1) && ((_3_i) < (new BigInteger((_1_extendedTypes).Count)))) && (((_1_extendedTypes).Select(_3_i)).Extends(_2_other)); + }))))(_0_extendedTypes, other)); + } + } + { + return false; + } + } } public class Type_UserDefined : Type { public readonly DAST._IResolvedType _resolved; diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 473343b466f..3fcceccb4fc 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -537,8 +537,8 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _8_fullPath = Dafny.Sequence>.Concat(containingPath, Dafny.Sequence>.FromElements((t).dtor_name)); Dafny.ISequence _9_name; _9_name = Defs.__default.escapeName((t).dtor_name); - RAST._IType _10_traitFulltype; - _10_traitFulltype = (RAST.Type.create_TIdentifier(_9_name)).Apply(_2_typeParams); + RAST._IType _10_traitFullType; + _10_traitFullType = (RAST.Type.create_TIdentifier(_9_name)).Apply(_2_typeParams); RAST._IExpr _11_traitFullExpr; _11_traitFullExpr = (RAST.Expr.create_Identifier(_9_name)).ApplyType(_2_typeParams); Dafny.ISequence _12_implBody; @@ -549,7 +549,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _12_implBody = _out3; _13_implBodyImplementingOtherTraits = _out4; if (((t).dtor_traitType).is_GeneralTrait) { - _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), 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.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType()))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())))); + _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), 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.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType()))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())))); } while ((new BigInteger((_13_implBodyImplementingOtherTraits).Count)).Sign == 1) { Dafny.ISequence> _14_otherTrait; @@ -600,12 +600,26 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_24_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_21_parentTpe)))); if ((_20_parentTyp).IsGeneralTrait()) { - _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_21_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_21_parentTpe))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_23_parentTpeExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); + _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_21_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_21_parentTpe))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_23_parentTpeExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); + } + } + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_rTypeParamsDecls, _10_traitFullType, _17_parents, _12_implBody))); + if ((new BigInteger(((t).dtor_parents).Count)).Sign == 1) { + RAST._IType _25_instantiatedFullType; + _25_instantiatedFullType = RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)); + Std.Wrappers._IOption _26_downcastDefinitionOpt; + _26_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_1_rTypeParamsDecls, _25_instantiatedFullType); + if ((_26_downcastDefinitionOpt).is_None) { + RAST._IExpr _27_dummy; + RAST._IExpr _out7; + _out7 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_25_instantiatedFullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _27_dummy = _out7; + } else { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_26_downcastDefinitionOpt).dtor_value)); } } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_rTypeParamsDecls, _10_traitFulltype, _17_parents, _12_implBody))); if (((t).dtor_traitType).is_GeneralTrait) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialEq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.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(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_eq"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Eq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.Hash, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFulltype)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_hash"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialEq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.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(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_eq"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Eq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.Hash, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_hash"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))))))))); } s = Dafny.Sequence.Concat(s, _18_upcastImplemented); return s; @@ -903,405 +917,436 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) public Dafny.ISequence GenDatatype(DAST._IDatatype c, Dafny.ISequence> path) { Dafny.ISequence s = Dafny.Sequence.Empty; - Dafny.ISequence _0_typeParamsSeq; - Dafny.ISequence _1_rTypeParams; - Dafny.ISequence _2_rTypeParamsDecls; + bool _0_isRcWrapped; + _0_isRcWrapped = (this).IsRcWrapped((c).dtor_attributes); + Dafny.ISequence _1_typeParamsSeq; + Dafny.ISequence _2_rTypeParams; + Dafny.ISequence _3_rTypeParamsDecls; Dafny.ISequence _out0; Dafny.ISequence _out1; Dafny.ISequence _out2; (this).GenTypeParameters((c).dtor_typeParams, out _out0, out _out1, out _out2); - _0_typeParamsSeq = _out0; - _1_rTypeParams = _out1; - _2_rTypeParamsDecls = _out2; - Dafny.ISequence _3_datatypeName; - Defs._IExternAttribute _4_extern; + _1_typeParamsSeq = _out0; + _2_rTypeParams = _out1; + _3_rTypeParamsDecls = _out2; + Dafny.ISequence _4_datatypeName; + Defs._IExternAttribute _5_extern; Dafny.ISequence _out3; Defs._IExternAttribute _out4; (this).GetName((c).dtor_attributes, (c).dtor_name, Dafny.Sequence.UnicodeFromString("datatypes"), out _out3, out _out4); - _3_datatypeName = _out3; - _4_extern = _out4; - Dafny.ISequence _5_ctors; - _5_ctors = Dafny.Sequence.FromElements(); - Dafny.ISequence _6_variances; - _6_variances = Std.Collections.Seq.__default.Map(((System.Func)((_7_typeParamDecl) => { - return (_7_typeParamDecl).dtor_variance; + _4_datatypeName = _out3; + _5_extern = _out4; + Dafny.ISequence _6_ctors; + _6_ctors = Dafny.Sequence.FromElements(); + Dafny.ISequence _7_variances; + _7_variances = Std.Collections.Seq.__default.Map(((System.Func)((_8_typeParamDecl) => { + return (_8_typeParamDecl).dtor_variance; })), (c).dtor_typeParams); - Dafny.ISequence _8_singletonConstructors; - _8_singletonConstructors = Dafny.Sequence.FromElements(); - Dafny.ISet> _9_usedTypeParams; - _9_usedTypeParams = Dafny.Set>.FromElements(); + Dafny.ISequence _9_singletonConstructors; + _9_singletonConstructors = Dafny.Sequence.FromElements(); + Dafny.ISet> _10_usedTypeParams; + _10_usedTypeParams = Dafny.Set>.FromElements(); BigInteger _hi0 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _10_i = BigInteger.Zero; _10_i < _hi0; _10_i++) { - DAST._IDatatypeCtor _11_ctor; - _11_ctor = ((c).dtor_ctors).Select(_10_i); - Dafny.ISequence _12_ctorArgs; - _12_ctorArgs = Dafny.Sequence.FromElements(); - bool _13_isNumeric; - _13_isNumeric = false; - if ((new BigInteger(((_11_ctor).dtor_args).Count)).Sign == 0) { - RAST._IExpr _14_instantiation; - _14_instantiation = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_3_datatypeName)).FSel(Defs.__default.escapeName((_11_ctor).dtor_name)), Dafny.Sequence.FromElements()); - if ((this).IsRcWrapped((c).dtor_attributes)) { - _14_instantiation = RAST.__default.RcNew(_14_instantiation); - } - _8_singletonConstructors = Dafny.Sequence.Concat(_8_singletonConstructors, Dafny.Sequence.FromElements(_14_instantiation)); - } - BigInteger _hi1 = new BigInteger(((_11_ctor).dtor_args).Count); - for (BigInteger _15_j = BigInteger.Zero; _15_j < _hi1; _15_j++) { - DAST._IDatatypeDtor _16_dtor; - _16_dtor = ((_11_ctor).dtor_args).Select(_15_j); - RAST._IType _17_formalType; + for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi0; _11_i++) { + DAST._IDatatypeCtor _12_ctor; + _12_ctor = ((c).dtor_ctors).Select(_11_i); + Dafny.ISequence _13_ctorArgs; + _13_ctorArgs = Dafny.Sequence.FromElements(); + bool _14_isNumeric; + _14_isNumeric = false; + if ((new BigInteger(((_12_ctor).dtor_args).Count)).Sign == 0) { + RAST._IExpr _15_instantiation; + _15_instantiation = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_12_ctor).dtor_name)), Dafny.Sequence.FromElements()); + if (_0_isRcWrapped) { + _15_instantiation = RAST.__default.RcNew(_15_instantiation); + } + _9_singletonConstructors = Dafny.Sequence.Concat(_9_singletonConstructors, Dafny.Sequence.FromElements(_15_instantiation)); + } + BigInteger _hi1 = new BigInteger(((_12_ctor).dtor_args).Count); + for (BigInteger _16_j = BigInteger.Zero; _16_j < _hi1; _16_j++) { + DAST._IDatatypeDtor _17_dtor; + _17_dtor = ((_12_ctor).dtor_args).Select(_16_j); + RAST._IType _18_formalType; RAST._IType _out5; - _out5 = (this).GenType(((_16_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); - _17_formalType = _out5; - _9_usedTypeParams = (this).GatherTypeParamNames(_9_usedTypeParams, _17_formalType); - Dafny.ISequence _18_formalName; - _18_formalName = Defs.__default.escapeVar(((_16_dtor).dtor_formal).dtor_name); - if (((_15_j).Sign == 0) && ((Dafny.Sequence.UnicodeFromString("0")).Equals(_18_formalName))) { - _13_isNumeric = true; - } - if ((((_15_j).Sign != 0) && (_13_isNumeric)) && (!(Std.Strings.__default.OfNat(_15_j)).Equals(_18_formalName))) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Formal extern names were supposed to be numeric but got "), _18_formalName), Dafny.Sequence.UnicodeFromString(" instead of ")), Std.Strings.__default.OfNat(_15_j))); - _13_isNumeric = false; + _out5 = (this).GenType(((_17_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); + _18_formalType = _out5; + _10_usedTypeParams = (this).GatherTypeParamNames(_10_usedTypeParams, _18_formalType); + Dafny.ISequence _19_formalName; + _19_formalName = Defs.__default.escapeVar(((_17_dtor).dtor_formal).dtor_name); + if (((_16_j).Sign == 0) && ((Dafny.Sequence.UnicodeFromString("0")).Equals(_19_formalName))) { + _14_isNumeric = true; + } + if ((((_16_j).Sign != 0) && (_14_isNumeric)) && (!(Std.Strings.__default.OfNat(_16_j)).Equals(_19_formalName))) { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Formal extern names were supposed to be numeric but got "), _19_formalName), Dafny.Sequence.UnicodeFromString(" instead of ")), Std.Strings.__default.OfNat(_16_j))); + _14_isNumeric = false; } if ((c).dtor_isCo) { - _12_ctorArgs = Dafny.Sequence.Concat(_12_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_18_formalName, RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("LazyFieldWrapper"))).AsType(), Dafny.Sequence.FromElements(_17_formalType)))))); + _13_ctorArgs = Dafny.Sequence.Concat(_13_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_19_formalName, RAST.Type.create_TypeApp(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("LazyFieldWrapper"))).AsType(), Dafny.Sequence.FromElements(_18_formalType)))))); } else { - _12_ctorArgs = Dafny.Sequence.Concat(_12_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_18_formalName, _17_formalType)))); + _13_ctorArgs = Dafny.Sequence.Concat(_13_ctorArgs, Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PRIV(), RAST.Formal.create(_19_formalName, _18_formalType)))); } } - RAST._IFields _19_namedFields; - _19_namedFields = RAST.Fields.create_NamedFields(_12_ctorArgs); - if (_13_isNumeric) { - _19_namedFields = (_19_namedFields).ToNamelessFields(); + RAST._IFields _20_namedFields; + _20_namedFields = RAST.Fields.create_NamedFields(_13_ctorArgs); + if (_14_isNumeric) { + _20_namedFields = (_20_namedFields).ToNamelessFields(); } - _5_ctors = Dafny.Sequence.Concat(_5_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Defs.__default.escapeName((_11_ctor).dtor_name), _19_namedFields))); + _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Defs.__default.escapeName((_12_ctor).dtor_name), _20_namedFields))); } - Dafny.ISet> _20_unusedTypeParams; - _20_unusedTypeParams = Dafny.Set>.Difference(Dafny.Helpers.Id, Dafny.ISet>>>((_21_rTypeParamsDecls) => ((System.Func>>)(() => { + Dafny.ISet> _21_unusedTypeParams; + _21_unusedTypeParams = Dafny.Set>.Difference(Dafny.Helpers.Id, Dafny.ISet>>>((_22_rTypeParamsDecls) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); - foreach (RAST._ITypeParamDecl _compr_0 in (_21_rTypeParamsDecls).CloneAsArray()) { - RAST._ITypeParamDecl _22_tp = (RAST._ITypeParamDecl)_compr_0; - if ((_21_rTypeParamsDecls).Contains(_22_tp)) { - _coll0.Add((_22_tp).dtor_name); + foreach (RAST._ITypeParamDecl _compr_0 in (_22_rTypeParamsDecls).CloneAsArray()) { + RAST._ITypeParamDecl _23_tp = (RAST._ITypeParamDecl)_compr_0; + if ((_22_rTypeParamsDecls).Contains(_23_tp)) { + _coll0.Add((_23_tp).dtor_name); } } return Dafny.Set>.FromCollection(_coll0); - }))())(_2_rTypeParamsDecls), _9_usedTypeParams); - Dafny.ISequence> _23_selfPath; - _23_selfPath = Dafny.Sequence>.FromElements((c).dtor_name); - Dafny.ISequence _24_implBodyRaw; - Dafny.IMap>,Dafny.ISequence> _25_traitBodies; + }))())(_3_rTypeParamsDecls), _10_usedTypeParams); + Dafny.ISequence> _24_selfPath; + _24_selfPath = Dafny.Sequence>.FromElements((c).dtor_name); + Dafny.ISequence _25_implBodyRaw; + Dafny.IMap>,Dafny.ISequence> _26_traitBodies; Dafny.ISequence _out6; Dafny.IMap>,Dafny.ISequence> _out7; - (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_23_selfPath, _0_typeParamsSeq, DAST.ResolvedTypeBase.create_Datatype(_6_variances), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _0_typeParamsSeq, out _out6, out _out7); - _24_implBodyRaw = _out6; - _25_traitBodies = _out7; - Dafny.ISequence _26_implBody; - _26_implBody = _24_implBodyRaw; - Dafny.ISet> _27_emittedFields; - _27_emittedFields = Dafny.Set>.FromElements(); + (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_24_selfPath, _1_typeParamsSeq, DAST.ResolvedTypeBase.create_Datatype(_7_variances), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _1_typeParamsSeq, out _out6, out _out7); + _25_implBodyRaw = _out6; + _26_traitBodies = _out7; + Dafny.ISequence _27_implBody; + _27_implBody = _25_implBodyRaw; + Dafny.ISet> _28_emittedFields; + _28_emittedFields = Dafny.Set>.FromElements(); BigInteger _hi2 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _28_i = BigInteger.Zero; _28_i < _hi2; _28_i++) { - DAST._IDatatypeCtor _29_ctor; - _29_ctor = ((c).dtor_ctors).Select(_28_i); - BigInteger _hi3 = new BigInteger(((_29_ctor).dtor_args).Count); - for (BigInteger _30_j = BigInteger.Zero; _30_j < _hi3; _30_j++) { - DAST._IDatatypeDtor _31_dtor; - _31_dtor = ((_29_ctor).dtor_args).Select(_30_j); - Dafny.ISequence _32_callName; - _32_callName = Std.Wrappers.Option>.GetOr((_31_dtor).dtor_callName, Defs.__default.escapeVar(((_31_dtor).dtor_formal).dtor_name)); - if (!((_27_emittedFields).Contains(_32_callName))) { - _27_emittedFields = Dafny.Set>.Union(_27_emittedFields, Dafny.Set>.FromElements(_32_callName)); - RAST._IType _33_formalType; + for (BigInteger _29_i = BigInteger.Zero; _29_i < _hi2; _29_i++) { + DAST._IDatatypeCtor _30_ctor; + _30_ctor = ((c).dtor_ctors).Select(_29_i); + BigInteger _hi3 = new BigInteger(((_30_ctor).dtor_args).Count); + for (BigInteger _31_j = BigInteger.Zero; _31_j < _hi3; _31_j++) { + DAST._IDatatypeDtor _32_dtor; + _32_dtor = ((_30_ctor).dtor_args).Select(_31_j); + Dafny.ISequence _33_callName; + _33_callName = Std.Wrappers.Option>.GetOr((_32_dtor).dtor_callName, Defs.__default.escapeVar(((_32_dtor).dtor_formal).dtor_name)); + if (!((_28_emittedFields).Contains(_33_callName))) { + _28_emittedFields = Dafny.Set>.Union(_28_emittedFields, Dafny.Set>.FromElements(_33_callName)); + RAST._IType _34_formalType; RAST._IType _out8; - _out8 = (this).GenType(((_31_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); - _33_formalType = _out8; - Dafny.ISequence _34_cases; - _34_cases = Dafny.Sequence.FromElements(); + _out8 = (this).GenType(((_32_dtor).dtor_formal).dtor_typ, Defs.GenTypeContext.@default()); + _34_formalType = _out8; + Dafny.ISequence _35_cases; + _35_cases = Dafny.Sequence.FromElements(); BigInteger _hi4 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _35_k = BigInteger.Zero; _35_k < _hi4; _35_k++) { - DAST._IDatatypeCtor _36_ctor2; - _36_ctor2 = ((c).dtor_ctors).Select(_35_k); - Dafny.ISequence _37_pattern; - _37_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), Defs.__default.escapeName((_36_ctor2).dtor_name)); - RAST._IExpr _38_rhs = RAST.Expr.Default(); - Std.Wrappers._IOption> _39_hasMatchingField; - _39_hasMatchingField = Std.Wrappers.Option>.create_None(); - Dafny.ISequence _40_patternInner; - _40_patternInner = Dafny.Sequence.UnicodeFromString(""); - bool _41_isNumeric; - _41_isNumeric = false; - BigInteger _hi5 = new BigInteger(((_36_ctor2).dtor_args).Count); - for (BigInteger _42_l = BigInteger.Zero; _42_l < _hi5; _42_l++) { - DAST._IDatatypeDtor _43_dtor2; - _43_dtor2 = ((_36_ctor2).dtor_args).Select(_42_l); - Dafny.ISequence _44_patternName; - _44_patternName = Defs.__default.escapeVar(((_43_dtor2).dtor_formal).dtor_name); - if (((_42_l).Sign == 0) && ((_44_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _41_isNumeric = true; + for (BigInteger _36_k = BigInteger.Zero; _36_k < _hi4; _36_k++) { + DAST._IDatatypeCtor _37_ctor2; + _37_ctor2 = ((c).dtor_ctors).Select(_36_k); + Dafny.ISequence _38_pattern; + _38_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), Defs.__default.escapeName((_37_ctor2).dtor_name)); + RAST._IExpr _39_rhs = RAST.Expr.Default(); + Std.Wrappers._IOption> _40_hasMatchingField; + _40_hasMatchingField = Std.Wrappers.Option>.create_None(); + Dafny.ISequence _41_patternInner; + _41_patternInner = Dafny.Sequence.UnicodeFromString(""); + bool _42_isNumeric; + _42_isNumeric = false; + BigInteger _hi5 = new BigInteger(((_37_ctor2).dtor_args).Count); + for (BigInteger _43_l = BigInteger.Zero; _43_l < _hi5; _43_l++) { + DAST._IDatatypeDtor _44_dtor2; + _44_dtor2 = ((_37_ctor2).dtor_args).Select(_43_l); + Dafny.ISequence _45_patternName; + _45_patternName = Defs.__default.escapeVar(((_44_dtor2).dtor_formal).dtor_name); + if (((_43_l).Sign == 0) && ((_45_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _42_isNumeric = true; } - if (_41_isNumeric) { - _44_patternName = Std.Wrappers.Option>.GetOr((_43_dtor2).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_42_l))); + if (_42_isNumeric) { + _45_patternName = Std.Wrappers.Option>.GetOr((_44_dtor2).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_43_l))); } - if (object.Equals(((_31_dtor).dtor_formal).dtor_name, ((_43_dtor2).dtor_formal).dtor_name)) { - _39_hasMatchingField = Std.Wrappers.Option>.create_Some(_44_patternName); + if (object.Equals(((_32_dtor).dtor_formal).dtor_name, ((_44_dtor2).dtor_formal).dtor_name)) { + _40_hasMatchingField = Std.Wrappers.Option>.create_Some(_45_patternName); } - _40_patternInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_40_patternInner, _44_patternName), Dafny.Sequence.UnicodeFromString(", ")); + _41_patternInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_41_patternInner, _45_patternName), Dafny.Sequence.UnicodeFromString(", ")); } - if (_41_isNumeric) { - _37_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_37_pattern, Dafny.Sequence.UnicodeFromString("(")), _40_patternInner), Dafny.Sequence.UnicodeFromString(")")); + if (_42_isNumeric) { + _38_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_38_pattern, Dafny.Sequence.UnicodeFromString("(")), _41_patternInner), Dafny.Sequence.UnicodeFromString(")")); } else { - _37_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_37_pattern, Dafny.Sequence.UnicodeFromString("{")), _40_patternInner), Dafny.Sequence.UnicodeFromString("}")); + _38_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_38_pattern, Dafny.Sequence.UnicodeFromString("{")), _41_patternInner), Dafny.Sequence.UnicodeFromString("}")); } - if ((_39_hasMatchingField).is_Some) { + if ((_40_hasMatchingField).is_Some) { if ((c).dtor_isCo) { - _38_rhs = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("deref"))).Apply1(RAST.__default.Borrow((RAST.Expr.create_Identifier((_39_hasMatchingField).dtor_value)).Sel(Dafny.Sequence.UnicodeFromString("0")))); + _39_rhs = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("deref"))).Apply1(RAST.__default.Borrow((RAST.Expr.create_Identifier((_40_hasMatchingField).dtor_value)).Sel(Dafny.Sequence.UnicodeFromString("0")))); } else { - _38_rhs = RAST.Expr.create_Identifier((_39_hasMatchingField).dtor_value); + _39_rhs = RAST.Expr.create_Identifier((_40_hasMatchingField).dtor_value); } } else { - _38_rhs = Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString("field does not exist on this variant")); + _39_rhs = Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString("field does not exist on this variant")); } - RAST._IMatchCase _45_ctorMatch; - _45_ctorMatch = RAST.MatchCase.create(_37_pattern, _38_rhs); - _34_cases = Dafny.Sequence.Concat(_34_cases, Dafny.Sequence.FromElements(_45_ctorMatch)); - } - if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_20_unusedTypeParams).Count)).Sign == 1)) { - _34_cases = Dafny.Sequence.Concat(_34_cases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); - } - RAST._IExpr _46_methodBody; - _46_methodBody = RAST.Expr.create_Match(RAST.__default.self, _34_cases); - _26_implBody = Dafny.Sequence.Concat(_26_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(_32_callName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_33_formalType)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_46_methodBody))))); - } - } - } - Dafny.ISequence _47_coerceTypes; - _47_coerceTypes = Dafny.Sequence.FromElements(); - Dafny.ISequence _48_rCoerceTypeParams; - _48_rCoerceTypeParams = Dafny.Sequence.FromElements(); - Dafny.ISequence _49_coerceArguments; - _49_coerceArguments = Dafny.Sequence.FromElements(); - Dafny.IMap _50_coerceMap; - _50_coerceMap = Dafny.Map.FromElements(); - Dafny.IMap _51_rCoerceMap; - _51_rCoerceMap = Dafny.Map.FromElements(); - Dafny.IMap<_System._ITuple2,RAST._IExpr> _52_coerceMapToArg; - _52_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(); + RAST._IMatchCase _46_ctorMatch; + _46_ctorMatch = RAST.MatchCase.create(_38_pattern, _39_rhs); + _35_cases = Dafny.Sequence.Concat(_35_cases, Dafny.Sequence.FromElements(_46_ctorMatch)); + } + if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { + _35_cases = Dafny.Sequence.Concat(_35_cases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + } + RAST._IExpr _47_methodBody; + _47_methodBody = RAST.Expr.create_Match(RAST.__default.self, _35_cases); + _27_implBody = Dafny.Sequence.Concat(_27_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(_33_callName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_34_formalType)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_47_methodBody))))); + } + } + } + Dafny.ISequence _48_coerceTypes; + _48_coerceTypes = Dafny.Sequence.FromElements(); + Dafny.ISequence _49_rCoerceTypeParams; + _49_rCoerceTypeParams = Dafny.Sequence.FromElements(); + Dafny.ISequence _50_coerceArguments; + _50_coerceArguments = Dafny.Sequence.FromElements(); + Dafny.IMap _51_coerceMap; + _51_coerceMap = Dafny.Map.FromElements(); + Dafny.IMap _52_rCoerceMap; + _52_rCoerceMap = Dafny.Map.FromElements(); + Dafny.IMap<_System._ITuple2,RAST._IExpr> _53_coerceMapToArg; + _53_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(); if ((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) { - Dafny.ISequence _53_types; - _53_types = Dafny.Sequence.FromElements(); + Dafny.ISequence _54_types; + _54_types = Dafny.Sequence.FromElements(); BigInteger _hi6 = new BigInteger(((c).dtor_typeParams).Count); - for (BigInteger _54_typeI = BigInteger.Zero; _54_typeI < _hi6; _54_typeI++) { - DAST._ITypeArgDecl _55_typeParam; - _55_typeParam = ((c).dtor_typeParams).Select(_54_typeI); - DAST._IType _56_typeArg; - RAST._ITypeParamDecl _57_rTypeParamDecl; + for (BigInteger _55_typeI = BigInteger.Zero; _55_typeI < _hi6; _55_typeI++) { + DAST._ITypeArgDecl _56_typeParam; + _56_typeParam = ((c).dtor_typeParams).Select(_55_typeI); + DAST._IType _57_typeArg; + RAST._ITypeParamDecl _58_rTypeParamDecl; DAST._IType _out9; RAST._ITypeParamDecl _out10; - (this).GenTypeParam(_55_typeParam, out _out9, out _out10); - _56_typeArg = _out9; - _57_rTypeParamDecl = _out10; - RAST._IType _58_rTypeArg; + (this).GenTypeParam(_56_typeParam, out _out9, out _out10); + _57_typeArg = _out9; + _58_rTypeParamDecl = _out10; + RAST._IType _59_rTypeArg; RAST._IType _out11; - _out11 = (this).GenType(_56_typeArg, Defs.GenTypeContext.@default()); - _58_rTypeArg = _out11; - _53_types = Dafny.Sequence.Concat(_53_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_58_rTypeArg)))); - if (((_54_typeI) < (new BigInteger((_6_variances).Count))) && (((_6_variances).Select(_54_typeI)).is_Nonvariant)) { - _47_coerceTypes = Dafny.Sequence.Concat(_47_coerceTypes, Dafny.Sequence.FromElements(_58_rTypeArg)); + _out11 = (this).GenType(_57_typeArg, Defs.GenTypeContext.@default()); + _59_rTypeArg = _out11; + _54_types = Dafny.Sequence.Concat(_54_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_59_rTypeArg)))); + if (((_55_typeI) < (new BigInteger((_7_variances).Count))) && (((_7_variances).Select(_55_typeI)).is_Nonvariant)) { + _48_coerceTypes = Dafny.Sequence.Concat(_48_coerceTypes, Dafny.Sequence.FromElements(_59_rTypeArg)); goto continue_2_0; } - DAST._ITypeArgDecl _59_coerceTypeParam; - DAST._ITypeArgDecl _60_dt__update__tmp_h0 = _55_typeParam; - Dafny.ISequence _61_dt__update_hname_h0 = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), Std.Strings.__default.OfNat(_54_typeI)); - _59_coerceTypeParam = DAST.TypeArgDecl.create(_61_dt__update_hname_h0, (_60_dt__update__tmp_h0).dtor_bounds, (_60_dt__update__tmp_h0).dtor_variance); - DAST._IType _62_coerceTypeArg; - RAST._ITypeParamDecl _63_rCoerceTypeParamDecl; + DAST._ITypeArgDecl _60_coerceTypeParam; + DAST._ITypeArgDecl _61_dt__update__tmp_h0 = _56_typeParam; + Dafny.ISequence _62_dt__update_hname_h0 = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), Std.Strings.__default.OfNat(_55_typeI)); + _60_coerceTypeParam = DAST.TypeArgDecl.create(_62_dt__update_hname_h0, (_61_dt__update__tmp_h0).dtor_bounds, (_61_dt__update__tmp_h0).dtor_variance); + DAST._IType _63_coerceTypeArg; + RAST._ITypeParamDecl _64_rCoerceTypeParamDecl; DAST._IType _out12; RAST._ITypeParamDecl _out13; - (this).GenTypeParam(_59_coerceTypeParam, out _out12, out _out13); - _62_coerceTypeArg = _out12; - _63_rCoerceTypeParamDecl = _out13; - _50_coerceMap = Dafny.Map.Merge(_50_coerceMap, Dafny.Map.FromElements(new Dafny.Pair(_56_typeArg, _62_coerceTypeArg))); - RAST._IType _64_rCoerceType; + (this).GenTypeParam(_60_coerceTypeParam, out _out12, out _out13); + _63_coerceTypeArg = _out12; + _64_rCoerceTypeParamDecl = _out13; + _51_coerceMap = Dafny.Map.Merge(_51_coerceMap, Dafny.Map.FromElements(new Dafny.Pair(_57_typeArg, _63_coerceTypeArg))); + RAST._IType _65_rCoerceType; RAST._IType _out14; - _out14 = (this).GenType(_62_coerceTypeArg, Defs.GenTypeContext.@default()); - _64_rCoerceType = _out14; - _51_rCoerceMap = Dafny.Map.Merge(_51_rCoerceMap, Dafny.Map.FromElements(new Dafny.Pair(_58_rTypeArg, _64_rCoerceType))); - _47_coerceTypes = Dafny.Sequence.Concat(_47_coerceTypes, Dafny.Sequence.FromElements(_64_rCoerceType)); - _48_rCoerceTypeParams = Dafny.Sequence.Concat(_48_rCoerceTypeParams, Dafny.Sequence.FromElements(_63_rCoerceTypeParamDecl)); - Dafny.ISequence _65_coerceFormal; - _65_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_54_typeI)); - _52_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_52_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_58_rTypeArg, _64_rCoerceType), (RAST.Expr.create_Identifier(_65_coerceFormal)).Clone()))); - _49_coerceArguments = Dafny.Sequence.Concat(_49_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_65_coerceFormal, RAST.__default.Rc(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_58_rTypeArg), _64_rCoerceType)), RAST.__default.StaticTrait))))); + _out14 = (this).GenType(_63_coerceTypeArg, Defs.GenTypeContext.@default()); + _65_rCoerceType = _out14; + _52_rCoerceMap = Dafny.Map.Merge(_52_rCoerceMap, Dafny.Map.FromElements(new Dafny.Pair(_59_rTypeArg, _65_rCoerceType))); + _48_coerceTypes = Dafny.Sequence.Concat(_48_coerceTypes, Dafny.Sequence.FromElements(_65_rCoerceType)); + _49_rCoerceTypeParams = Dafny.Sequence.Concat(_49_rCoerceTypeParams, Dafny.Sequence.FromElements(_64_rCoerceTypeParamDecl)); + Dafny.ISequence _66_coerceFormal; + _66_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_55_typeI)); + _53_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_53_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_59_rTypeArg, _65_rCoerceType), (RAST.Expr.create_Identifier(_66_coerceFormal)).Clone()))); + _50_coerceArguments = Dafny.Sequence.Concat(_50_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_66_coerceFormal, RAST.__default.Rc(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_59_rTypeArg), _65_rCoerceType)), RAST.__default.StaticTrait))))); continue_2_0: ; } after_2_0: ; - if ((new BigInteger((_20_unusedTypeParams).Count)).Sign == 1) { - _5_ctors = Dafny.Sequence.Concat(_5_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_66_tpe) => { - return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _66_tpe); -})), _53_types))))); - } - } - bool _67_cIsEq; - _67_cIsEq = (this).DatatypeIsEq(c); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create(((_67_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _3_datatypeName, _2_rTypeParamsDecls, _5_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), _26_implBody))); - Dafny.ISequence _68_printImplBodyCases; - _68_printImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _69_hashImplBodyCases; - _69_hashImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _70_coerceImplBodyCases; - _70_coerceImplBodyCases = Dafny.Sequence.FromElements(); + if ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1) { + _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_67_tpe) => { + return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _67_tpe); +})), _54_types))))); + } + } + bool _68_cIsEq; + _68_cIsEq = (this).DatatypeIsEq(c); + RAST._IType _69_datatypeType; + _69_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create(((_68_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _69_datatypeType, _27_implBody))); + if ((new BigInteger(((c).dtor_superTraitTypes).Count)).Sign == 1) { + RAST._IType _70_fullType; + if (_0_isRcWrapped) { + _70_fullType = RAST.__default.Rc(_69_datatypeType); + } else { + _70_fullType = _69_datatypeType; + } + Std.Wrappers._IOption _71_downcastDefinitionOpt; + _71_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_3_rTypeParamsDecls, _70_fullType); + if ((_71_downcastDefinitionOpt).is_None) { + RAST._IExpr _72_dummy; + RAST._IExpr _out15; + _out15 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _72_dummy = _out15; + } else { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_71_downcastDefinitionOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements()); + } + Std.Wrappers._IOption _73_downcastImplementationsOpt; + _73_downcastImplementationsOpt = Defs.__default.DowncastImplFor(_3_rTypeParamsDecls, _70_fullType, _70_fullType); + if ((_73_downcastImplementationsOpt).is_None) { + RAST._IExpr _74_dummy; + RAST._IExpr _out16; + _out16 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _74_dummy = _out16; + } else { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_73_downcastImplementationsOpt).dtor_value)); + } + } + Dafny.ISequence _75_printImplBodyCases; + _75_printImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _76_hashImplBodyCases; + _76_hashImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _77_coerceImplBodyCases; + _77_coerceImplBodyCases = Dafny.Sequence.FromElements(); BigInteger _hi7 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _71_i = BigInteger.Zero; _71_i < _hi7; _71_i++) { - DAST._IDatatypeCtor _72_ctor; - _72_ctor = ((c).dtor_ctors).Select(_71_i); - Dafny.ISequence _73_ctorMatch; - _73_ctorMatch = Defs.__default.escapeName((_72_ctor).dtor_name); - Dafny.ISequence _74_modulePrefix; + for (BigInteger _78_i = BigInteger.Zero; _78_i < _hi7; _78_i++) { + DAST._IDatatypeCtor _79_ctor; + _79_ctor = ((c).dtor_ctors).Select(_78_i); + Dafny.ISequence _80_ctorMatch; + _80_ctorMatch = Defs.__default.escapeName((_79_ctor).dtor_name); + Dafny.ISequence _81_modulePrefix; if (((((c).dtor_enclosingModule))).Equals(Dafny.Sequence.UnicodeFromString("_module"))) { - _74_modulePrefix = Dafny.Sequence.UnicodeFromString(""); + _81_modulePrefix = Dafny.Sequence.UnicodeFromString(""); } else { - _74_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); - } - Dafny.ISequence _75_ctorName; - _75_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_74_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_72_ctor).dtor_name)); - if (((new BigInteger((_75_ctorName).Count)) >= (new BigInteger(13))) && (((_75_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { - _75_ctorName = Dafny.Sequence.UnicodeFromString(""); - } - RAST._IExpr _76_printRhs; - _76_printRhs = (this).writeStr(Dafny.Sequence.Concat(_75_ctorName, (((_72_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); - RAST._IExpr _77_hashRhs; - _77_hashRhs = (this).InitEmptyExpr(); - Dafny.ISequence _78_coerceRhsArgs; - _78_coerceRhsArgs = Dafny.Sequence.FromElements(); - bool _79_isNumeric; - _79_isNumeric = false; - Dafny.ISequence _80_ctorMatchInner; - _80_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); - BigInteger _hi8 = new BigInteger(((_72_ctor).dtor_args).Count); - for (BigInteger _81_j = BigInteger.Zero; _81_j < _hi8; _81_j++) { - DAST._IDatatypeDtor _82_dtor; - _82_dtor = ((_72_ctor).dtor_args).Select(_81_j); - Dafny.ISequence _83_patternName; - _83_patternName = Defs.__default.escapeVar(((_82_dtor).dtor_formal).dtor_name); - DAST._IType _84_formalType; - _84_formalType = ((_82_dtor).dtor_formal).dtor_typ; - if (((_81_j).Sign == 0) && ((_83_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _79_isNumeric = true; - } - if (_79_isNumeric) { - _83_patternName = Std.Wrappers.Option>.GetOr((_82_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_81_j))); - } - if ((_84_formalType).is_Arrow) { - _77_hashRhs = (_77_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + _81_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); + } + Dafny.ISequence _82_ctorName; + _82_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_81_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_79_ctor).dtor_name)); + if (((new BigInteger((_82_ctorName).Count)) >= (new BigInteger(13))) && (((_82_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { + _82_ctorName = Dafny.Sequence.UnicodeFromString(""); + } + RAST._IExpr _83_printRhs; + _83_printRhs = (this).writeStr(Dafny.Sequence.Concat(_82_ctorName, (((_79_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); + RAST._IExpr _84_hashRhs; + _84_hashRhs = (this).InitEmptyExpr(); + Dafny.ISequence _85_coerceRhsArgs; + _85_coerceRhsArgs = Dafny.Sequence.FromElements(); + bool _86_isNumeric; + _86_isNumeric = false; + Dafny.ISequence _87_ctorMatchInner; + _87_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); + BigInteger _hi8 = new BigInteger(((_79_ctor).dtor_args).Count); + for (BigInteger _88_j = BigInteger.Zero; _88_j < _hi8; _88_j++) { + DAST._IDatatypeDtor _89_dtor; + _89_dtor = ((_79_ctor).dtor_args).Select(_88_j); + Dafny.ISequence _90_patternName; + _90_patternName = Defs.__default.escapeVar(((_89_dtor).dtor_formal).dtor_name); + DAST._IType _91_formalType; + _91_formalType = ((_89_dtor).dtor_formal).dtor_typ; + if (((_88_j).Sign == 0) && ((_90_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _86_isNumeric = true; + } + if (_86_isNumeric) { + _90_patternName = Std.Wrappers.Option>.GetOr((_89_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_88_j))); + } + if ((_91_formalType).is_Arrow) { + _84_hashRhs = (_84_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); } else { - _77_hashRhs = (_77_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_83_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); - } - _80_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_80_ctorMatchInner, _83_patternName), Dafny.Sequence.UnicodeFromString(", ")); - if ((_81_j).Sign == 1) { - _76_printRhs = (_76_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); - } - _76_printRhs = (_76_printRhs).Then((((_84_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_83_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); - RAST._IExpr _85_coerceRhsArg = RAST.Expr.Default(); - RAST._IType _86_formalTpe; - RAST._IType _out15; - _out15 = (this).GenType(_84_formalType, Defs.GenTypeContext.@default()); - _86_formalTpe = _out15; - DAST._IType _87_newFormalType; - _87_newFormalType = (_84_formalType).Replace(_50_coerceMap); - RAST._IType _88_newFormalTpe; - _88_newFormalTpe = (_86_formalTpe).ReplaceMap(_51_rCoerceMap); - Std.Wrappers._IResult,RAST._IExpr>>> _89_upcastConverter; - _89_upcastConverter = (this).UpcastConversionLambda(_84_formalType, _86_formalTpe, _87_newFormalType, _88_newFormalTpe, _52_coerceMapToArg); - if ((_89_upcastConverter).is_Success) { - RAST._IExpr _90_coercionFunction; - _90_coercionFunction = (_89_upcastConverter).dtor_value; - _85_coerceRhsArg = (_90_coercionFunction).Apply1(RAST.Expr.create_Identifier(_83_patternName)); + _84_hashRhs = (_84_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_90_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); + } + _87_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_87_ctorMatchInner, _90_patternName), Dafny.Sequence.UnicodeFromString(", ")); + if ((_88_j).Sign == 1) { + _83_printRhs = (_83_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); + } + _83_printRhs = (_83_printRhs).Then((((_91_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_90_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); + RAST._IExpr _92_coerceRhsArg = RAST.Expr.Default(); + RAST._IType _93_formalTpe; + RAST._IType _out17; + _out17 = (this).GenType(_91_formalType, Defs.GenTypeContext.@default()); + _93_formalTpe = _out17; + DAST._IType _94_newFormalType; + _94_newFormalType = (_91_formalType).Replace(_51_coerceMap); + RAST._IType _95_newFormalTpe; + _95_newFormalTpe = (_93_formalTpe).ReplaceMap(_52_rCoerceMap); + Std.Wrappers._IResult,RAST._IExpr>>> _96_upcastConverter; + _96_upcastConverter = (this).UpcastConversionLambda(_91_formalType, _93_formalTpe, _94_newFormalType, _95_newFormalTpe, _53_coerceMapToArg); + if ((_96_upcastConverter).is_Success) { + RAST._IExpr _97_coercionFunction; + _97_coercionFunction = (_96_upcastConverter).dtor_value; + _92_coerceRhsArg = (_97_coercionFunction).Apply1(RAST.Expr.create_Identifier(_90_patternName)); } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_81_j)), Dafny.Sequence.UnicodeFromString(" of ")), _3_datatypeName)); - _85_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_88_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); + _92_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); } - _78_coerceRhsArgs = Dafny.Sequence.Concat(_78_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_83_patternName, _85_coerceRhsArg))); + _85_coerceRhsArgs = Dafny.Sequence.Concat(_85_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_90_patternName, _92_coerceRhsArg))); } - RAST._IExpr _91_coerceRhs; - _91_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_3_datatypeName)).FSel(Defs.__default.escapeName((_72_ctor).dtor_name)), _78_coerceRhsArgs); - if (_79_isNumeric) { - _73_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_73_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _80_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + RAST._IExpr _98_coerceRhs; + _98_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_79_ctor).dtor_name)), _85_coerceRhsArgs); + if (_86_isNumeric) { + _80_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_80_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _87_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); } else { - _73_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_73_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _80_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); - } - if ((_72_ctor).dtor_hasAnyArgs) { - _76_printRhs = (_76_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); - } - _76_printRhs = (_76_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); - _68_printImplBodyCases = Dafny.Sequence.Concat(_68_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_76_printRhs)))); - _69_hashImplBodyCases = Dafny.Sequence.Concat(_69_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_77_hashRhs)))); - _70_coerceImplBodyCases = Dafny.Sequence.Concat(_70_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _73_ctorMatch), RAST.Expr.create_Block(_91_coerceRhs)))); - } - if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_20_unusedTypeParams).Count)).Sign == 1)) { - Dafny.ISequence _92_extraCases; - _92_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_3_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); - _68_printImplBodyCases = Dafny.Sequence.Concat(_68_printImplBodyCases, _92_extraCases); - _69_hashImplBodyCases = Dafny.Sequence.Concat(_69_hashImplBodyCases, _92_extraCases); - _70_coerceImplBodyCases = Dafny.Sequence.Concat(_70_coerceImplBodyCases, _92_extraCases); - } - Dafny.ISequence _93_defaultConstrainedTypeParams; - _93_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - Dafny.ISequence _94_rTypeParamsDeclsWithEq; - _94_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); - Dafny.ISequence _95_rTypeParamsDeclsWithHash; - _95_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - RAST._IExpr _96_printImplBody; - _96_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _68_printImplBodyCases); - RAST._IExpr _97_hashImplBody; - _97_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _69_hashImplBodyCases); - RAST._IType _98_datatypeType; - _98_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_2_rTypeParamsDecls, _98_datatypeType, _1_rTypeParams), Defs.__default.PrintImpl(_2_rTypeParamsDecls, _98_datatypeType, _1_rTypeParams, _96_printImplBody))); - if ((new BigInteger((_48_rCoerceTypeParams).Count)).Sign == 1) { - RAST._IExpr _99_coerceImplBody; - _99_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _70_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_2_rTypeParamsDecls, _3_datatypeName, _98_datatypeType, _48_rCoerceTypeParams, _49_coerceArguments, _47_coerceTypes, _99_coerceImplBody))); - } - if ((new BigInteger((_8_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { - RAST._IType _100_instantiationType; - if ((this).IsRcWrapped((c).dtor_attributes)) { - _100_instantiationType = RAST.__default.Rc(_98_datatypeType); + _80_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_80_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _87_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + } + if ((_79_ctor).dtor_hasAnyArgs) { + _83_printRhs = (_83_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); + } + _83_printRhs = (_83_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); + _75_printImplBodyCases = Dafny.Sequence.Concat(_75_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _80_ctorMatch), RAST.Expr.create_Block(_83_printRhs)))); + _76_hashImplBodyCases = Dafny.Sequence.Concat(_76_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _80_ctorMatch), RAST.Expr.create_Block(_84_hashRhs)))); + _77_coerceImplBodyCases = Dafny.Sequence.Concat(_77_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _80_ctorMatch), RAST.Expr.create_Block(_98_coerceRhs)))); + } + if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { + Dafny.ISequence _99_extraCases; + _99_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + _75_printImplBodyCases = Dafny.Sequence.Concat(_75_printImplBodyCases, _99_extraCases); + _76_hashImplBodyCases = Dafny.Sequence.Concat(_76_hashImplBodyCases, _99_extraCases); + _77_coerceImplBodyCases = Dafny.Sequence.Concat(_77_coerceImplBodyCases, _99_extraCases); + } + Dafny.ISequence _100_defaultConstrainedTypeParams; + _100_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + Dafny.ISequence _101_rTypeParamsDeclsWithEq; + _101_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); + Dafny.ISequence _102_rTypeParamsDeclsWithHash; + _102_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); + RAST._IExpr _103_printImplBody; + _103_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _75_printImplBodyCases); + RAST._IExpr _104_hashImplBody; + _104_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _76_hashImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams, _103_printImplBody))); + if ((new BigInteger((_49_rCoerceTypeParams).Count)).Sign == 1) { + RAST._IExpr _105_coerceImplBody; + _105_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _77_coerceImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _69_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _105_coerceImplBody))); + } + if ((new BigInteger((_9_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { + RAST._IType _106_instantiationType; + if (_0_isRcWrapped) { + _106_instantiationType = RAST.__default.Rc(_69_datatypeType); } else { - _100_instantiationType = _98_datatypeType; + _106_instantiationType = _69_datatypeType; } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_2_rTypeParamsDecls, _98_datatypeType, _100_instantiationType, _8_singletonConstructors))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _69_datatypeType, _106_instantiationType, _9_singletonConstructors))); } - if (_67_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_94_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), Dafny.Sequence.FromElements())))); + if (_68_cIsEq) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_101_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), Dafny.Sequence.FromElements())))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_95_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams), _97_hashImplBody))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_102_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), _104_hashImplBody))); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - RAST._IExpr _101_structName; - _101_structName = (RAST.Expr.create_Identifier(_3_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _102_structAssignments; - _102_structAssignments = Dafny.Sequence.FromElements(); + RAST._IExpr _107_structName; + _107_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _108_structAssignments; + _108_structAssignments = Dafny.Sequence.FromElements(); BigInteger _hi9 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); - for (BigInteger _103_i = BigInteger.Zero; _103_i < _hi9; _103_i++) { - DAST._IDatatypeDtor _104_dtor; - _104_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_103_i); - _102_structAssignments = Dafny.Sequence.Concat(_102_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_104_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); - } - Dafny.ISequence _105_defaultConstrainedTypeParams; - _105_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - RAST._IType _106_fullType; - _106_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_3_datatypeName), _1_rTypeParams); - if ((false) && (_67_cIsEq)) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_105_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, _106_fullType, 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(_106_fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_101_structName, _102_structAssignments))))))))); - } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsType()).Apply1(_106_fullType), _106_fullType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfBorrowed), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self)))))))); - } - Dafny.ISequence _107_superTraitImplementations; - Dafny.ISequence _out16; - _out16 = (this).GenTraitImplementations(path, _1_rTypeParams, _2_rTypeParamsDecls, (c).dtor_superTraitTypes, _25_traitBodies, _4_extern, Dafny.Sequence.UnicodeFromString("datatype")); - _107_superTraitImplementations = _out16; - s = Dafny.Sequence.Concat(s, _107_superTraitImplementations); + for (BigInteger _109_i = BigInteger.Zero; _109_i < _hi9; _109_i++) { + DAST._IDatatypeDtor _110_dtor; + _110_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_109_i); + _108_structAssignments = Dafny.Sequence.Concat(_108_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_110_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); + } + Dafny.ISequence _111_defaultConstrainedTypeParams; + _111_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + RAST._IType _112_fullType; + _112_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); + if ((false) && (_68_cIsEq)) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_111_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, _112_fullType, 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(_112_fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_107_structName, _108_structAssignments))))))))); + } + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_3_rTypeParamsDecls, ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsType()).Apply1(_112_fullType), _112_fullType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfBorrowed), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self)))))))); + } + Dafny.ISequence _113_superTraitImplementations; + Dafny.ISequence _out18; + _out18 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, Dafny.Sequence.UnicodeFromString("datatype")); + _113_superTraitImplementations = _out18; + s = Dafny.Sequence.Concat(s, _113_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -1837,7 +1882,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e { if (_source0.is_UserDefined) { DAST._IResolvedType _11_r = _source0.dtor_resolved; - _10_instanceType = DAST.Type.create_UserDefined(Dafny.Helpers.Let(_11_r, _pat_let25_0 => Dafny.Helpers.Let(_pat_let25_0, _12_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let_tv0, _pat_let26_0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let26_0, _13_dt__update_htypeArgs_h0 => DAST.ResolvedType.create((_12_dt__update__tmp_h0).dtor_path, _13_dt__update_htypeArgs_h0, (_12_dt__update__tmp_h0).dtor_kind, (_12_dt__update__tmp_h0).dtor_attributes, (_12_dt__update__tmp_h0).dtor_properMethods, (_12_dt__update__tmp_h0).dtor_extendedTypes)))))); + _10_instanceType = DAST.Type.create_UserDefined(Dafny.Helpers.Let(_11_r, _pat_let26_0 => Dafny.Helpers.Let(_pat_let26_0, _12_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let_tv0, _pat_let27_0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let27_0, _13_dt__update_htypeArgs_h0 => DAST.ResolvedType.create((_12_dt__update__tmp_h0).dtor_path, _13_dt__update_htypeArgs_h0, (_12_dt__update__tmp_h0).dtor_kind, (_12_dt__update__tmp_h0).dtor_attributes, (_12_dt__update__tmp_h0).dtor_properMethods, (_12_dt__update__tmp_h0).dtor_extendedTypes)))))); goto after_match0; } } @@ -2256,6 +2301,16 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Defs._ISelfInfo } after_match0: ; } + public RAST._IExpr FromGeneralBorrowToSelfBorrow(RAST._IExpr onExpr, Defs._IOwnership onExprOwnership, Defs._IEnvironment env) + { + if (((onExpr).is_Identifier) && ((env).NeedsAsRefForBorrow((onExpr).dtor_name))) { + return ((onExpr).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); + } else if (((onExprOwnership).is_OwnershipBorrowed) && (!object.Equals(onExpr, RAST.__default.self))) { + return (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(onExpr); + } else { + return onExpr; + } + } public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequence typeArgs, Dafny.ISequence args, Defs._IEnvironment env, out RAST._IExpr r, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); @@ -2313,11 +2368,7 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D _9_onExpr = _out9; _10_recOwnership = _out10; _11_recIdents = _out11; - if (((_9_onExpr).is_Identifier) && ((env).NeedsAsRefForBorrow((_9_onExpr).dtor_name))) { - _9_onExpr = ((_9_onExpr).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); - } else if (((_10_recOwnership).is_OwnershipBorrowed) && (!object.Equals(_9_onExpr, RAST.__default.self))) { - _9_onExpr = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(_9_onExpr); - } + _9_onExpr = (this).FromGeneralBorrowToSelfBorrow(_9_onExpr, _10_recOwnership, env); readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); } else if (((_6_base).is_Newtype) && (Defs.__default.IsNewtypeCopy((_6_base).dtor_range))) { RAST._IExpr _out12; @@ -3038,9 +3089,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. DAST._IExpression _source0 = e; { if (_source0.is_Literal) { - DAST._ILiteral _h300 = _source0.dtor_Literal_a0; - if (_h300.is_BoolLiteral) { - bool _0_b = _h300.dtor_BoolLiteral_a0; + DAST._ILiteral _h560 = _source0.dtor_Literal_a0; + if (_h560.is_BoolLiteral) { + bool _0_b = _h560.dtor_BoolLiteral_a0; { RAST._IExpr _out0; Defs._IOwnership _out1; @@ -3056,10 +3107,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h301 = _source0.dtor_Literal_a0; - if (_h301.is_IntLiteral) { - Dafny.ISequence _1_i = _h301.dtor_IntLiteral_a0; - DAST._IType _2_t = _h301.dtor_IntLiteral_a1; + DAST._ILiteral _h561 = _source0.dtor_Literal_a0; + if (_h561.is_IntLiteral) { + Dafny.ISequence _1_i = _h561.dtor_IntLiteral_a0; + DAST._IType _2_t = _h561.dtor_IntLiteral_a1; { DAST._IType _source1 = _2_t; { @@ -3102,11 +3153,11 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h302 = _source0.dtor_Literal_a0; - if (_h302.is_DecLiteral) { - Dafny.ISequence _5_n = _h302.dtor_DecLiteral_a0; - Dafny.ISequence _6_d = _h302.dtor_DecLiteral_a1; - DAST._IType _7_t = _h302.dtor_DecLiteral_a2; + DAST._ILiteral _h562 = _source0.dtor_Literal_a0; + if (_h562.is_DecLiteral) { + Dafny.ISequence _5_n = _h562.dtor_DecLiteral_a0; + Dafny.ISequence _6_d = _h562.dtor_DecLiteral_a1; + DAST._IType _7_t = _h562.dtor_DecLiteral_a2; { DAST._IType _source2 = _7_t; { @@ -3145,10 +3196,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h303 = _source0.dtor_Literal_a0; - if (_h303.is_StringLiteral) { - Dafny.ISequence _10_l = _h303.dtor_StringLiteral_a0; - bool _11_verbatim = _h303.dtor_verbatim; + DAST._ILiteral _h563 = _source0.dtor_Literal_a0; + if (_h563.is_StringLiteral) { + Dafny.ISequence _10_l = _h563.dtor_StringLiteral_a0; + bool _11_verbatim = _h563.dtor_verbatim; { r = (((RAST.__default.dafny__runtime).MSel((this).string__of)).AsExpr()).Apply1(RAST.Expr.create_LiteralString(_10_l, false, _11_verbatim)); RAST._IExpr _out8; @@ -3165,9 +3216,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h304 = _source0.dtor_Literal_a0; - if (_h304.is_CharLiteralUTF16) { - BigInteger _12_c = _h304.dtor_CharLiteralUTF16_a0; + DAST._ILiteral _h564 = _source0.dtor_Literal_a0; + if (_h564.is_CharLiteralUTF16) { + BigInteger _12_c = _h564.dtor_CharLiteralUTF16_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(_12_c)); r = RAST.Expr.create_TypeAscription(r, RAST.Type.create_U16()); @@ -3186,9 +3237,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h305 = _source0.dtor_Literal_a0; - if (_h305.is_CharLiteral) { - Dafny.Rune _13_c = _h305.dtor_CharLiteral_a0; + DAST._ILiteral _h565 = _source0.dtor_Literal_a0; + if (_h565.is_CharLiteral) { + Dafny.Rune _13_c = _h565.dtor_CharLiteral_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(new BigInteger((_13_c).Value))); if (!(((this).charType).is_UTF32)) { @@ -3210,8 +3261,8 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } } { - DAST._ILiteral _h306 = _source0.dtor_Literal_a0; - DAST._IType _14_tpe = _h306.dtor_Null_a0; + DAST._ILiteral _h566 = _source0.dtor_Literal_a0; + DAST._IType _14_tpe = _h566.dtor_Null_a0; { RAST._IType _15_tpeGen; RAST._IType _out14; @@ -4067,7 +4118,7 @@ public bool SameTypesButDifferentTypeParameters(DAST._IType fromType, RAST._ITyp var arr16 = new Std.Wrappers._IResult,RAST._IExpr>>>[Dafny.Helpers.ToIntChecked(dim16, "array size exceeds memory limit")]; for (int i16 = 0; i16 < dim16; i16++) { var _13_j = (BigInteger) i16; - arr16[(int)(_13_j)] = Dafny.Helpers.Let,RAST._IExpr>>>>((_6_indices).Select(_13_j), _pat_let27_0 => Dafny.Helpers.Let,RAST._IExpr>>>>(_pat_let27_0, _14_i => (this).UpcastConversionLambda((((_pat_let_tv0).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv1).dtor_arguments).Select(_14_i), (((_pat_let_tv2).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv3).dtor_arguments).Select(_14_i), _pat_let_tv4))); + arr16[(int)(_13_j)] = Dafny.Helpers.Let,RAST._IExpr>>>>((_6_indices).Select(_13_j), _pat_let28_0 => Dafny.Helpers.Let,RAST._IExpr>>>>(_pat_let28_0, _14_i => (this).UpcastConversionLambda((((_pat_let_tv0).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv1).dtor_arguments).Select(_14_i), (((_pat_let_tv2).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv3).dtor_arguments).Select(_14_i), _pat_let_tv4))); } return Dafny.Sequence,RAST._IExpr>>>>.FromArray(arr16); }))()); @@ -4139,57 +4190,152 @@ public RAST._IExpr BorrowedToOwned(RAST._IExpr expr, Defs._IEnvironment env) return (expr).Clone(); } } - public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) + public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTyp, DAST._IType toTyp, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) { r = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); r = expr; RAST._IType _0_fromTpeGen; RAST._IType _out0; - _out0 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); + _out0 = (this).GenType(fromTyp, Defs.GenTypeContext.@default()); _0_fromTpeGen = _out0; RAST._IType _1_toTpeGen; RAST._IType _out1; - _out1 = (this).GenType(toTpe, Defs.GenTypeContext.@default()); + _out1 = (this).GenType(toTyp, Defs.GenTypeContext.@default()); _1_toTpeGen = _out1; - Std.Wrappers._IResult,RAST._IExpr>>> _2_upcastConverter; - _2_upcastConverter = (this).UpcastConversionLambda(fromTpe, _0_fromTpeGen, toTpe, _1_toTpeGen, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements()); - if ((_2_upcastConverter).is_Success) { - RAST._IExpr _3_conversionLambda; - _3_conversionLambda = (_2_upcastConverter).dtor_value; + bool _2_isDatatype; + _2_isDatatype = (toTyp).IsDatatype(); + bool _3_isGeneralTrait; + _3_isGeneralTrait = (!(_2_isDatatype)) && ((toTyp).IsGeneralTrait()); + if ((_2_isDatatype) || (_3_isGeneralTrait)) { + bool _4_isDowncast; + _4_isDowncast = (toTyp).Extends(fromTyp); + if (_4_isDowncast) { + DAST._IType _5_underlyingType; + if (_2_isDatatype) { + _5_underlyingType = (toTyp).GetDatatypeType(); + } else { + _5_underlyingType = (toTyp).GetGeneralTraitType(); + } + RAST._IType _6_toTpeRaw; + RAST._IType _out2; + _out2 = (this).GenType(_5_underlyingType, Defs.GenTypeContext.@default()); + _6_toTpeRaw = _out2; + Std.Wrappers._IOption _7_toTpeRawDowncastOpt; + _7_toTpeRawDowncastOpt = (_6_toTpeRaw).ToDowncastExpr(); + if ((_7_toTpeRawDowncastOpt).is_Some) { + RAST._IExpr _8_newExpr; + _8_newExpr = expr; + if ((exprOwnership).is_OwnershipOwned) { + RAST._IExpr _source0 = _8_newExpr; + { + if (_source0.is_Call) { + RAST._IExpr obj0 = _source0.dtor_obj; + if (obj0.is_Select) { + RAST._IExpr obj1 = obj0.dtor_obj; + if (obj1.is_Identifier) { + Dafny.ISequence _9_name = obj1.dtor_name; + Dafny.ISequence name0 = obj0.dtor_name; + if (object.Equals(name0, Dafny.Sequence.UnicodeFromString("clone"))) { + Dafny.ISequence _10_arguments = _source0.dtor_arguments; + if ((new BigInteger((_10_arguments).Count)).Sign == 0) { + _8_newExpr = RAST.Expr.create_Identifier(_9_name); + if (!((env).IsBorrowed(_9_name))) { + _8_newExpr = RAST.__default.Borrow(_8_newExpr); + } + } else { + RAST._IExpr _out3; + Defs._IOwnership _out4; + (this).FromOwnership(_8_newExpr, Defs.Ownership.create_OwnershipOwned(), Defs.Ownership.create_OwnershipBorrowed(), out _out3, out _out4); + _8_newExpr = _out3; + resultingOwnership = _out4; + } + goto after_match0; + } + } + } + } + } + { + { + RAST._IExpr _out5; + Defs._IOwnership _out6; + (this).FromOwnership(_8_newExpr, Defs.Ownership.create_OwnershipOwned(), Defs.Ownership.create_OwnershipBorrowed(), out _out5, out _out6); + _8_newExpr = _out5; + resultingOwnership = _out6; + } + } + after_match0: ; + } + _8_newExpr = (this).FromGeneralBorrowToSelfBorrow(expr, Defs.Ownership.create_OwnershipBorrowed(), env); + r = (((_7_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_as"))).Apply1(_8_newExpr); + RAST._IExpr _out7; + Defs._IOwnership _out8; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out7, out _out8); + r = _out7; + resultingOwnership = _out8; + return ; + } else { + RAST._IExpr _out9; + _out9 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_6_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); + r = _out9; + RAST._IExpr _out10; + Defs._IOwnership _out11; + (this).FromOwned(r, expectedOwnership, out _out10, out _out11); + r = _out10; + resultingOwnership = _out11; + return ; + } + } + } else { + RAST._IExpr _out12; + _out12 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"), (this).InitEmptyExpr()); + r = _out12; + RAST._IExpr _out13; + Defs._IOwnership _out14; + (this).FromOwned(r, expectedOwnership, out _out13, out _out14); + r = _out13; + resultingOwnership = _out14; + return ; + } + Std.Wrappers._IResult,RAST._IExpr>>> _11_upcastConverter; + _11_upcastConverter = (this).UpcastConversionLambda(fromTyp, _0_fromTpeGen, toTyp, _1_toTpeGen, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements()); + if ((_11_upcastConverter).is_Success) { + RAST._IExpr _12_conversionLambda; + _12_conversionLambda = (_11_upcastConverter).dtor_value; if (object.Equals(exprOwnership, Defs.Ownership.create_OwnershipBorrowed())) { r = (this).BorrowedToOwned(r, env); } - r = (_3_conversionLambda).Apply1(r); - RAST._IExpr _out2; - Defs._IOwnership _out3; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out2, out _out3); - r = _out2; - resultingOwnership = _out3; + r = (_12_conversionLambda).Apply1(r); + RAST._IExpr _out15; + Defs._IOwnership _out16; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out15, out _out16); + r = _out15; + resultingOwnership = _out16; } else if ((this).IsDowncastConversion(_0_fromTpeGen, _1_toTpeGen)) { _1_toTpeGen = (_1_toTpeGen).ObjectOrPointerUnderlying(); r = (((RAST.__default.dafny__runtime).MSel((this).downcast)).AsExpr()).Apply(Dafny.Sequence.FromElements(r, RAST.Expr.create_ExprFromType(_1_toTpeGen))); - RAST._IExpr _out4; - Defs._IOwnership _out5; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out4, out _out5); - r = _out4; - resultingOwnership = _out5; + RAST._IExpr _out17; + Defs._IOwnership _out18; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out17, out _out18); + r = _out17; + resultingOwnership = _out18; } else { - Std.Wrappers._IResult,RAST._IExpr>>> _let_tmp_rhs0 = _2_upcastConverter; + Std.Wrappers._IResult,RAST._IExpr>>> _let_tmp_rhs0 = _11_upcastConverter; _System._ITuple5,RAST._IExpr>> _let_tmp_rhs1 = _let_tmp_rhs0.dtor_error; - DAST._IType _4_fromType = _let_tmp_rhs1.dtor__0; - RAST._IType _5_fromTpeGen = _let_tmp_rhs1.dtor__1; - DAST._IType _6_toType = _let_tmp_rhs1.dtor__2; - RAST._IType _7_toTpeGen = _let_tmp_rhs1.dtor__3; - Dafny.IMap<_System._ITuple2,RAST._IExpr> _8_m = _let_tmp_rhs1.dtor__4; - RAST._IExpr _out6; - _out6 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Coercion from "), (_5_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_7_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), r); - r = _out6; - RAST._IExpr _out7; - Defs._IOwnership _out8; - (this).FromOwned(r, expectedOwnership, out _out7, out _out8); - r = _out7; - resultingOwnership = _out8; + DAST._IType _13_fromType = _let_tmp_rhs1.dtor__0; + RAST._IType _14_fromTpeGen = _let_tmp_rhs1.dtor__1; + DAST._IType _15_toType = _let_tmp_rhs1.dtor__2; + RAST._IType _16_toTpeGen = _let_tmp_rhs1.dtor__3; + Dafny.IMap<_System._ITuple2,RAST._IExpr> _17_m = _let_tmp_rhs1.dtor__4; + RAST._IExpr _out19; + _out19 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Coercion from "), (_14_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_16_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), r); + r = _out19; + RAST._IExpr _out20; + Defs._IOwnership _out21; + (this).FromOwned(r, expectedOwnership, out _out20, out _out21); + r = _out20; + resultingOwnership = _out21; } } public void GenExprConvert(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership, out Dafny.ISet> readIdents) @@ -4360,14 +4506,14 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v75; + Defs._IOwnership _5___v76; Dafny.ISet> _6_argIdents; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); _4_argExpr = _out1; - _5___v75 = _out2; + _5___v76 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -4565,14 +4711,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi1 = new BigInteger((_9_values).Count); for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13___v85; + Defs._IOwnership _13___v86; Dafny.ISet> _14_recIdents; RAST._IExpr _out16; Defs._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); _12_recursiveGen = _out16; - _13___v85 = _out17; + _13___v86 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -4621,14 +4767,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi3 = new BigInteger((_17_args).Count); for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { RAST._IExpr _23_recursiveGen; - Defs._IOwnership _24___v86; + Defs._IOwnership _24___v87; Dafny.ISet> _25_recIdents; RAST._IExpr _out23; Defs._IOwnership _out24; Dafny.ISet> _out25; (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); _23_recursiveGen = _out23; - _24___v86 = _out24; + _24___v87 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -4666,14 +4812,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi4 = new BigInteger((_26_dims).Count); for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { RAST._IExpr _31_recursiveGen; - Defs._IOwnership _32___v87; + Defs._IOwnership _32___v88; Dafny.ISet> _33_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr((_26_dims).Select(_30_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _31_recursiveGen = _out30; - _32___v87 = _out31; + _32___v88 = _out31; _33_recIdents = _out32; _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); @@ -4700,14 +4846,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _35_underlying = _source0.dtor_value; { RAST._IExpr _36_recursiveGen; - Defs._IOwnership _37___v88; + Defs._IOwnership _37___v89; Dafny.ISet> _38_recIdents; RAST._IExpr _out35; Defs._IOwnership _out36; Dafny.ISet> _out37; (this).GenExpr(_35_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out35, out _out36, out _out37); _36_recursiveGen = _out35; - _37___v88 = _out36; + _37___v89 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -4730,14 +4876,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out40 = (this).GenType(_40_typ, Defs.GenTypeContext.@default()); _41_tpe = _out40; RAST._IExpr _42_recursiveGen; - Defs._IOwnership _43___v89; + Defs._IOwnership _43___v90; Dafny.ISet> _44_recIdents; RAST._IExpr _out41; Defs._IOwnership _out42; Dafny.ISet> _out43; (this).GenExpr(_39_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); _42_recursiveGen = _out41; - _43___v89 = _out42; + _43___v90 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -4803,14 +4949,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; if (_50_isCo) { RAST._IExpr _59_recursiveGen; - Defs._IOwnership _60___v90; + Defs._IOwnership _60___v91; Dafny.ISet> _61_recIdents; RAST._IExpr _out50; Defs._IOwnership _out51; Dafny.ISet> _out52; (this).GenExpr(_58_value, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); _59_recursiveGen = _out50; - _60___v90 = _out51; + _60___v91 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -4833,14 +4979,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _64_wasAssigned))); } else { RAST._IExpr _65_recursiveGen; - Defs._IOwnership _66___v91; + Defs._IOwnership _66___v92; Dafny.ISet> _67_recIdents; RAST._IExpr _out53; Defs._IOwnership _out54; Dafny.ISet> _out55; (this).GenExpr(_58_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out53, out _out54, out _out55); _65_recursiveGen = _out53; - _66___v91 = _out54; + _66___v92 = _out54; _67_recIdents = _out55; _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _65_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); @@ -4880,24 +5026,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _69_expr = _source0.dtor_elem; { RAST._IExpr _70_recursiveGen; - Defs._IOwnership _71___v95; + Defs._IOwnership _71___v96; Dafny.ISet> _72_recIdents; RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; (this).GenExpr(_69_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); _70_recursiveGen = _out61; - _71___v95 = _out62; + _71___v96 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v96; + Defs._IOwnership _74___v97; Dafny.ISet> _75_lengthIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_68_length, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); _73_lengthGen = _out64; - _74___v96 = _out65; + _74___v97 = _out65; _75_lengthIdents = _out66; r = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("_initializer"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_70_recursiveGen)); RAST._IExpr _76_range; @@ -4936,14 +5082,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _82_args = Dafny.Sequence.FromElements(); while ((_81_i) < (new BigInteger((_78_exprs).Count))) { RAST._IExpr _83_recursiveGen; - Defs._IOwnership _84___v97; + Defs._IOwnership _84___v98; Dafny.ISet> _85_recIdents; RAST._IExpr _out70; Defs._IOwnership _out71; Dafny.ISet> _out72; (this).GenExpr((_78_exprs).Select(_81_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out70, out _out71, out _out72); _83_recursiveGen = _out70; - _84___v97 = _out71; + _84___v98 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -4974,14 +5120,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _88_i = BigInteger.Zero; while ((_88_i) < (new BigInteger((_86_exprs).Count))) { RAST._IExpr _89_recursiveGen; - Defs._IOwnership _90___v98; + Defs._IOwnership _90___v99; Dafny.ISet> _91_recIdents; RAST._IExpr _out75; Defs._IOwnership _out76; Dafny.ISet> _out77; (this).GenExpr((_86_exprs).Select(_88_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out75, out _out76, out _out77); _89_recursiveGen = _out75; - _90___v98 = _out76; + _90___v99 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -5009,14 +5155,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _94_i = BigInteger.Zero; while ((_94_i) < (new BigInteger((_92_exprs).Count))) { RAST._IExpr _95_recursiveGen; - Defs._IOwnership _96___v99; + Defs._IOwnership _96___v100; Dafny.ISet> _97_recIdents; RAST._IExpr _out80; Defs._IOwnership _out81; Dafny.ISet> _out82; (this).GenExpr((_92_exprs).Select(_94_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out80, out _out81, out _out82); _95_recursiveGen = _out80; - _96___v99 = _out81; + _96___v100 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -5038,14 +5184,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _98_expr = _source0.dtor_ToMultiset_a0; { RAST._IExpr _99_recursiveGen; - Defs._IOwnership _100___v100; + Defs._IOwnership _100___v101; Dafny.ISet> _101_recIdents; RAST._IExpr _out85; Defs._IOwnership _out86; Dafny.ISet> _out87; (this).GenExpr(_98_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out85, out _out86, out _out87); _99_recursiveGen = _out85; - _100___v100 = _out86; + _100___v101 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -5070,24 +5216,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _104_i = BigInteger.Zero; while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v101; + Defs._IOwnership _106___v102; Dafny.ISet> _107_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); _105_recursiveGenKey = _out90; - _106___v101 = _out91; + _106___v102 = _out91; _107_recIdentsKey = _out92; RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v102; + Defs._IOwnership _109___v103; Dafny.ISet> _110_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); _108_recursiveGenValue = _out93; - _109___v102 = _out94; + _109___v103 = _out94; _110_recIdentsValue = _out95; _103_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_103_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_105_recursiveGenKey, _108_recursiveGenValue))); readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _107_recIdentsKey), _110_recIdentsValue); @@ -5122,14 +5268,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _116_value = _source0.dtor_value; { RAST._IExpr _117_exprR; - Defs._IOwnership _118___v103; + Defs._IOwnership _118___v104; Dafny.ISet> _119_exprIdents; RAST._IExpr _out98; Defs._IOwnership _out99; Dafny.ISet> _out100; (this).GenExpr(_114_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out98, out _out99, out _out100); _117_exprR = _out98; - _118___v103 = _out99; + _118___v104 = _out99; _119_exprIdents = _out100; RAST._IExpr _120_indexR; Defs._IOwnership _121_indexOwnership; @@ -5170,14 +5316,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _128_value = _source0.dtor_value; { RAST._IExpr _129_exprR; - Defs._IOwnership _130___v104; + Defs._IOwnership _130___v105; Dafny.ISet> _131_exprIdents; RAST._IExpr _out109; Defs._IOwnership _out110; Dafny.ISet> _out111; (this).GenExpr(_126_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out109, out _out110, out _out111); _129_exprR = _out109; - _130___v104 = _out110; + _130___v105 = _out110; _131_exprIdents = _out111; RAST._IExpr _132_indexR; Defs._IOwnership _133_indexOwnership; @@ -5258,14 +5404,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _143_f = _source0.dtor_els; { RAST._IExpr _144_cond; - Defs._IOwnership _145___v105; + Defs._IOwnership _145___v106; Dafny.ISet> _146_recIdentsCond; RAST._IExpr _out126; Defs._IOwnership _out127; Dafny.ISet> _out128; (this).GenExpr(_141_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out126, out _out127, out _out128); _144_cond = _out126; - _145___v105 = _out127; + _145___v106 = _out127; _146_recIdentsCond = _out128; RAST._IExpr _147_fExpr; Defs._IOwnership _148_fOwned; @@ -5278,14 +5424,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _148_fOwned = _out130; _149_recIdentsF = _out131; RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v106; + Defs._IOwnership _151___v107; Dafny.ISet> _152_recIdentsT; RAST._IExpr _out132; Defs._IOwnership _out133; Dafny.ISet> _out134; (this).GenExpr(_142_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); _150_tExpr = _out132; - _151___v106 = _out133; + _151___v107 = _out133; _152_recIdentsT = _out134; r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); RAST._IExpr _out135; @@ -5307,14 +5453,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; { RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v107; + Defs._IOwnership _156___v108; Dafny.ISet> _157_recIdents; RAST._IExpr _out137; Defs._IOwnership _out138; Dafny.ISet> _out139; (this).GenExpr(_153_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out137, out _out138, out _out139); _155_recursiveGen = _out137; - _156___v107 = _out138; + _156___v108 = _out138; _157_recIdents = _out139; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); RAST._IExpr _out140; @@ -5337,14 +5483,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; { RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v108; + Defs._IOwnership _161___v109; Dafny.ISet> _162_recIdents; RAST._IExpr _out142; Defs._IOwnership _out143; Dafny.ISet> _out144; (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out142, out _out143, out _out144); _160_recursiveGen = _out142; - _161___v108 = _out143; + _161___v109 = _out143; _162_recIdents = _out144; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); RAST._IExpr _out145; @@ -5409,14 +5555,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _171_native = _source0.dtor_native; { RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v113; + Defs._IOwnership _173___v114; Dafny.ISet> _174_recIdents; RAST._IExpr _out155; Defs._IOwnership _out156; Dafny.ISet> _out157; (this).GenExpr(_168_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out155, out _out156, out _out157); _172_recursiveGen = _out155; - _173___v113 = _out156; + _173___v114 = _out156; _174_recIdents = _out157; RAST._IType _175_arrayType; RAST._IType _out158; @@ -5458,14 +5604,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _177_expr = _source0.dtor_expr; { RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v114; + Defs._IOwnership _179___v115; Dafny.ISet> _180_recIdents; RAST._IExpr _out162; Defs._IOwnership _out163; Dafny.ISet> _out164; (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); _178_recursiveGen = _out162; - _179___v114 = _out163; + _179___v115 = _out163; _180_recIdents = _out164; readIdents = _180_recIdents; r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); @@ -5484,14 +5630,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _181_expr = _source0.dtor_expr; { RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v115; + Defs._IOwnership _183___v116; Dafny.ISet> _184_recIdents; RAST._IExpr _out167; Defs._IOwnership _out168; Dafny.ISet> _out169; (this).GenExpr(_181_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); _182_recursiveGen = _out167; - _183___v115 = _out168; + _183___v116 = _out168; _184_recIdents = _out169; readIdents = _184_recIdents; r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); @@ -5510,14 +5656,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _185_expr = _source0.dtor_expr; { RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v116; + Defs._IOwnership _187___v117; Dafny.ISet> _188_recIdents; RAST._IExpr _out172; Defs._IOwnership _out173; Dafny.ISet> _out174; (this).GenExpr(_185_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out172, out _out173, out _out174); _186_recursiveGen = _out172; - _187___v116 = _out173; + _187___v117 = _out173; _188_recIdents = _out174; readIdents = _188_recIdents; r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); @@ -5589,15 +5735,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _209_name = _let_tmp_rhs1.dtor__0; RAST._IType _210_ty = _let_tmp_rhs1.dtor__1; RAST._IExpr _211_rIdent; - Defs._IOwnership _212___v117; - Dafny.ISet> _213___v118; + Defs._IOwnership _212___v118; + Dafny.ISet> _213___v119; RAST._IExpr _out181; Defs._IOwnership _out182; Dafny.ISet> _out183; (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((!(_193_isConstant)) && ((_210_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); _211_rIdent = _out181; - _212___v117 = _out182; - _213___v118 = _out183; + _212___v118 = _out182; + _213___v119 = _out183; _207_onExprArgs = Dafny.Sequence.Concat(_207_onExprArgs, Dafny.Sequence.FromElements(_211_rIdent)); } _206_body = (_206_body).Apply(_207_onExprArgs); @@ -5888,14 +6034,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _258_l = _source5.dtor_value; { RAST._IExpr _259_lExpr; - Defs._IOwnership _260___v121; + Defs._IOwnership _260___v122; Dafny.ISet> _261_recIdentsL; RAST._IExpr _out217; Defs._IOwnership _out218; Dafny.ISet> _out219; (this).GenExpr(_258_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out217, out _out218, out _out219); _259_lExpr = _out217; - _260___v121 = _out218; + _260___v122 = _out218; _261_recIdentsL = _out219; _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_259_lExpr)); readIdents = Dafny.Set>.Union(readIdents, _261_recIdentsL); @@ -5912,14 +6058,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _262_h = _source6.dtor_value; { RAST._IExpr _263_hExpr; - Defs._IOwnership _264___v122; + Defs._IOwnership _264___v123; Dafny.ISet> _265_recIdentsH; RAST._IExpr _out220; Defs._IOwnership _out221; Dafny.ISet> _out222; (this).GenExpr(_262_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out220, out _out221, out _out222); _263_hExpr = _out220; - _264___v122 = _out221; + _264___v123 = _out221; _265_recIdentsH = _out222; _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_263_hExpr)); readIdents = Dafny.Set>.Union(readIdents, _265_recIdentsH); @@ -6049,14 +6195,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _287_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_283_paramNames, _284_paramTypesMap)); RAST._IExpr _288_recursiveGen; Dafny.ISet> _289_recIdents; - Defs._IEnvironment _290___v124; + Defs._IEnvironment _290___v125; RAST._IExpr _out235; Dafny.ISet> _out236; Defs._IEnvironment _out237; (this).GenStmts(_281_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _287_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out235, out _out236, out _out237); _288_recursiveGen = _out235; _289_recIdents = _out236; - _290___v124 = _out237; + _290___v125 = _out237; readIdents = Dafny.Set>.FromElements(); _289_recIdents = Dafny.Set>.Difference(_289_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_291_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); @@ -6082,15 +6228,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir after__ASSIGN_SUCH_THAT_1: ; if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_294_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { RAST._IExpr _295_selfCloned; - Defs._IOwnership _296___v125; - Dafny.ISet> _297___v126; + Defs._IOwnership _296___v126; + Dafny.ISet> _297___v127; RAST._IExpr _out238; Defs._IOwnership _out239; Dafny.ISet> _out240; (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out238, out _out239, out _out240); _295_selfCloned = _out238; - _296___v125 = _out239; - _297___v126 = _out240; + _296___v126 = _out239; + _297___v127 = _out240; _293_allReadCloned = (_293_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_295_selfCloned))); } else if (!((_283_paramNames).Contains(_294_next))) { RAST._IExpr _298_copy; @@ -6152,14 +6298,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out245 = (this).GenType((((_300_values).Select(_311_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); _312_typeGen = _out245; RAST._IExpr _313_valueGen; - Defs._IOwnership _314___v127; + Defs._IOwnership _314___v128; Dafny.ISet> _315_recIdents; RAST._IExpr _out246; Defs._IOwnership _out247; Dafny.ISet> _out248; (this).GenExpr(((_300_values).Select(_311_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out246, out _out247, out _out248); _313_valueGen = _out246; - _314___v127 = _out247; + _314___v128 = _out247; _315_recIdents = _out248; r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_300_values).Select(_311_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_312_typeGen), Std.Wrappers.Option.create_Some(_313_valueGen))); readIdents = Dafny.Set>.Union(readIdents, _315_recIdents); @@ -6196,14 +6342,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _323_iifeBody = _source0.dtor_iifeBody; { RAST._IExpr _324_valueGen; - Defs._IOwnership _325___v128; + Defs._IOwnership _325___v129; Dafny.ISet> _326_recIdents; RAST._IExpr _out254; Defs._IOwnership _out255; Dafny.ISet> _out256; (this).GenExpr(_322_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out254, out _out255, out _out256); _324_valueGen = _out254; - _325___v128 = _out255; + _325___v129 = _out255; _326_recIdents = _out256; readIdents = _326_recIdents; RAST._IType _327_valueTypeGen; @@ -6213,14 +6359,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _328_iifeVar; _328_iifeVar = Defs.__default.escapeVar(_320_name); RAST._IExpr _329_bodyGen; - Defs._IOwnership _330___v129; + Defs._IOwnership _330___v130; Dafny.ISet> _331_bodyIdents; RAST._IExpr _out258; Defs._IOwnership _out259; Dafny.ISet> _out260; (this).GenExpr(_323_iifeBody, selfIdent, (env).AddAssigned(_328_iifeVar, _327_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out258, out _out259, out _out260); _329_bodyGen = _out258; - _330___v129 = _out259; + _330___v130 = _out259; _331_bodyIdents = _out260; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_331_bodyIdents, Dafny.Set>.FromElements(_328_iifeVar))); r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _328_iifeVar, Std.Wrappers.Option.create_Some(_327_valueTypeGen), Std.Wrappers.Option.create_Some(_324_valueGen))).Then(_329_bodyGen)); @@ -6240,14 +6386,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _333_args = _source0.dtor_args; { RAST._IExpr _334_funcExpr; - Defs._IOwnership _335___v130; + Defs._IOwnership _335___v131; Dafny.ISet> _336_recIdents; RAST._IExpr _out263; Defs._IOwnership _out264; Dafny.ISet> _out265; (this).GenExpr(_332_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out263, out _out264, out _out265); _334_funcExpr = _out263; - _335___v130 = _out264; + _335___v131 = _out264; _336_recIdents = _out265; readIdents = _336_recIdents; Dafny.ISequence _337_rArgs; @@ -6285,14 +6431,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _344_variant = _source0.dtor_variant; { RAST._IExpr _345_exprGen; - Defs._IOwnership _346___v131; + Defs._IOwnership _346___v132; Dafny.ISet> _347_recIdents; RAST._IExpr _out271; Defs._IOwnership _out272; Dafny.ISet> _out273; (this).GenExpr(_342_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out271, out _out272, out _out273); _345_exprGen = _out271; - _346___v131 = _out272; + _346___v132 = _out272; _347_recIdents = _out273; RAST._IExpr _348_variantExprPath; RAST._IExpr _out274; @@ -6313,8 +6459,8 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { if (_source0.is_Is) { DAST._IExpression _349_expr = _source0.dtor_expr; - DAST._IType _350_fromType = _source0.dtor_fromType; - DAST._IType _351_toType = _source0.dtor_toType; + DAST._IType _350_fromTyp = _source0.dtor_fromType; + DAST._IType _351_toTyp = _source0.dtor_toType; { RAST._IExpr _352_expr; Defs._IOwnership _353_recOwned; @@ -6326,27 +6472,61 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _352_expr = _out277; _353_recOwned = _out278; _354_recIdents = _out279; - RAST._IType _355_fromType; + RAST._IType _355_fromTpe; RAST._IType _out280; - _out280 = (this).GenType(_350_fromType, Defs.GenTypeContext.@default()); - _355_fromType = _out280; - RAST._IType _356_toType; + _out280 = (this).GenType(_350_fromTyp, Defs.GenTypeContext.@default()); + _355_fromTpe = _out280; + RAST._IType _356_toTpe; RAST._IType _out281; - _out281 = (this).GenType(_351_toType, Defs.GenTypeContext.@default()); - _356_toType = _out281; - if (((_355_fromType).IsObjectOrPointer()) && ((_356_toType).IsObjectOrPointer())) { - r = (((_352_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_356_toType).ObjectOrPointerUnderlying()))).Apply0(); + _out281 = (this).GenType(_351_toTyp, Defs.GenTypeContext.@default()); + _356_toTpe = _out281; + if (((_355_fromTpe).IsObjectOrPointer()) && ((_356_toTpe).IsObjectOrPointer())) { + r = (((_352_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_356_toTpe).ObjectOrPointerUnderlying()))).Apply0(); } else { - RAST._IExpr _out282; - _out282 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object or Ptr"), (this).InitEmptyExpr()); - r = _out282; - readIdents = Dafny.Set>.FromElements(); + bool _357_isDatatype; + _357_isDatatype = (_351_toTyp).IsDatatype(); + bool _358_isGeneralTrait; + _358_isGeneralTrait = (!(_357_isDatatype)) && ((_351_toTyp).IsGeneralTrait()); + if ((_357_isDatatype) || (_358_isGeneralTrait)) { + bool _359_isDowncast; + _359_isDowncast = (_351_toTyp).Extends(_350_fromTyp); + if (_359_isDowncast) { + DAST._IType _360_underlyingType; + if (_357_isDatatype) { + _360_underlyingType = (_351_toTyp).GetDatatypeType(); + } else { + _360_underlyingType = (_351_toTyp).GetGeneralTraitType(); + } + RAST._IType _361_toTpeRaw; + RAST._IType _out282; + _out282 = (this).GenType(_360_underlyingType, Defs.GenTypeContext.@default()); + _361_toTpeRaw = _out282; + Std.Wrappers._IOption _362_toTpeRawDowncastOpt; + _362_toTpeRawDowncastOpt = (_361_toTpeRaw).ToDowncastExpr(); + if ((_362_toTpeRawDowncastOpt).is_Some) { + r = (((_362_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_352_expr); + _353_recOwned = Defs.Ownership.create_OwnershipOwned(); + } else { + RAST._IExpr _out283; + _out283 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_361_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); + r = _out283; + } + } else { + RAST._IExpr _out284; + _out284 = (this).Error(Dafny.Sequence.UnicodeFromString("Needs support for upcasting general traits"), (this).InitEmptyExpr()); + r = _out284; + } + } else { + RAST._IExpr _out285; + _out285 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"), (this).InitEmptyExpr()); + r = _out285; + } } - RAST._IExpr _out283; - Defs._IOwnership _out284; - (this).FromOwnership(r, _353_recOwned, expectedOwnership, out _out283, out _out284); - r = _out283; - resultingOwnership = _out284; + RAST._IExpr _out286; + Defs._IOwnership _out287; + (this).FromOwnership(r, _353_recOwned, expectedOwnership, out _out286, out _out287); + r = _out286; + resultingOwnership = _out287; readIdents = _354_recIdents; return ; } @@ -6357,11 +6537,11 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_BoolBoundedPool) { { r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("[false, true]")); - RAST._IExpr _out285; - Defs._IOwnership _out286; - (this).FromOwned(r, expectedOwnership, out _out285, out _out286); - r = _out285; - resultingOwnership = _out286; + RAST._IExpr _out288; + Defs._IOwnership _out289; + (this).FromOwned(r, expectedOwnership, out _out288, out _out289); + r = _out288; + resultingOwnership = _out289; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6370,25 +6550,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBoundedPool) { - DAST._IExpression _357_of = _source0.dtor_of; + DAST._IExpression _363_of = _source0.dtor_of; { - RAST._IExpr _358_exprGen; - Defs._IOwnership _359___v132; - Dafny.ISet> _360_recIdents; - RAST._IExpr _out287; - Defs._IOwnership _out288; - Dafny.ISet> _out289; - (this).GenExpr(_357_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out287, out _out288, out _out289); - _358_exprGen = _out287; - _359___v132 = _out288; - _360_recIdents = _out289; - r = ((_358_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + RAST._IExpr _364_exprGen; + Defs._IOwnership _365___v133; + Dafny.ISet> _366_recIdents; RAST._IExpr _out290; Defs._IOwnership _out291; - (this).FromOwned(r, expectedOwnership, out _out290, out _out291); - r = _out290; - resultingOwnership = _out291; - readIdents = _360_recIdents; + Dafny.ISet> _out292; + (this).GenExpr(_363_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out290, out _out291, out _out292); + _364_exprGen = _out290; + _365___v133 = _out291; + _366_recIdents = _out292; + r = ((_364_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + RAST._IExpr _out293; + Defs._IOwnership _out294; + (this).FromOwned(r, expectedOwnership, out _out293, out _out294); + r = _out293; + resultingOwnership = _out294; + readIdents = _366_recIdents; return ; } goto after_match0; @@ -6396,29 +6576,29 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SeqBoundedPool) { - DAST._IExpression _361_of = _source0.dtor_of; - bool _362_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _367_of = _source0.dtor_of; + bool _368_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _363_exprGen; - Defs._IOwnership _364___v133; - Dafny.ISet> _365_recIdents; - RAST._IExpr _out292; - Defs._IOwnership _out293; - Dafny.ISet> _out294; - (this).GenExpr(_361_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out292, out _out293, out _out294); - _363_exprGen = _out292; - _364___v133 = _out293; - _365_recIdents = _out294; - r = ((_363_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_362_includeDuplicates)) { - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); - } + RAST._IExpr _369_exprGen; + Defs._IOwnership _370___v134; + Dafny.ISet> _371_recIdents; RAST._IExpr _out295; Defs._IOwnership _out296; - (this).FromOwned(r, expectedOwnership, out _out295, out _out296); - r = _out295; - resultingOwnership = _out296; - readIdents = _365_recIdents; + Dafny.ISet> _out297; + (this).GenExpr(_367_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out295, out _out296, out _out297); + _369_exprGen = _out295; + _370___v134 = _out296; + _371_recIdents = _out297; + r = ((_369_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_368_includeDuplicates)) { + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); + } + RAST._IExpr _out298; + Defs._IOwnership _out299; + (this).FromOwned(r, expectedOwnership, out _out298, out _out299); + r = _out298; + resultingOwnership = _out299; + readIdents = _371_recIdents; return ; } goto after_match0; @@ -6426,29 +6606,29 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MultisetBoundedPool) { - DAST._IExpression _366_of = _source0.dtor_of; - bool _367_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _372_of = _source0.dtor_of; + bool _373_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _368_exprGen; - Defs._IOwnership _369___v134; - Dafny.ISet> _370_recIdents; - RAST._IExpr _out297; - Defs._IOwnership _out298; - Dafny.ISet> _out299; - (this).GenExpr(_366_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out297, out _out298, out _out299); - _368_exprGen = _out297; - _369___v134 = _out298; - _370_recIdents = _out299; - r = ((_368_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_367_includeDuplicates)) { - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); - } + RAST._IExpr _374_exprGen; + Defs._IOwnership _375___v135; + Dafny.ISet> _376_recIdents; RAST._IExpr _out300; Defs._IOwnership _out301; - (this).FromOwned(r, expectedOwnership, out _out300, out _out301); - r = _out300; - resultingOwnership = _out301; - readIdents = _370_recIdents; + Dafny.ISet> _out302; + (this).GenExpr(_372_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out300, out _out301, out _out302); + _374_exprGen = _out300; + _375___v135 = _out301; + _376_recIdents = _out302; + r = ((_374_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_373_includeDuplicates)) { + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); + } + RAST._IExpr _out303; + Defs._IOwnership _out304; + (this).FromOwned(r, expectedOwnership, out _out303, out _out304); + r = _out303; + resultingOwnership = _out304; + readIdents = _376_recIdents; return ; } goto after_match0; @@ -6456,99 +6636,99 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBoundedPool) { - DAST._IExpression _371_of = _source0.dtor_of; + DAST._IExpression _377_of = _source0.dtor_of; { - RAST._IExpr _372_exprGen; - Defs._IOwnership _373___v135; - Dafny.ISet> _374_recIdents; - RAST._IExpr _out302; - Defs._IOwnership _out303; - Dafny.ISet> _out304; - (this).GenExpr(_371_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); - _372_exprGen = _out302; - _373___v135 = _out303; - _374_recIdents = _out304; - r = ((((_372_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - readIdents = _374_recIdents; + RAST._IExpr _378_exprGen; + Defs._IOwnership _379___v136; + Dafny.ISet> _380_recIdents; RAST._IExpr _out305; Defs._IOwnership _out306; - (this).FromOwned(r, expectedOwnership, out _out305, out _out306); - r = _out305; - resultingOwnership = _out306; + Dafny.ISet> _out307; + (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out305, out _out306, out _out307); + _378_exprGen = _out305; + _379___v136 = _out306; + _380_recIdents = _out307; + r = ((((_378_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + readIdents = _380_recIdents; + RAST._IExpr _out308; + Defs._IOwnership _out309; + (this).FromOwned(r, expectedOwnership, out _out308, out _out309); + r = _out308; + resultingOwnership = _out309; } goto after_match0; } } { if (_source0.is_ExactBoundedPool) { - DAST._IExpression _375_of = _source0.dtor_of; + DAST._IExpression _381_of = _source0.dtor_of; { - RAST._IExpr _376_exprGen; - Defs._IOwnership _377___v136; - Dafny.ISet> _378_recIdents; - RAST._IExpr _out307; - Defs._IOwnership _out308; - Dafny.ISet> _out309; - (this).GenExpr(_375_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out307, out _out308, out _out309); - _376_exprGen = _out307; - _377___v136 = _out308; - _378_recIdents = _out309; - r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_376_exprGen); - readIdents = _378_recIdents; + RAST._IExpr _382_exprGen; + Defs._IOwnership _383___v137; + Dafny.ISet> _384_recIdents; RAST._IExpr _out310; Defs._IOwnership _out311; - (this).FromOwned(r, expectedOwnership, out _out310, out _out311); - r = _out310; - resultingOwnership = _out311; + Dafny.ISet> _out312; + (this).GenExpr(_381_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out310, out _out311, out _out312); + _382_exprGen = _out310; + _383___v137 = _out311; + _384_recIdents = _out312; + r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_382_exprGen); + readIdents = _384_recIdents; + RAST._IExpr _out313; + Defs._IOwnership _out314; + (this).FromOwned(r, expectedOwnership, out _out313, out _out314); + r = _out313; + resultingOwnership = _out314; } goto after_match0; } } { if (_source0.is_IntRange) { - DAST._IType _379_typ = _source0.dtor_elemType; - DAST._IExpression _380_lo = _source0.dtor_lo; - DAST._IExpression _381_hi = _source0.dtor_hi; - bool _382_up = _source0.dtor_up; + DAST._IType _385_typ = _source0.dtor_elemType; + DAST._IExpression _386_lo = _source0.dtor_lo; + DAST._IExpression _387_hi = _source0.dtor_hi; + bool _388_up = _source0.dtor_up; { - RAST._IExpr _383_lo; - Defs._IOwnership _384___v137; - Dafny.ISet> _385_recIdentsLo; - RAST._IExpr _out312; - Defs._IOwnership _out313; - Dafny.ISet> _out314; - (this).GenExpr(_380_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out312, out _out313, out _out314); - _383_lo = _out312; - _384___v137 = _out313; - _385_recIdentsLo = _out314; - RAST._IExpr _386_hi; - Defs._IOwnership _387___v138; - Dafny.ISet> _388_recIdentsHi; + RAST._IExpr _389_lo; + Defs._IOwnership _390___v138; + Dafny.ISet> _391_recIdentsLo; RAST._IExpr _out315; Defs._IOwnership _out316; Dafny.ISet> _out317; - (this).GenExpr(_381_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out315, out _out316, out _out317); - _386_hi = _out315; - _387___v138 = _out316; - _388_recIdentsHi = _out317; - if (_382_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_383_lo, _386_hi)); + (this).GenExpr(_386_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out315, out _out316, out _out317); + _389_lo = _out315; + _390___v138 = _out316; + _391_recIdentsLo = _out317; + RAST._IExpr _392_hi; + Defs._IOwnership _393___v139; + Dafny.ISet> _394_recIdentsHi; + RAST._IExpr _out318; + Defs._IOwnership _out319; + Dafny.ISet> _out320; + (this).GenExpr(_387_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out318, out _out319, out _out320); + _392_hi = _out318; + _393___v139 = _out319; + _394_recIdentsHi = _out320; + if (_388_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_389_lo, _392_hi)); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_386_hi, _383_lo)); - } - if (!((_379_typ).is_Primitive)) { - RAST._IType _389_tpe; - RAST._IType _out318; - _out318 = (this).GenType(_379_typ, Defs.GenTypeContext.@default()); - _389_tpe = _out318; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_389_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); - } - RAST._IExpr _out319; - Defs._IOwnership _out320; - (this).FromOwned(r, expectedOwnership, out _out319, out _out320); - r = _out319; - resultingOwnership = _out320; - readIdents = Dafny.Set>.Union(_385_recIdentsLo, _388_recIdentsHi); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_392_hi, _389_lo)); + } + if (!((_385_typ).is_Primitive)) { + RAST._IType _395_tpe; + RAST._IType _out321; + _out321 = (this).GenType(_385_typ, Defs.GenTypeContext.@default()); + _395_tpe = _out321; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_395_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); + } + RAST._IExpr _out322; + Defs._IOwnership _out323; + (this).FromOwned(r, expectedOwnership, out _out322, out _out323); + r = _out322; + resultingOwnership = _out323; + readIdents = Dafny.Set>.Union(_391_recIdentsLo, _394_recIdentsHi); return ; } goto after_match0; @@ -6556,30 +6736,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_UnboundedIntRange) { - DAST._IExpression _390_start = _source0.dtor_start; - bool _391_up = _source0.dtor_up; + DAST._IExpression _396_start = _source0.dtor_start; + bool _397_up = _source0.dtor_up; { - RAST._IExpr _392_start; - Defs._IOwnership _393___v139; - Dafny.ISet> _394_recIdentStart; - RAST._IExpr _out321; - Defs._IOwnership _out322; - Dafny.ISet> _out323; - (this).GenExpr(_390_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out321, out _out322, out _out323); - _392_start = _out321; - _393___v139 = _out322; - _394_recIdentStart = _out323; - if (_391_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_392_start); - } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_392_start); - } + RAST._IExpr _398_start; + Defs._IOwnership _399___v140; + Dafny.ISet> _400_recIdentStart; RAST._IExpr _out324; Defs._IOwnership _out325; - (this).FromOwned(r, expectedOwnership, out _out324, out _out325); - r = _out324; - resultingOwnership = _out325; - readIdents = _394_recIdentStart; + Dafny.ISet> _out326; + (this).GenExpr(_396_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out324, out _out325, out _out326); + _398_start = _out324; + _399___v140 = _out325; + _400_recIdentStart = _out326; + if (_397_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_398_start); + } else { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_398_start); + } + RAST._IExpr _out327; + Defs._IOwnership _out328; + (this).FromOwned(r, expectedOwnership, out _out327, out _out328); + r = _out327; + resultingOwnership = _out328; + readIdents = _400_recIdentStart; return ; } goto after_match0; @@ -6587,23 +6767,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBuilder) { - DAST._IType _395_keyType = _source0.dtor_keyType; - DAST._IType _396_valueType = _source0.dtor_valueType; + DAST._IType _401_keyType = _source0.dtor_keyType; + DAST._IType _402_valueType = _source0.dtor_valueType; { - RAST._IType _397_kType; - RAST._IType _out326; - _out326 = (this).GenType(_395_keyType, Defs.GenTypeContext.@default()); - _397_kType = _out326; - RAST._IType _398_vType; - RAST._IType _out327; - _out327 = (this).GenType(_396_valueType, Defs.GenTypeContext.@default()); - _398_vType = _out327; - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_397_kType, _398_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out328; - Defs._IOwnership _out329; - (this).FromOwned(r, expectedOwnership, out _out328, out _out329); - r = _out328; - resultingOwnership = _out329; + RAST._IType _403_kType; + RAST._IType _out329; + _out329 = (this).GenType(_401_keyType, Defs.GenTypeContext.@default()); + _403_kType = _out329; + RAST._IType _404_vType; + RAST._IType _out330; + _out330 = (this).GenType(_402_valueType, Defs.GenTypeContext.@default()); + _404_vType = _out330; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_403_kType, _404_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out331; + Defs._IOwnership _out332; + (this).FromOwned(r, expectedOwnership, out _out331, out _out332); + r = _out331; + resultingOwnership = _out332; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6612,93 +6792,93 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBuilder) { - DAST._IType _399_elemType = _source0.dtor_elemType; + DAST._IType _405_elemType = _source0.dtor_elemType; { - RAST._IType _400_eType; - RAST._IType _out330; - _out330 = (this).GenType(_399_elemType, Defs.GenTypeContext.@default()); - _400_eType = _out330; + RAST._IType _406_eType; + RAST._IType _out333; + _out333 = (this).GenType(_405_elemType, Defs.GenTypeContext.@default()); + _406_eType = _out333; readIdents = Dafny.Set>.FromElements(); - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_400_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out331; - Defs._IOwnership _out332; - (this).FromOwned(r, expectedOwnership, out _out331, out _out332); - r = _out331; - resultingOwnership = _out332; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_406_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out334; + Defs._IOwnership _out335; + (this).FromOwned(r, expectedOwnership, out _out334, out _out335); + r = _out334; + resultingOwnership = _out335; return ; } goto after_match0; } } { - DAST._IType _401_elemType = _source0.dtor_elemType; - DAST._IExpression _402_collection = _source0.dtor_collection; - bool _403_is__forall = _source0.dtor_is__forall; - DAST._IExpression _404_lambda = _source0.dtor_lambda; + DAST._IType _407_elemType = _source0.dtor_elemType; + DAST._IExpression _408_collection = _source0.dtor_collection; + bool _409_is__forall = _source0.dtor_is__forall; + DAST._IExpression _410_lambda = _source0.dtor_lambda; { - RAST._IType _405_tpe; - RAST._IType _out333; - _out333 = (this).GenType(_401_elemType, Defs.GenTypeContext.@default()); - _405_tpe = _out333; - RAST._IExpr _406_collectionGen; - Defs._IOwnership _407___v140; - Dafny.ISet> _408_recIdents; - RAST._IExpr _out334; - Defs._IOwnership _out335; - Dafny.ISet> _out336; - (this).GenExpr(_402_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); - _406_collectionGen = _out334; - _407___v140 = _out335; - _408_recIdents = _out336; - Dafny.ISequence _409_extraAttributes; - _409_extraAttributes = Dafny.Sequence.FromElements(); - if ((((((_402_collection).is_IntRange) || ((_402_collection).is_UnboundedIntRange)) || ((_402_collection).is_SeqBoundedPool)) || ((_402_collection).is_ExactBoundedPool)) || ((_402_collection).is_MultisetBoundedPool)) { - _409_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); - } - if ((_404_lambda).is_Lambda) { - Dafny.ISequence _410_formals; - _410_formals = (_404_lambda).dtor_params; - Dafny.ISequence _411_newFormals; - _411_newFormals = Dafny.Sequence.FromElements(); - BigInteger _hi15 = new BigInteger((_410_formals).Count); - for (BigInteger _412_i = BigInteger.Zero; _412_i < _hi15; _412_i++) { - var _pat_let_tv0 = _409_extraAttributes; - var _pat_let_tv1 = _410_formals; - _411_newFormals = Dafny.Sequence.Concat(_411_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_410_formals).Select(_412_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _413_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_412_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _414_dt__update_hattributes_h0 => DAST.Formal.create((_413_dt__update__tmp_h0).dtor_name, (_413_dt__update__tmp_h0).dtor_typ, _414_dt__update_hattributes_h0))))))); - } - DAST._IExpression _415_newLambda; - DAST._IExpression _416_dt__update__tmp_h1 = _404_lambda; - Dafny.ISequence _417_dt__update_hparams_h0 = _411_newFormals; - _415_newLambda = DAST.Expression.create_Lambda(_417_dt__update_hparams_h0, (_416_dt__update__tmp_h1).dtor_retType, (_416_dt__update__tmp_h1).dtor_body); - RAST._IExpr _418_lambdaGen; - Defs._IOwnership _419___v141; - Dafny.ISet> _420_recLambdaIdents; - RAST._IExpr _out337; - Defs._IOwnership _out338; - Dafny.ISet> _out339; - (this).GenExpr(_415_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); - _418_lambdaGen = _out337; - _419___v141 = _out338; - _420_recLambdaIdents = _out339; - Dafny.ISequence _421_fn; - if (_403_is__forall) { - _421_fn = Dafny.Sequence.UnicodeFromString("all"); + RAST._IType _411_tpe; + RAST._IType _out336; + _out336 = (this).GenType(_407_elemType, Defs.GenTypeContext.@default()); + _411_tpe = _out336; + RAST._IExpr _412_collectionGen; + Defs._IOwnership _413___v141; + Dafny.ISet> _414_recIdents; + RAST._IExpr _out337; + Defs._IOwnership _out338; + Dafny.ISet> _out339; + (this).GenExpr(_408_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); + _412_collectionGen = _out337; + _413___v141 = _out338; + _414_recIdents = _out339; + Dafny.ISequence _415_extraAttributes; + _415_extraAttributes = Dafny.Sequence.FromElements(); + if ((((((_408_collection).is_IntRange) || ((_408_collection).is_UnboundedIntRange)) || ((_408_collection).is_SeqBoundedPool)) || ((_408_collection).is_ExactBoundedPool)) || ((_408_collection).is_MultisetBoundedPool)) { + _415_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); + } + if ((_410_lambda).is_Lambda) { + Dafny.ISequence _416_formals; + _416_formals = (_410_lambda).dtor_params; + Dafny.ISequence _417_newFormals; + _417_newFormals = Dafny.Sequence.FromElements(); + BigInteger _hi15 = new BigInteger((_416_formals).Count); + for (BigInteger _418_i = BigInteger.Zero; _418_i < _hi15; _418_i++) { + var _pat_let_tv0 = _415_extraAttributes; + var _pat_let_tv1 = _416_formals; + _417_newFormals = Dafny.Sequence.Concat(_417_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_416_formals).Select(_418_i), _pat_let29_0 => Dafny.Helpers.Let(_pat_let29_0, _419_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_418_i)).dtor_attributes), _pat_let30_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let30_0, _420_dt__update_hattributes_h0 => DAST.Formal.create((_419_dt__update__tmp_h0).dtor_name, (_419_dt__update__tmp_h0).dtor_typ, _420_dt__update_hattributes_h0))))))); + } + DAST._IExpression _421_newLambda; + DAST._IExpression _422_dt__update__tmp_h1 = _410_lambda; + Dafny.ISequence _423_dt__update_hparams_h0 = _417_newFormals; + _421_newLambda = DAST.Expression.create_Lambda(_423_dt__update_hparams_h0, (_422_dt__update__tmp_h1).dtor_retType, (_422_dt__update__tmp_h1).dtor_body); + RAST._IExpr _424_lambdaGen; + Defs._IOwnership _425___v142; + Dafny.ISet> _426_recLambdaIdents; + RAST._IExpr _out340; + Defs._IOwnership _out341; + Dafny.ISet> _out342; + (this).GenExpr(_421_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out340, out _out341, out _out342); + _424_lambdaGen = _out340; + _425___v142 = _out341; + _426_recLambdaIdents = _out342; + Dafny.ISequence _427_fn; + if (_409_is__forall) { + _427_fn = Dafny.Sequence.UnicodeFromString("all"); } else { - _421_fn = Dafny.Sequence.UnicodeFromString("any"); + _427_fn = Dafny.Sequence.UnicodeFromString("any"); } - r = ((_406_collectionGen).Sel(_421_fn)).Apply1(((_418_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); - readIdents = Dafny.Set>.Union(_408_recIdents, _420_recLambdaIdents); + r = ((_412_collectionGen).Sel(_427_fn)).Apply1(((_424_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); + readIdents = Dafny.Set>.Union(_414_recIdents, _426_recLambdaIdents); } else { - RAST._IExpr _out340; - _out340 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); - r = _out340; + RAST._IExpr _out343; + _out343 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); + r = _out343; readIdents = Dafny.Set>.FromElements(); } - RAST._IExpr _out341; - Defs._IOwnership _out342; - (this).FromOwned(r, expectedOwnership, out _out341, out _out342); - r = _out341; - resultingOwnership = _out342; + RAST._IExpr _out344; + Defs._IOwnership _out345; + (this).FromOwned(r, expectedOwnership, out _out344, out _out345); + r = _out344; + resultingOwnership = _out345; } } after_match0: ; @@ -6785,15 +6965,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v142; - Dafny.ISet> _2___v143; + Defs._IOwnership _1___v143; + Dafny.ISet> _2___v144; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v142 = _out1; - _2___v143 = _out2; + _1___v143 = _out1; + _2___v144 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index 6028ecc89bd..0be243083a8 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -538,6 +538,30 @@ public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsType(), newtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("partial_cmp"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("option"))).MSel(Dafny.Sequence.UnicodeFromString("Option"))).AsType()).Apply1((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Ordering"))).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("partial_cmp"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.__default.Borrow((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); } + public static Std.Wrappers._IOption DowncastTraitDeclFor(Dafny.ISequence rTypeParamsDecls, RAST._IType fullType) + { + Std.Wrappers._IOption _0_valueOrError0 = (fullType).ToDowncast(); + if ((_0_valueOrError0).IsFailure()) { + return (_0_valueOrError0).PropagateFailure(); + } else { + RAST._IType _1_downcast__type = (_0_valueOrError0).Extract(); + return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(rTypeParamsDecls, _1_downcast__type, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())))))); + } + } + public static Std.Wrappers._IOption DowncastImplFor(Dafny.ISequence rTypeParamsDecls, RAST._IType typeToDowncastTo, RAST._IType forType) + { + var _pat_let_tv0 = forType; + Std.Wrappers._IOption _0_valueOrError0 = (typeToDowncastTo).ToDowncast(); + if ((_0_valueOrError0).IsFailure()) { + return (_0_valueOrError0).PropagateFailure(); + } else { + RAST._IType _1_downcast__type = (_0_valueOrError0).Extract(); + RAST._IType _2_forTypeRaw = (((forType).IsRc()) ? ((forType).RcUnderlying()) : (forType)); + bool _3_sameType = object.Equals(typeToDowncastTo, forType); + RAST._IExpr _4_asBody = ((_3_sameType) ? (Dafny.Helpers.Let((RAST.__default.self).Clone(), _pat_let25_0 => Dafny.Helpers.Let(_pat_let25_0, _5_body => (((_pat_let_tv0).IsRc()) ? (RAST.__default.RcNew(_5_body)) : (_5_body))))) : ((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply1(RAST.Expr.create_LiteralString(Dafny.Sequence.Concat(Dafny.Sequence.Concat((_2_forTypeRaw)._ToString(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString(" is not a ")), (typeToDowncastTo)._ToString(Dafny.Sequence.UnicodeFromString(""))), false, true)))); + return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, forType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_LiteralBool(_3_sameType)))), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(forType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_4_asBody))))))); + } + } public static Dafny.ISet> reserved__rust { get { return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("as"), Dafny.Sequence.UnicodeFromString("async"), Dafny.Sequence.UnicodeFromString("await"), Dafny.Sequence.UnicodeFromString("break"), Dafny.Sequence.UnicodeFromString("const"), Dafny.Sequence.UnicodeFromString("continue"), Dafny.Sequence.UnicodeFromString("crate"), Dafny.Sequence.UnicodeFromString("dyn"), Dafny.Sequence.UnicodeFromString("else"), Dafny.Sequence.UnicodeFromString("enum"), Dafny.Sequence.UnicodeFromString("extern"), Dafny.Sequence.UnicodeFromString("false"), Dafny.Sequence.UnicodeFromString("fn"), Dafny.Sequence.UnicodeFromString("for"), Dafny.Sequence.UnicodeFromString("if"), Dafny.Sequence.UnicodeFromString("impl"), Dafny.Sequence.UnicodeFromString("in"), Dafny.Sequence.UnicodeFromString("let"), Dafny.Sequence.UnicodeFromString("loop"), Dafny.Sequence.UnicodeFromString("match"), Dafny.Sequence.UnicodeFromString("mod"), Dafny.Sequence.UnicodeFromString("move"), Dafny.Sequence.UnicodeFromString("mut"), Dafny.Sequence.UnicodeFromString("pub"), Dafny.Sequence.UnicodeFromString("ref"), Dafny.Sequence.UnicodeFromString("return"), Dafny.Sequence.UnicodeFromString("static"), Dafny.Sequence.UnicodeFromString("struct"), Dafny.Sequence.UnicodeFromString("super"), Dafny.Sequence.UnicodeFromString("trait"), Dafny.Sequence.UnicodeFromString("true"), Dafny.Sequence.UnicodeFromString("type"), Dafny.Sequence.UnicodeFromString("union"), Dafny.Sequence.UnicodeFromString("unsafe"), Dafny.Sequence.UnicodeFromString("use"), Dafny.Sequence.UnicodeFromString("where"), Dafny.Sequence.UnicodeFromString("while"), Dafny.Sequence.UnicodeFromString("Keywords"), Dafny.Sequence.UnicodeFromString("The"), Dafny.Sequence.UnicodeFromString("abstract"), Dafny.Sequence.UnicodeFromString("become"), Dafny.Sequence.UnicodeFromString("box"), Dafny.Sequence.UnicodeFromString("do"), Dafny.Sequence.UnicodeFromString("final"), Dafny.Sequence.UnicodeFromString("macro"), Dafny.Sequence.UnicodeFromString("override"), Dafny.Sequence.UnicodeFromString("priv"), Dafny.Sequence.UnicodeFromString("try"), Dafny.Sequence.UnicodeFromString("typeof"), Dafny.Sequence.UnicodeFromString("unsized"), Dafny.Sequence.UnicodeFromString("virtual"), Dafny.Sequence.UnicodeFromString("yield")); } } diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index 86045b8317a..3c4394e3494 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -249,6 +249,9 @@ public static RAST._IPath PtrPath { get { public static RAST._IPath BoxPath { get { return ((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("boxed"))).MSel(Dafny.Sequence.UnicodeFromString("Box")); } } + public static RAST._IType BoxType { get { + return (RAST.__default.BoxPath).AsType(); + } } public static RAST._IExpr Ptr { get { return (RAST.__default.PtrPath).AsExpr(); } } @@ -2554,6 +2557,7 @@ public interface _IPath { RAST._IPath dtor_base { get; } Dafny.ISequence dtor_name { get; } _IPath DowncastClone(); + RAST._IPath ToDowncast(); RAST._IPath MSel(Dafny.ISequence name); RAST._IPath MSels(Dafny.ISequence> names); RAST._IExpr FSel(Dafny.ISequence name); @@ -2602,6 +2606,19 @@ public Dafny.ISequence dtor_name { } } public abstract _IPath DowncastClone(); + public RAST._IPath ToDowncast() { + RAST._IPath _source0 = this; + { + if (_source0.is_PMemberSelect) { + RAST._IPath _0_base = _source0.dtor_base; + Dafny.ISequence _1_name = _source0.dtor_name; + return RAST.Path.create_PMemberSelect(_0_base, Dafny.Sequence.Concat(RAST.Path.DowncastPrefix, _1_name)); + } + } + { + return this; + } + } public RAST._IPath MSel(Dafny.ISequence name) { return RAST.Path.create_PMemberSelect(this, name); } @@ -2674,6 +2691,9 @@ public RAST._IExpr AsExpr() { return Std.Wrappers.Option>.create_Some(_1_name); } } + public static Dafny.ISequence DowncastPrefix { get { + return Dafny.Sequence.UnicodeFromString("_Downcast_"); + } } } public class Path_Global : Path { public Path_Global() : base() { @@ -2811,6 +2831,9 @@ public interface _IType { bool dtor_copySemantics { get; } bool dtor_overflow { get; } _IType DowncastClone(); + RAST._IType RemoveSynonyms(); + Std.Wrappers._IOption ToDowncast(); + Std.Wrappers._IOption ToDowncastExpr(); Std.Wrappers._IOption ToExpr(); RAST._IType Expand(); bool EndsWithNameThatCanAcceptGenerics(); @@ -2844,6 +2867,8 @@ public interface _IType { RAST._IType GetBuiltinCollectionElement(); bool IsRc(); RAST._IType RcUnderlying(); + bool IsBoxDyn(); + RAST._IType BoxDynUnderlying(); } public abstract class Type : _IType { public Type() { @@ -3042,6 +3067,80 @@ public bool dtor_overflow { } } public abstract _IType DowncastClone(); + public RAST._IType RemoveSynonyms() { + _IType _this = this; + TAIL_CALL_START: ; + RAST._IType _source0 = _this; + { + if (_source0.is_TSynonym) { + RAST._IType _0_display = _source0.dtor_display; + RAST._IType _1_base = _source0.dtor_base; + RAST._IType _in0 = _0_display; + _this = _in0; + ; + goto TAIL_CALL_START; + } + } + { + if (_source0.is_TMetaData) { + RAST._IType _2_display = _source0.dtor_display; + RAST._IType _in1 = _2_display; + _this = _in1; + ; + goto TAIL_CALL_START; + } + } + { + return _this; + } + } + public Std.Wrappers._IOption ToDowncast() { + RAST._IType _0_t = (this).RemoveSynonyms(); + if ((_0_t).IsRc()) { + return ((_0_t).RcUnderlying()).ToDowncast(); + } else if ((_0_t).IsBoxDyn()) { + return ((_0_t).BoxDynUnderlying()).ToDowncast(); + } else { + RAST._IType _source0 = _0_t; + { + if (_source0.is_TypeFromPath) { + RAST._IPath _1_path = _source0.dtor_path; + return Std.Wrappers.Option.create_Some(RAST.Type.create_TypeFromPath((_1_path).ToDowncast())); + } + } + { + if (_source0.is_TypeApp) { + RAST._IType _2_baseName = _source0.dtor_baseName; + Dafny.ISequence _3_arguments = _source0.dtor_arguments; + Std.Wrappers._IOption _4_valueOrError0 = (_2_baseName).ToDowncast(); + if ((_4_valueOrError0).IsFailure()) { + return (_4_valueOrError0).PropagateFailure(); + } else { + RAST._IType _5_baseNameExpr = (_4_valueOrError0).Extract(); + return Std.Wrappers.Option.create_Some((_5_baseNameExpr).Apply(_3_arguments)); + } + } + } + { + if (_source0.is_TIdentifier) { + Dafny.ISequence _6_name = _source0.dtor_name; + return Std.Wrappers.Option.create_Some(RAST.Type.create_TIdentifier(Dafny.Sequence.Concat(RAST.Path.DowncastPrefix, _6_name))); + } + } + { + return Std.Wrappers.Option.create_None(); + } + } + } + public Std.Wrappers._IOption ToDowncastExpr() { + Std.Wrappers._IOption _0_valueOrError0 = (this).ToDowncast(); + if ((_0_valueOrError0).IsFailure()) { + return (_0_valueOrError0).PropagateFailure(); + } else { + RAST._IType _1_tpe = (_0_valueOrError0).Extract(); + return (_1_tpe).ToExpr(); + } + } public Std.Wrappers._IOption ToExpr() { RAST._IType _source0 = this; { @@ -3875,6 +3974,12 @@ public bool IsRc() { public RAST._IType RcUnderlying() { return ((this).dtor_arguments).Select(BigInteger.Zero); } + public bool IsBoxDyn() { + return ((((this).is_TypeApp) && (object.Equals((this).dtor_baseName, RAST.__default.BoxType))) && ((new BigInteger(((this).dtor_arguments).Count)) == (BigInteger.One))) && ((((this).dtor_arguments).Select(BigInteger.Zero)).is_DynType); + } + public RAST._IType BoxDynUnderlying() { + return (((this).dtor_arguments).Select(BigInteger.Zero)).dtor_underlying; + } } public class Type_U8 : Type { public Type_U8() : base() { diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index fc267756b73..4ba3e85ff6f 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -2038,16 +2038,6 @@ impl Display for DafnyPrintWrapper<&T> { } } -// from gazebo -#[inline] -pub unsafe fn transmute_unchecked(x: A) -> B { - assert_eq!(std::mem::size_of::(), std::mem::size_of::()); - debug_assert_eq!(0, (&x as *const A).align_offset(std::mem::align_of::())); - let b = std::ptr::read(&x as *const A as *const B); - std::mem::forget(x); - b -} - pub trait DafnyPrint { fn fmt_print(&self, f: &mut Formatter<'_>, in_seq: bool) -> std::fmt::Result; @@ -3899,9 +3889,9 @@ pub fn upcast_box() -> Rc Box> Rc::new(|x: A| UpcastBox::upcast(&x)) } pub fn upcast_box_box() -> Rc) -> Box> - where Box: UpcastBox + where A: UpcastBox { - Rc::new(|x: Box| UpcastBox::upcast(&x)) + Rc::new(|x: Box| UpcastBox::upcast(x.as_ref())) } pub fn upcast_id() -> Rc A> @@ -3949,6 +3939,20 @@ impl UpcastObject for T { pub trait UpcastBox { fn upcast(&self) -> Box; } +impl UpcastBox for Rc + where U: UpcastBox +{ + fn upcast(&self) -> Box { + UpcastBox::upcast(AsRef::as_ref(self)) + } +} +impl UpcastBox for Box + where U: UpcastBox +{ + fn upcast(&self) -> Box { + UpcastBox::upcast(AsRef::as_ref(self)) + } +} #[macro_export] diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index 866d93b2138..a31e7cb2803 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -955,11 +955,6 @@ mod tests { trait GeneralTrait: GeneralTraitSuper + UpcastBox> { fn _clone(&self) -> Box; } - impl UpcastBox> for Box { - fn upcast(&self) -> ::std::boxed::Box> { - crate::tests::tests::GeneralTraitSuper::::_clone(self.as_ref()) - } - } impl Clone for Box { fn clone(&self) -> Self { GeneralTrait::_clone(self.as_ref()) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy index de204551a68..f0264d2b40e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy @@ -4,13 +4,16 @@ trait SuperTrait { function GetBool(): bool } -trait DatatypeOps extends SuperTrait { +trait SuperSubTrait extends SuperTrait { + const DecideOtherwise := !GetBool() +} +trait DatatypeOps extends SuperSubTrait { function GetInt(): int function GetBool(): bool { GetInt() % 2 == 0 } function ChooseAmong(a: T, b: T): T { - if GetBool() then a else b + if !DecideOtherwise then a else b } method ChooseAmongMethod(a: T, b: T) returns (c: T) { if GetBool() { @@ -28,6 +31,14 @@ datatype {:rust_rc false} ADatatype extends DatatypeOps = ADatatype(i: int) function GetInt(): int { i } } + +datatype BDatatype extends DatatypeOps = BDatatype(i: int) { + function AsDatatypeOps(): DatatypeOps { + this as DatatypeOps + } + function GetInt(): int { i } +} + method StaticWithGenerics(c: bool, a: T, b: T) returns (t: T){ if c { t := a; @@ -41,7 +52,7 @@ function StaticWithGenericsFn(c: bool, a: T, b: T): (t: T){ datatype TW = TW(d: DatatypeOps) {} -method Main() { +method MainADatatype() { var x := ADatatype(2); expect x.GetInt() == 2; expect x.GetBool() == true; @@ -81,5 +92,67 @@ method Main() { print x1, "\n"; // Ensure we can print even if behind trait print TW(x1) == TW(x1), "\n"; // True print TW(x1) == TW(y1), "\n"; // False + var sx := x1 as SuperTrait; + expect sx is SuperSubTrait; + var sx1 := sx as SuperSubTrait; + var sx1x := sx1 as SuperTrait; + expect sx is ADatatype; + expect !(sx is BDatatype); + var sxa := sx as ADatatype; +} + + +method MainBDatatype() { + var x := BDatatype(2); + expect x.GetInt() == 2; + expect x.GetBool() == true; + expect x.ChooseAmong(8, 9) == 8; + var xm := x.ChooseAmongMethod(8, 9); + expect xm == 8; + var y := BDatatype(3); + expect y.GetInt() == 3; + expect y.GetBool() == false; + expect y.ChooseAmong(8, 9) == 9; + var ym := y.ChooseAmongMethod(8, 9); + expect ym == 9; + var x1 := x.AsDatatypeOps(); // Dynamic dispatch now. + expect x1.GetInt() == 2; + expect x1.GetBool() == true; + expect x1.ChooseAmong(8, 9) == 8; + var x1m := x1.ChooseAmongMethod(8, 9); + expect x1m == 8; + var y1 := y.AsDatatypeOps(); + expect y1.GetInt() == 3; + expect y1.GetBool() == false; + expect y1.ChooseAmong(8, 9) == 9; + var y1m := y1.ChooseAmongMethod(8, 9); + expect y1m == 9; + var zy := y as SuperTrait; + var zx := x as SuperTrait; + expect zx.GetBool(); + expect !zy.GetBool(); + var xory1a := StaticWithGenerics(true, x1, y1); + var xory1b := StaticWithGenerics(false, x1, y1); + var xory1c := StaticWithGenericsFn(true, x1, y1); + var xory1d := StaticWithGenericsFn(false, x1, y1); + var tw := TW(x1); + expect tw.d.GetInt() == 2; + expect TW(xory1a) == TW(x1) == TW(xory1c) != TW(y1); // If not wrapped, Dafny complains + expect TW(xory1b) == TW(y1) == TW(xory1d) != TW(x1); + print x1, "\n"; // Ensure we can print even if behind trait + print TW(x1) == TW(x1), "\n"; // True + print TW(x1) == TW(y1), "\n"; // False + var sx := x1 as SuperTrait; + expect sx is SuperSubTrait; + var sx1 := sx as SuperSubTrait; + var sx1x := sx1 as SuperTrait; + expect sx is BDatatype; + expect !(sx is ADatatype); + var sxa := sx as BDatatype; +} + +method Main() { + MainADatatype(); + MainBDatatype(); print "Main passed all the tests"; } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect index e70b51fd2b7..cb1f36afd41 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect @@ -3,4 +3,7 @@ Dafny program verifier finished with 4 verified, 0 errors ADatatype.ADatatype(2) true false +BDatatype.BDatatype(2) +true +false Main passed all the tests \ No newline at end of file From e09172a12456fe581566ef2b3c57eba2ed1bcb2b Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Wed, 4 Dec 2024 21:11:47 +0100 Subject: [PATCH 19/69] Fixed the merge --- Source/DafnyCore.Test/GeneratedFromDafny/DefsCoverage.cs | 2 +- .../Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/DafnyCore.Test/GeneratedFromDafny/DefsCoverage.cs b/Source/DafnyCore.Test/GeneratedFromDafny/DefsCoverage.cs index 10677a61959..4dcaf1a5ee6 100644 --- a/Source/DafnyCore.Test/GeneratedFromDafny/DefsCoverage.cs +++ b/Source/DafnyCore.Test/GeneratedFromDafny/DefsCoverage.cs @@ -18,7 +18,7 @@ public partial class __default { public static void Expect(bool x) { if (!(x)) { - throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-definitions.dfy(789,4): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} + throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-definitions.dfy(968,4): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} } public static void Tests() { diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index 7bf63f22f8e..d4c1b5bd1a9 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -2160,8 +2160,6 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite if (c is not TraitDecl || TraitRepeatsInheritedDeclarations) { thisContext = c; - var canRedeclareMemberDefinedInTrait = c is not ClassLikeDecl and not DatatypeDecl and not NewtypeDecl || - InstanceMethodsAllowedToCallTraitMethods; foreach (var member in inheritedMembers.Select(memberx => (memberx as Function)?.ByMethodDecl ?? memberx)) { var canRedeclareMemberDefinedInTrait = c is not ClassLikeDecl and not DatatypeDecl and not NewtypeDecl || !InstanceMethodsCanOnlyCallOverridenTraitMethods || member.IsOverrideThatAddsBody; From 787088cb6dfd4bdba3e4110eaa100f48519901c9 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Thu, 5 Dec 2024 01:41:48 +0100 Subject: [PATCH 20/69] Fixed the merge --- .../GeneratedFromDafny/DefsCoverage.cs | 2 +- .../Rust/Dafny-compiler-rust-definitions.dfy | 19 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 18 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 1042 +++++++++-------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 294 ++++- Source/DafnyCore/GeneratedFromDafny/RAST.cs | 502 +++++--- 6 files changed, 1142 insertions(+), 735 deletions(-) diff --git a/Source/DafnyCore.Test/GeneratedFromDafny/DefsCoverage.cs b/Source/DafnyCore.Test/GeneratedFromDafny/DefsCoverage.cs index 4dcaf1a5ee6..b46418fee58 100644 --- a/Source/DafnyCore.Test/GeneratedFromDafny/DefsCoverage.cs +++ b/Source/DafnyCore.Test/GeneratedFromDafny/DefsCoverage.cs @@ -18,7 +18,7 @@ public partial class __default { public static void Expect(bool x) { if (!(x)) { - throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-definitions.dfy(968,4): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} + throw new Dafny.HaltException("Backends/Rust/Dafny-compiler-rust-definitions-coverage.dfy(17,4): " + Dafny.Sequence.UnicodeFromString("expectation violation").ToVerbatimString(false));} } public static void Tests() { diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index a6b6fdfdf72..20e92916240 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -677,10 +677,10 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { } */ const hasher_trait := R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_hash", [], [R.Formal.selfBorrowed], Some(R.Type.U64), - "", Some( R.DeclareVar(R.MUT, "hasher", None, Some(R.std.MSel("hash").MSel("DefaultHasher").AsExpr().FSel("new").Apply0())).Then( R.self.Sel("hash").Apply1(R.UnaryOp("&mut", R.Identifier("hasher"), Format.UnaryOpFormat.NoFormat)).Then( @@ -695,10 +695,10 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { } */ function eq_trait(fullTraitPath: R.Type, fullTraitExpr: R.Expr): R.ImplMember { R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.Borrowed(R.Box(R.DynType(fullTraitPath))))], Some(R.Type.Bool), - "", Some( fullTraitExpr.FSel("_as_any").Apply1(R.Identifier("other").Sel("as_ref").Apply0()).Sel("downcast_ref").ApplyType([R.SelfOwned]).Apply0().Sel("map_or").Apply( [ @@ -711,10 +711,10 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { function clone_trait(fullTraitPath: R.Type): R.ImplMember { R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(fullTraitPath))), - "", Some(R.BoxNew(R.self.Sel("clone").Apply0())))) } @@ -724,10 +724,10 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { } */ const print_trait := R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), - "", Some(R.self.Sel("fmt_print").Apply([R.Identifier("_formatter"), R.Identifier("in_seq")])))) /** @@ -736,10 +736,10 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { } */ const as_any_trait := R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.std.MSel("any").MSel("Any").AsType()))), - "", Some(R.self))) function UnaryOpsImpl( @@ -862,24 +862,25 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { Some( R.TraitDecl( R.Trait( + R.NoDoc, R.NoAttr, rTypeParamsDecls, downcast_type, [], [ R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_is", [], [R.Formal.selfBorrowed], Some(R.Bool), - "", None)), R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_as", [], [R.Formal.selfBorrowed], Some(fullType), - "", None)) ]))) } @@ -926,20 +927,20 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { downcast_type, forType, [ R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_is", [], [R.Formal.selfBorrowed], Some(R.Bool), - "", Some(R.LiteralBool(sameType)))), R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_as", [], [R.Formal.selfBorrowed], Some(forType), - "", Some(asBody))) ])) ) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 8549b3e7f05..36f3091b54c 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -557,28 +557,32 @@ module {:extern "DCOMP"} DafnyToRustCompiler { None )), R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( - "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), "", None + "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), None ) ), R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( - "_hash", [], [R.Formal.selfBorrowed], Some(R.Type.U64), "", None + "_hash", [], [R.Formal.selfBorrowed], Some(R.Type.U64), None ) ), R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.Borrowed(R.Box(R.DynType(traitFullType))))], - Some(R.Bool), "", None + Some(R.Bool), None ) ), R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( - "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.std.MSel("any").MSel("Any").AsType()))), "", None + "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.std.MSel("any").MSel("Any").AsType()))), None ) ) ]; @@ -680,10 +684,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.DafnyPrint, R.Box(R.DynType(traitFullType)), [R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn("fmt_print", [], fmt_print_parameters, Some(fmt_print_result), - "", Some(traitFullExpr.FSel("_fmt_print").Apply([R.self.Sel("as_ref").Apply0(), R.Identifier("_formatter"), R.Identifier("in_seq")])) ))])), /* @@ -700,10 +704,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.std.MSel("cmp").MSel("PartialEq").AsType(), R.Box(R.DynType(traitFullType)), [R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn("eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.SelfBorrowed)], Some(R.Bool), - "", Some(traitFullExpr.FSel("_eq").Apply([R.self.Sel("as_ref").Apply0(), R.Identifier("other")])) ))])), R.ImplDecl( @@ -727,12 +731,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Hash, R.Box(R.DynType(traitFullType)), [R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "hash", hash_type_parameters, hash_parameters, None, - "", Some(hash_function.Apply([R.Borrow(traitFullExpr.FSel("_hash").Apply1(R.self.Sel("as_ref").Apply0())), R.Identifier("_state")])) ))])) ]; diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 3fcceccb4fc..1eb81caa75a 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -83,7 +83,7 @@ public bool HasAttribute(Dafny.ISequence attributes, Dafny.ISe } else if ((_4_optExtern).is_UnsupportedExtern) { (this).error = Std.Wrappers.Option>.create_Some((_4_optExtern).dtor_reason); } - s = DafnyCompilerRustUtils.GatheringModule.MergeSeqMap(DafnyCompilerRustUtils.GatheringModule.Wrap(Defs.__default.ContainingPathToRust(_2_containingPath), RAST.Mod.create_Mod(_3_modName, _5_attributes, _6_body)), _7_allmodules); + s = DafnyCompilerRustUtils.GatheringModule.MergeSeqMap(DafnyCompilerRustUtils.GatheringModule.Wrap(Defs.__default.ContainingPathToRust(_2_containingPath), RAST.Mod.create_Mod((mod).dtor_docString, _5_attributes, _3_modName, _6_body)), _7_allmodules); } return s; } @@ -350,7 +350,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _18_x = RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _13_fullTraitPath, RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), _12_body)); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(_18_x)); if ((_7_traitType).is_GeneralTrait) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_13_fullTraitPath)), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_13_fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((_9_path).AsExpr()).ApplyType(_11_typeArgs)).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(RAST.__default.self))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_13_fullTraitPath)), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_13_fullTraitPath))), Std.Wrappers.Option.create_Some(((((_9_path).AsExpr()).ApplyType(_11_typeArgs)).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(RAST.__default.self))))))))); } else { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_13_fullTraitPath))), RAST.Type.create_TypeApp(_1_genSelfPath, rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(_13_fullTraitPath))))))))); } @@ -435,7 +435,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _16_className = _out9; _17_extern = _out10; RAST._IStruct _18_struct; - _18_struct = RAST.Struct.create(Dafny.Sequence>.FromElements(), _16_className, _2_rTypeParamsDecls, RAST.Fields.create_NamedFields(_4_fields)); + _18_struct = RAST.Struct.create((c).dtor_docString, Dafny.Sequence>.FromElements(), _16_className, _2_rTypeParamsDecls, RAST.Fields.create_NamedFields(_4_fields)); s = Dafny.Sequence.FromElements(); if ((_17_extern).is_NoExtern) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(_18_struct))); @@ -448,7 +448,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _19_implBody = _out11; _20_traitBodies = _out12; if (((_17_extern).is_NoExtern) && (!(_16_className).Equals(Dafny.Sequence.UnicodeFromString("_default")))) { - _19_implBody = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create((this).allocate__fn, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((this).Object(RAST.__default.SelfOwned)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel((this).allocate)).AsExpr()).ApplyType1(RAST.__default.SelfOwned)).Apply0())))), _19_implBody); + _19_implBody = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Allocates an UNINITIALIZED instance. Only the Dafny compiler should use that."), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create((this).allocate__fn, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((this).Object(RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel((this).allocate)).AsExpr()).ApplyType1(RAST.__default.SelfOwned)).Apply0())))), _19_implBody); } RAST._IType _21_selfTypeForImpl = RAST.Type.Default(); if (((_17_extern).is_NoExtern) || ((_17_extern).is_UnsupportedExtern)) { @@ -478,7 +478,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc if (((this).HasAttribute((_25_m).dtor_attributes, Dafny.Sequence.UnicodeFromString("test"))) && ((new BigInteger(((_25_m).dtor_params).Count)).Sign == 0)) { Dafny.ISequence _27_fnName; _27_fnName = Defs.__default.escapeName((_25_m).dtor_name); - _23_testMethods = Dafny.Sequence.Concat(_23_testMethods, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[test]")), RAST.Visibility.create_PUB(), RAST.Fn.create(_27_fnName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_default"))).FSel(_27_fnName)).Apply(Dafny.Sequence.FromElements()))))))); + _23_testMethods = Dafny.Sequence.Concat(_23_testMethods, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create((_25_m).dtor_docString, Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[test]")), RAST.Visibility.create_PUB(), RAST.Fn.create(_27_fnName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_default"))).FSel(_27_fnName)).Apply(Dafny.Sequence.FromElements()))))))); } } s = Dafny.Sequence.Concat(s, _23_testMethods); @@ -549,7 +549,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _12_implBody = _out3; _13_implBodyImplementingOtherTraits = _out4; if (((t).dtor_traitType).is_GeneralTrait) { - _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), 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.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType()))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())))); + _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType()))), Std.Wrappers.Option.create_None())))); } while ((new BigInteger((_13_implBodyImplementingOtherTraits).Count)).Sign == 1) { Dafny.ISequence> _14_otherTrait; @@ -600,10 +600,10 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_24_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_21_parentTpe)))); if ((_20_parentTyp).IsGeneralTrait()) { - _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_21_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_21_parentTpe))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_23_parentTpeExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); + _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_21_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_21_parentTpe))), Std.Wrappers.Option.create_Some(((_23_parentTpeExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); } } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(_1_rTypeParamsDecls, _10_traitFullType, _17_parents, _12_implBody))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create((t).dtor_docString, Dafny.Sequence>.FromElements(), _1_rTypeParamsDecls, _10_traitFullType, _17_parents, _12_implBody))); if ((new BigInteger(((t).dtor_parents).Count)).Sign == 1) { RAST._IType _25_instantiatedFullType; _25_instantiatedFullType = RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)); @@ -619,7 +619,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } } if (((t).dtor_traitType).is_GeneralTrait) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialEq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.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(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_eq"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Eq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.Hash, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_hash"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialEq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_eq"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Eq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.Hash, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_hash"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))))))))); } s = Dafny.Sequence.Concat(s, _18_upcastImplemented); return s; @@ -661,7 +661,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } else { _9_attributes = Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq)]"); } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(Dafny.Sequence>.FromElements(_9_attributes, Dafny.Sequence.UnicodeFromString("#[repr(transparent)]")), _7_newtypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _4_wrappedType)))))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create((c).dtor_docString, Dafny.Sequence>.FromElements(_9_attributes, Dafny.Sequence.UnicodeFromString("#[repr(transparent)]")), _7_newtypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _4_wrappedType)))))); RAST._IExpr _10_fnBody = RAST.Expr.Default(); Std.Wrappers._IOption _source0 = (c).dtor_witnessExpr; { @@ -692,7 +692,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } after_match0: ; RAST._IImplMember _16_body; - _16_body = RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("default"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_10_fnBody))); + _16_body = RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _7_newtypeName), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("default"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(_10_fnBody))); Std.Wrappers._IOption _source1 = (c).dtor_constraint; { if (_source1.is_None) { @@ -717,13 +717,13 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc Dafny.ISequence _out10; _out10 = (this).GenParams(Dafny.Sequence.FromElements(_17_formal), false); _22_rFormals = _out10; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _22_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_19_rStmts)))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Constraint check"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _22_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_19_rStmts)))))))); } after_match1: ; s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _8_resultingType, Dafny.Sequence.FromElements(_16_body))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsType(), _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Target"), _4_wrappedType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("deref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(((RAST.Path.create_Self()).MSel(Dafny.Sequence.UnicodeFromString("Target"))).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_from_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("o"), RAST.Type.create_Borrowed(_4_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("transmute"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("o"))))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("For Dafny print statements"), RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsType(), _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Target"), _4_wrappedType), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("deref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(((RAST.Path.create_Self()).MSel(Dafny.Sequence.UnicodeFromString("Target"))).AsType())), Std.Wrappers.Option.create_Some(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("SAFETY: The newtype is marked as transparent"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_from_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("o"), RAST.Type.create_Borrowed(_4_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Std.Wrappers.Option.create_Some(RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("transmute"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("o"))))))))))))); Dafny.ISequence _23_rTypeParamsDeclsWithHash; _23_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_23_rTypeParamsDeclsWithHash, _8_resultingType, (Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))))); @@ -767,7 +767,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc RAST._IType _out3; _out3 = (this).GenType((c).dtor_base, Defs.GenTypeContext.@default()); _4_resultingType = _out3; - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TypeDecl(RAST.TypeSynonym.create(Dafny.Sequence>.FromElements(), _3_synonymTypeName, _2_rTypeParamsDecls, _4_resultingType))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TypeDecl(RAST.TypeSynonym.create((c).dtor_docString, Dafny.Sequence>.FromElements(), _3_synonymTypeName, _2_rTypeParamsDecls, _4_resultingType))); Dafny.ISequence _5_defaultConstrainedTypeParams; _5_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); Std.Wrappers._IOption _source0 = (c).dtor_witnessExpr; @@ -797,7 +797,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _12___v10 = _out9; Dafny.ISequence _13_constantName; _13_constantName = Defs.__default.escapeName(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_init_"), ((c).dtor_name))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_13_constantName, _5_defaultConstrainedTypeParams, Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_4_resultingType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((_7_rStmts).Then(_10_rExpr))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _3_synonymTypeName), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_13_constantName, _5_defaultConstrainedTypeParams, Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_4_resultingType), Std.Wrappers.Option.create_Some((_7_rStmts).Then(_10_rExpr))))))); } goto after_match0; } @@ -991,7 +991,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) if (_14_isNumeric) { _20_namedFields = (_20_namedFields).ToNamelessFields(); } - _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Defs.__default.escapeName((_12_ctor).dtor_name), _20_namedFields))); + _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create((_12_ctor).dtor_docString, Defs.__default.escapeName((_12_ctor).dtor_name), _20_namedFields))); } Dafny.ISet> _21_unusedTypeParams; _21_unusedTypeParams = Dafny.Set>.Difference(Dafny.Helpers.Id, Dafny.ISet>>>((_22_rTypeParamsDecls) => ((System.Func>>)(() => { @@ -1088,7 +1088,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } RAST._IExpr _47_methodBody; _47_methodBody = RAST.Expr.create_Match(RAST.__default.self, _35_cases); - _27_implBody = Dafny.Sequence.Concat(_27_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(_33_callName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_34_formalType)), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_47_methodBody))))); + _27_implBody = Dafny.Sequence.Concat(_27_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl((((new BigInteger(((c).dtor_ctors).Count)) == (BigInteger.One)) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Returns a borrow of the field "), _33_callName)) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Gets the field "), _33_callName), Dafny.Sequence.UnicodeFromString(" for all enum members which have it")))), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_33_callName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_34_formalType)), Std.Wrappers.Option.create_Some(_47_methodBody))))); } } } @@ -1154,7 +1154,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } after_2_0: ; if ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1) { - _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_67_tpe) => { + _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_67_tpe) => { return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _67_tpe); })), _54_types))))); } @@ -1163,7 +1163,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _68_cIsEq = (this).DatatypeIsEq(c); RAST._IType _69_datatypeType; _69_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create(((_68_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _69_datatypeType, _27_implBody))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, ((_68_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _69_datatypeType, _27_implBody))); if ((new BigInteger(((c).dtor_superTraitTypes).Count)).Sign == 1) { RAST._IType _70_fullType; if (_0_isRcWrapped) { @@ -1180,7 +1180,6 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _72_dummy = _out15; } else { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_71_downcastDefinitionOpt).dtor_value)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements()); } Std.Wrappers._IOption _73_downcastImplementationsOpt; _73_downcastImplementationsOpt = Defs.__default.DowncastImplFor(_3_rTypeParamsDecls, _70_fullType, _70_fullType); @@ -1333,20 +1332,18 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _110_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_109_i); _108_structAssignments = Dafny.Sequence.Concat(_108_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_110_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); } - Dafny.ISequence _111_defaultConstrainedTypeParams; - _111_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - RAST._IType _112_fullType; - _112_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); + RAST._IType _111_fullType; + _111_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); if ((false) && (_68_cIsEq)) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_111_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, _112_fullType, 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(_112_fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(_107_structName, _108_structAssignments))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _111_fullType, _107_structName, _108_structAssignments))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_3_rTypeParamsDecls, ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsType()).Apply1(_112_fullType), _112_fullType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfBorrowed), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self)))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _111_fullType))); } - Dafny.ISequence _113_superTraitImplementations; + Dafny.ISequence _112_superTraitImplementations; Dafny.ISequence _out18; _out18 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, Dafny.Sequence.UnicodeFromString("datatype")); - _113_superTraitImplementations = _out18; - s = Dafny.Sequence.Concat(s, _113_superTraitImplementations); + _112_superTraitImplementations = _out18; + s = Dafny.Sequence.Concat(s, _112_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -2040,7 +2037,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e { } after_match1: ; - _32_env = Defs.Environment.create(Dafny.Sequence>.Concat(_34_preAssignNames, _1_paramNames), Dafny.Map, RAST._IType>.Merge(_35_preAssignTypes, _2_paramTypes)); + _32_env = Defs.Environment.create(Dafny.Sequence>.Concat(_34_preAssignNames, _1_paramNames), Dafny.Map, RAST._IType>.Merge(_35_preAssignTypes, _2_paramTypes), Dafny.Set>.FromElements()); RAST._IExpr _50_body; Dafny.ISet> _51___v19; Defs._IEnvironment _52___v20; @@ -2053,10 +2050,10 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e _52___v20 = _out8; _31_fBody = Std.Wrappers.Option.create_Some((_33_preBody).Then(_50_body)); } else { - _32_env = Defs.Environment.create(_1_paramNames, _2_paramTypes); + _32_env = Defs.Environment.create(_1_paramNames, _2_paramTypes, Dafny.Set>.FromElements()); _31_fBody = Std.Wrappers.Option.create_None(); } - s = RAST.ImplMember.create_FnDecl(_21_visibility, RAST.Fn.create(_7_fnName, _25_typeParams, _0_params, Std.Wrappers.Option.create_Some((((new BigInteger((_18_retTypeArgs).Count)) == (BigInteger.One)) ? ((_18_retTypeArgs).Select(BigInteger.Zero)) : (RAST.Type.create_TupleType(_18_retTypeArgs)))), Dafny.Sequence.UnicodeFromString(""), _31_fBody)); + s = RAST.ImplMember.create_FnDecl((m).dtor_docString, RAST.__default.NoAttr, _21_visibility, RAST.Fn.create(_7_fnName, _25_typeParams, _0_params, Std.Wrappers.Option.create_Some((((new BigInteger((_18_retTypeArgs).Count)) == (BigInteger.One)) ? ((_18_retTypeArgs).Select(BigInteger.Zero)) : (RAST.Type.create_TupleType(_18_retTypeArgs)))), _31_fBody)); return s; } public void GenStmts(Dafny.ISequence stmts, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, bool isLast, Std.Wrappers._IOption>> earlyReturn, out RAST._IExpr generated, out Dafny.ISet> readIdents, out Defs._IEnvironment newEnv) @@ -2083,61 +2080,67 @@ public void GenStmts(Dafny.ISequence stmts, Defs._ISelfInfo se DAST._IType _5_optType = _source0.dtor_typ; Std.Wrappers._IOption maybeValue0 = _source0.dtor_maybeValue; if (maybeValue0.is_None) { - if (((_1_i) + (BigInteger.One)) < (new BigInteger((_2_stmts).Count))) { - DAST._IStatement _source1 = (_2_stmts).Select((_1_i) + (BigInteger.One)); - { - if (_source1.is_Assign) { - DAST._IAssignLhs lhs0 = _source1.dtor_lhs; - if (lhs0.is_Ident) { - Dafny.ISequence _6_name2 = lhs0.dtor_ident; - DAST._IExpression _7_rhs = _source1.dtor_value; - if (object.Equals(_6_name2, _4_name)) { - _2_stmts = Dafny.Sequence.Concat(Dafny.Sequence.Concat((_2_stmts).Subsequence(BigInteger.Zero, _1_i), Dafny.Sequence.FromElements(DAST.Statement.create_DeclareVar(_4_name, _5_optType, Std.Wrappers.Option.create_Some(_7_rhs)))), (_2_stmts).Drop((_1_i) + (new BigInteger(2)))); - _3_stmt = (_2_stmts).Select(_1_i); - } - goto after_match1; - } - } - } - { - } - after_match1: ; - } + Defs._IAssignmentStatus _6_laterAssignmentStatus; + _6_laterAssignmentStatus = Defs.__default.DetectAssignmentStatus((_2_stmts).Drop((_1_i) + (BigInteger.One)), _4_name); + newEnv = (newEnv).AddAssignmentStatus(Defs.__default.escapeVar(_4_name), _6_laterAssignmentStatus); goto after_match0; } } } + { + if (_source0.is_DeclareVar) { + Dafny.ISequence _7_name = _source0.dtor_name; + DAST._IType _8_optType = _source0.dtor_typ; + Std.Wrappers._IOption maybeValue1 = _source0.dtor_maybeValue; + if (maybeValue1.is_Some) { + DAST._IExpression value0 = maybeValue1.dtor_value; + if (value0.is_InitializationValue) { + DAST._IType _9_typ = value0.dtor_typ; + RAST._IType _10_tpe; + RAST._IType _out0; + _out0 = (this).GenType(_9_typ, Defs.GenTypeContext.@default()); + _10_tpe = _out0; + Dafny.ISequence _11_varName; + _11_varName = Defs.__default.escapeVar(_7_name); + Defs._IAssignmentStatus _12_laterAssignmentStatus; + _12_laterAssignmentStatus = Defs.__default.DetectAssignmentStatus((_2_stmts).Drop((_1_i) + (BigInteger.One)), _7_name); + newEnv = (newEnv).AddAssignmentStatus(_11_varName, _12_laterAssignmentStatus); + goto after_match0; + } + } + } + } { } after_match0: ; - RAST._IExpr _8_stmtExpr; - Dafny.ISet> _9_recIdents; - Defs._IEnvironment _10_newEnv2; - RAST._IExpr _out0; - Dafny.ISet> _out1; - Defs._IEnvironment _out2; - (this).GenStmt(_3_stmt, selfIdent, newEnv, (isLast) && ((_1_i) == ((new BigInteger((_2_stmts).Count)) - (BigInteger.One))), earlyReturn, out _out0, out _out1, out _out2); - _8_stmtExpr = _out0; - _9_recIdents = _out1; - _10_newEnv2 = _out2; - newEnv = _10_newEnv2; - DAST._IStatement _source2 = _3_stmt; + RAST._IExpr _13_stmtExpr; + Dafny.ISet> _14_recIdents; + Defs._IEnvironment _15_newEnv2; + RAST._IExpr _out1; + Dafny.ISet> _out2; + Defs._IEnvironment _out3; + (this).GenStmt(_3_stmt, selfIdent, newEnv, (isLast) && ((_1_i) == ((new BigInteger((_2_stmts).Count)) - (BigInteger.One))), earlyReturn, out _out1, out _out2, out _out3); + _13_stmtExpr = _out1; + _14_recIdents = _out2; + _15_newEnv2 = _out3; + newEnv = _15_newEnv2; + DAST._IStatement _source1 = _3_stmt; { - if (_source2.is_DeclareVar) { - Dafny.ISequence _11_name = _source2.dtor_name; + if (_source1.is_DeclareVar) { + Dafny.ISequence _16_name = _source1.dtor_name; { - _0_declarations = Dafny.Set>.Union(_0_declarations, Dafny.Set>.FromElements(Defs.__default.escapeVar(_11_name))); + _0_declarations = Dafny.Set>.Union(_0_declarations, Dafny.Set>.FromElements(Defs.__default.escapeVar(_16_name))); } - goto after_match2; + goto after_match1; } } { } - after_match2: ; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_9_recIdents, _0_declarations)); - generated = (generated).Then(_8_stmtExpr); + after_match1: ; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_14_recIdents, _0_declarations)); + generated = (generated).Then(_13_stmtExpr); _1_i = (_1_i) + (BigInteger.One); - if ((_8_stmtExpr).is_Return) { + if ((_13_stmtExpr).is_Return) { goto after_0; } continue_0: ; @@ -2277,14 +2280,14 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Defs._ISelfInfo BigInteger _hi0 = new BigInteger((_12_indices).Count); for (BigInteger _18_i = BigInteger.Zero; _18_i < _hi0; _18_i++) { RAST._IExpr _19_idx; - Defs._IOwnership _20___v29; + Defs._IOwnership _20___v28; Dafny.ISet> _21_recIdentsIdx; RAST._IExpr _out6; Defs._IOwnership _out7; Dafny.ISet> _out8; (this).GenExpr((_12_indices).Select(_18_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out6, out _out7, out _out8); _19_idx = _out6; - _20___v29 = _out7; + _20___v28 = _out7; _21_recIdentsIdx = _out8; Dafny.ISequence _22_varName; _22_varName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("__idx"), Std.Strings.__default.OfNat(_18_i)); @@ -2395,14 +2398,14 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D } { RAST._IExpr _12_onExpr; - Defs._IOwnership _13___v34; + Defs._IOwnership _13___v33; Dafny.ISet> _14_recIdents; RAST._IExpr _out18; Defs._IOwnership _out19; Dafny.ISet> _out20; (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out18, out _out19, out _out20); _12_onExpr = _out18; - _13___v34 = _out19; + _13___v33 = _out19; _14_recIdents = _out20; readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); Dafny.ISequence _15_renderedName; @@ -2482,15 +2485,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _5_isAssignedVar = Defs.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { RAST._IExpr _6_rhs; - Defs._IOwnership _7___v44; - Dafny.ISet> _8___v45; + Defs._IOwnership _7___v43; + Dafny.ISet> _8___v44; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr(DAST.Expression.create_InitializationValue(((_2_field).dtor_formal).dtor_typ), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); _6_rhs = _out1; - _7___v44 = _out2; - _8___v45 = _out3; + _7___v43 = _out2; + _8___v44 = _out3; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); Dafny.ISequence _9_update__if__uninit; if ((_2_field).dtor_isConstant) { @@ -2523,32 +2526,42 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv bool _15_hasCopySemantics; _15_hasCopySemantics = (_13_tpe).CanReadWithoutClone(); if (((_12_expression).is_InitializationValue) && (!(_15_hasCopySemantics))) { - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _14_varName, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((((RAST.__default.MaybePlaceboPath).AsExpr()).ApplyType1(_13_tpe)).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0())); - readIdents = Dafny.Set>.FromElements(); - newEnv = (env).AddAssigned(_14_varName, RAST.__default.MaybePlaceboType(_13_tpe)); + if ((env).IsAssignmentStatusKnown(_14_varName)) { + RAST._IType _16_tpe; + RAST._IType _out5; + _out5 = (this).GenType(_11_typ, Defs.GenTypeContext.@default()); + _16_tpe = _out5; + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _14_varName, Std.Wrappers.Option.create_Some(_16_tpe), Std.Wrappers.Option.create_None()); + readIdents = Dafny.Set>.FromElements(); + newEnv = (env).AddAssigned(_14_varName, _16_tpe); + } else { + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _14_varName, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((((RAST.__default.MaybePlaceboPath).AsExpr()).ApplyType1(_13_tpe)).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0())); + readIdents = Dafny.Set>.FromElements(); + newEnv = (env).AddAssigned(_14_varName, RAST.__default.MaybePlaceboType(_13_tpe)); + } } else { - RAST._IExpr _16_expr = RAST.Expr.Default(); - Dafny.ISet> _17_recIdents = Dafny.Set>.Empty; + RAST._IExpr _17_expr = RAST.Expr.Default(); + Dafny.ISet> _18_recIdents = Dafny.Set>.Empty; if (((_12_expression).is_InitializationValue) && ((_13_tpe).IsObjectOrPointer())) { - _16_expr = (_13_tpe).ToNullExpr(); - _17_recIdents = Dafny.Set>.FromElements(); + _17_expr = (_13_tpe).ToNullExpr(); + _18_recIdents = Dafny.Set>.FromElements(); } else { - Defs._IOwnership _18_exprOwnership = Defs.Ownership.Default(); - RAST._IExpr _out5; - Defs._IOwnership _out6; - Dafny.ISet> _out7; - (this).GenExpr(_12_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); - _16_expr = _out5; - _18_exprOwnership = _out6; - _17_recIdents = _out7; + Defs._IOwnership _19_exprOwnership = Defs.Ownership.Default(); + RAST._IExpr _out6; + Defs._IOwnership _out7; + Dafny.ISet> _out8; + (this).GenExpr(_12_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out6, out _out7, out _out8); + _17_expr = _out6; + _19_exprOwnership = _out7; + _18_recIdents = _out8; } - readIdents = _17_recIdents; + readIdents = _18_recIdents; if ((_12_expression).is_NewUninitArray) { _13_tpe = (_13_tpe).TypeAtInitialization(); } else { _13_tpe = _13_tpe; } - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _14_varName, Std.Wrappers.Option.create_Some(_13_tpe), Std.Wrappers.Option.create_Some(_16_expr)); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _14_varName, Std.Wrappers.Option.create_Some(_13_tpe), Std.Wrappers.Option.create_Some(_17_expr)); newEnv = (env).AddAssigned(_14_varName, _13_tpe); } } @@ -2558,20 +2571,32 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_DeclareVar) { - Dafny.ISequence _19_name = _source0.dtor_name; - DAST._IType _20_typ = _source0.dtor_typ; + Dafny.ISequence _20_name = _source0.dtor_name; + DAST._IType _21_typ = _source0.dtor_typ; Std.Wrappers._IOption maybeValue1 = _source0.dtor_maybeValue; if (maybeValue1.is_None) { { - DAST._IStatement _21_newStmt; - _21_newStmt = DAST.Statement.create_DeclareVar(_19_name, _20_typ, Std.Wrappers.Option.create_Some(DAST.Expression.create_InitializationValue(_20_typ))); - RAST._IExpr _out8; - Dafny.ISet> _out9; - Defs._IEnvironment _out10; - (this).GenStmt(_21_newStmt, selfIdent, env, isLast, earlyReturn, out _out8, out _out9, out _out10); - generated = _out8; - readIdents = _out9; - newEnv = _out10; + Dafny.ISequence _22_varName; + _22_varName = Defs.__default.escapeVar(_20_name); + if ((env).IsAssignmentStatusKnown(_22_varName)) { + RAST._IType _23_tpe; + RAST._IType _out9; + _out9 = (this).GenType(_21_typ, Defs.GenTypeContext.@default()); + _23_tpe = _out9; + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _22_varName, Std.Wrappers.Option.create_Some(_23_tpe), Std.Wrappers.Option.create_None()); + readIdents = Dafny.Set>.FromElements(); + newEnv = (env).AddAssigned(_22_varName, _23_tpe); + } else { + DAST._IStatement _24_newStmt; + _24_newStmt = DAST.Statement.create_DeclareVar(_20_name, _21_typ, Std.Wrappers.Option.create_Some(DAST.Expression.create_InitializationValue(_21_typ))); + RAST._IExpr _out10; + Dafny.ISet> _out11; + Defs._IEnvironment _out12; + (this).GenStmt(_24_newStmt, selfIdent, env, isLast, earlyReturn, out _out10, out _out11, out _out12); + generated = _out10; + readIdents = _out11; + newEnv = _out12; + } } goto after_match0; } @@ -2579,124 +2604,124 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_Assign) { - DAST._IAssignLhs _22_lhs = _source0.dtor_lhs; - DAST._IExpression _23_expression = _source0.dtor_value; + DAST._IAssignLhs _25_lhs = _source0.dtor_lhs; + DAST._IExpression _26_expression = _source0.dtor_value; { - RAST._IExpr _24_exprGen; - Defs._IOwnership _25___v46; - Dafny.ISet> _26_exprIdents; - RAST._IExpr _out11; - Defs._IOwnership _out12; - Dafny.ISet> _out13; - (this).GenExpr(_23_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out11, out _out12, out _out13); - _24_exprGen = _out11; - _25___v46 = _out12; - _26_exprIdents = _out13; - if ((_22_lhs).is_Ident) { - Dafny.ISequence _27_rustId; - _27_rustId = Defs.__default.escapeVar((_22_lhs).dtor_ident); - Std.Wrappers._IOption _28_tpe; - _28_tpe = (env).GetType(_27_rustId); - if (((_28_tpe).is_Some) && ((((_28_tpe).dtor_value).ExtractMaybePlacebo()).is_Some)) { - _24_exprGen = RAST.__default.MaybePlacebo(_24_exprGen); + RAST._IExpr _27_exprGen; + Defs._IOwnership _28___v45; + Dafny.ISet> _29_exprIdents; + RAST._IExpr _out13; + Defs._IOwnership _out14; + Dafny.ISet> _out15; + (this).GenExpr(_26_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out13, out _out14, out _out15); + _27_exprGen = _out13; + _28___v45 = _out14; + _29_exprIdents = _out15; + if ((_25_lhs).is_Ident) { + Dafny.ISequence _30_rustId; + _30_rustId = Defs.__default.escapeVar((_25_lhs).dtor_ident); + Std.Wrappers._IOption _31_tpe; + _31_tpe = (env).GetType(_30_rustId); + if (((_31_tpe).is_Some) && ((((_31_tpe).dtor_value).ExtractMaybePlacebo()).is_Some)) { + _27_exprGen = RAST.__default.MaybePlacebo(_27_exprGen); } } - if (((_22_lhs).is_Index) && (((_22_lhs).dtor_expr).is_Ident)) { - Dafny.ISequence _29_rustId; - _29_rustId = Defs.__default.escapeVar(((_22_lhs).dtor_expr).dtor_name); - Std.Wrappers._IOption _30_tpe; - _30_tpe = (env).GetType(_29_rustId); - if (((_30_tpe).is_Some) && ((((_30_tpe).dtor_value).ExtractMaybeUninitArrayElement()).is_Some)) { - _24_exprGen = RAST.__default.MaybeUninitNew(_24_exprGen); + if (((_25_lhs).is_Index) && (((_25_lhs).dtor_expr).is_Ident)) { + Dafny.ISequence _32_rustId; + _32_rustId = Defs.__default.escapeVar(((_25_lhs).dtor_expr).dtor_name); + Std.Wrappers._IOption _33_tpe; + _33_tpe = (env).GetType(_32_rustId); + if (((_33_tpe).is_Some) && ((((_33_tpe).dtor_value).ExtractMaybeUninitArrayElement()).is_Some)) { + _27_exprGen = RAST.__default.MaybeUninitNew(_27_exprGen); } } - RAST._IExpr _31_lhsGen; - bool _32_needsIIFE; - Dafny.ISet> _33_recIdents; - Defs._IEnvironment _34_resEnv; - RAST._IExpr _out14; - bool _out15; - Dafny.ISet> _out16; - Defs._IEnvironment _out17; - (this).GenAssignLhs(_22_lhs, _24_exprGen, selfIdent, env, out _out14, out _out15, out _out16, out _out17); - _31_lhsGen = _out14; - _32_needsIIFE = _out15; - _33_recIdents = _out16; - _34_resEnv = _out17; - generated = _31_lhsGen; - newEnv = _34_resEnv; - if (_32_needsIIFE) { + RAST._IExpr _34_lhsGen; + bool _35_needsIIFE; + Dafny.ISet> _36_recIdents; + Defs._IEnvironment _37_resEnv; + RAST._IExpr _out16; + bool _out17; + Dafny.ISet> _out18; + Defs._IEnvironment _out19; + (this).GenAssignLhs(_25_lhs, _27_exprGen, selfIdent, env, out _out16, out _out17, out _out18, out _out19); + _34_lhsGen = _out16; + _35_needsIIFE = _out17; + _36_recIdents = _out18; + _37_resEnv = _out19; + generated = _34_lhsGen; + newEnv = _37_resEnv; + if (_35_needsIIFE) { generated = RAST.Expr.create_Block(generated); } - readIdents = Dafny.Set>.Union(_33_recIdents, _26_exprIdents); + readIdents = Dafny.Set>.Union(_36_recIdents, _29_exprIdents); } goto after_match0; } } { if (_source0.is_If) { - DAST._IExpression _35_cond = _source0.dtor_cond; - Dafny.ISequence _36_thnDafny = _source0.dtor_thn; - Dafny.ISequence _37_elsDafny = _source0.dtor_els; + DAST._IExpression _38_cond = _source0.dtor_cond; + Dafny.ISequence _39_thnDafny = _source0.dtor_thn; + Dafny.ISequence _40_elsDafny = _source0.dtor_els; { - RAST._IExpr _38_cond; - Defs._IOwnership _39___v47; - Dafny.ISet> _40_recIdents; - RAST._IExpr _out18; - Defs._IOwnership _out19; - Dafny.ISet> _out20; - (this).GenExpr(_35_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out18, out _out19, out _out20); - _38_cond = _out18; - _39___v47 = _out19; - _40_recIdents = _out20; - Dafny.ISequence _41_condString; - _41_condString = (_38_cond)._ToString(Defs.__default.IND); - readIdents = _40_recIdents; - RAST._IExpr _42_thn; - Dafny.ISet> _43_thnIdents; - Defs._IEnvironment _44_thnEnv; - RAST._IExpr _out21; + RAST._IExpr _41_cond; + Defs._IOwnership _42___v46; + Dafny.ISet> _43_recIdents; + RAST._IExpr _out20; + Defs._IOwnership _out21; Dafny.ISet> _out22; - Defs._IEnvironment _out23; - (this).GenStmts(_36_thnDafny, selfIdent, env, isLast, earlyReturn, out _out21, out _out22, out _out23); - _42_thn = _out21; - _43_thnIdents = _out22; - _44_thnEnv = _out23; - readIdents = Dafny.Set>.Union(readIdents, _43_thnIdents); - RAST._IExpr _45_els; - Dafny.ISet> _46_elsIdents; - Defs._IEnvironment _47_elsEnv; - RAST._IExpr _out24; - Dafny.ISet> _out25; - Defs._IEnvironment _out26; - (this).GenStmts(_37_elsDafny, selfIdent, env, isLast, earlyReturn, out _out24, out _out25, out _out26); - _45_els = _out24; - _46_elsIdents = _out25; - _47_elsEnv = _out26; - readIdents = Dafny.Set>.Union(readIdents, _46_elsIdents); + (this).GenExpr(_38_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out20, out _out21, out _out22); + _41_cond = _out20; + _42___v46 = _out21; + _43_recIdents = _out22; + Dafny.ISequence _44_condString; + _44_condString = (_41_cond)._ToString(Defs.__default.IND); + readIdents = _43_recIdents; + RAST._IExpr _45_thn; + Dafny.ISet> _46_thnIdents; + Defs._IEnvironment _47_thnEnv; + RAST._IExpr _out23; + Dafny.ISet> _out24; + Defs._IEnvironment _out25; + (this).GenStmts(_39_thnDafny, selfIdent, env, isLast, earlyReturn, out _out23, out _out24, out _out25); + _45_thn = _out23; + _46_thnIdents = _out24; + _47_thnEnv = _out25; + readIdents = Dafny.Set>.Union(readIdents, _46_thnIdents); + RAST._IExpr _48_els; + Dafny.ISet> _49_elsIdents; + Defs._IEnvironment _50_elsEnv; + RAST._IExpr _out26; + Dafny.ISet> _out27; + Defs._IEnvironment _out28; + (this).GenStmts(_40_elsDafny, selfIdent, env, isLast, earlyReturn, out _out26, out _out27, out _out28); + _48_els = _out26; + _49_elsIdents = _out27; + _50_elsEnv = _out28; + readIdents = Dafny.Set>.Union(readIdents, _49_elsIdents); newEnv = env; - generated = RAST.Expr.create_IfExpr(_38_cond, _42_thn, _45_els); + generated = RAST.Expr.create_IfExpr(_41_cond, _45_thn, _48_els); } goto after_match0; } } { if (_source0.is_Labeled) { - Dafny.ISequence _48_lbl = _source0.dtor_lbl; - Dafny.ISequence _49_body = _source0.dtor_body; + Dafny.ISequence _51_lbl = _source0.dtor_lbl; + Dafny.ISequence _52_body = _source0.dtor_body; { - RAST._IExpr _50_body; - Dafny.ISet> _51_bodyIdents; - Defs._IEnvironment _52_env2; - RAST._IExpr _out27; - Dafny.ISet> _out28; - Defs._IEnvironment _out29; - (this).GenStmts(_49_body, selfIdent, env, isLast, earlyReturn, out _out27, out _out28, out _out29); - _50_body = _out27; - _51_bodyIdents = _out28; - _52_env2 = _out29; - readIdents = _51_bodyIdents; - generated = RAST.Expr.create_Labelled(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _48_lbl), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), RAST.Expr.create_StmtExpr(_50_body, RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())))); + RAST._IExpr _53_body; + Dafny.ISet> _54_bodyIdents; + Defs._IEnvironment _55_env2; + RAST._IExpr _out29; + Dafny.ISet> _out30; + Defs._IEnvironment _out31; + (this).GenStmts(_52_body, selfIdent, env, isLast, earlyReturn, out _out29, out _out30, out _out31); + _53_body = _out29; + _54_bodyIdents = _out30; + _55_env2 = _out31; + readIdents = _54_bodyIdents; + generated = RAST.Expr.create_Labelled(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _51_lbl), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), RAST.Expr.create_StmtExpr(_53_body, RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())))); newEnv = env; } goto after_match0; @@ -2704,91 +2729,91 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_While) { - DAST._IExpression _53_cond = _source0.dtor_cond; - Dafny.ISequence _54_body = _source0.dtor_body; + DAST._IExpression _56_cond = _source0.dtor_cond; + Dafny.ISequence _57_body = _source0.dtor_body; { - RAST._IExpr _55_cond; - Defs._IOwnership _56___v48; - Dafny.ISet> _57_recIdents; - RAST._IExpr _out30; - Defs._IOwnership _out31; - Dafny.ISet> _out32; - (this).GenExpr(_53_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); - _55_cond = _out30; - _56___v48 = _out31; - _57_recIdents = _out32; - readIdents = _57_recIdents; - RAST._IExpr _58_bodyExpr; - Dafny.ISet> _59_bodyIdents; - Defs._IEnvironment _60_bodyEnv; - RAST._IExpr _out33; + RAST._IExpr _58_cond; + Defs._IOwnership _59___v47; + Dafny.ISet> _60_recIdents; + RAST._IExpr _out32; + Defs._IOwnership _out33; Dafny.ISet> _out34; - Defs._IEnvironment _out35; - (this).GenStmts(_54_body, selfIdent, env, false, earlyReturn, out _out33, out _out34, out _out35); - _58_bodyExpr = _out33; - _59_bodyIdents = _out34; - _60_bodyEnv = _out35; + (this).GenExpr(_56_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out32, out _out33, out _out34); + _58_cond = _out32; + _59___v47 = _out33; + _60_recIdents = _out34; + readIdents = _60_recIdents; + RAST._IExpr _61_bodyExpr; + Dafny.ISet> _62_bodyIdents; + Defs._IEnvironment _63_bodyEnv; + RAST._IExpr _out35; + Dafny.ISet> _out36; + Defs._IEnvironment _out37; + (this).GenStmts(_57_body, selfIdent, env, false, earlyReturn, out _out35, out _out36, out _out37); + _61_bodyExpr = _out35; + _62_bodyIdents = _out36; + _63_bodyEnv = _out37; newEnv = env; - readIdents = Dafny.Set>.Union(readIdents, _59_bodyIdents); - generated = RAST.Expr.create_Loop(Std.Wrappers.Option.create_Some(_55_cond), _58_bodyExpr); + readIdents = Dafny.Set>.Union(readIdents, _62_bodyIdents); + generated = RAST.Expr.create_Loop(Std.Wrappers.Option.create_Some(_58_cond), _61_bodyExpr); } goto after_match0; } } { if (_source0.is_Foreach) { - Dafny.ISequence _61_boundName = _source0.dtor_boundName; - DAST._IType _62_boundType = _source0.dtor_boundType; - DAST._IExpression _63_overExpr = _source0.dtor_over; - Dafny.ISequence _64_body = _source0.dtor_body; + Dafny.ISequence _64_boundName = _source0.dtor_boundName; + DAST._IType _65_boundType = _source0.dtor_boundType; + DAST._IExpression _66_overExpr = _source0.dtor_over; + Dafny.ISequence _67_body = _source0.dtor_body; { - RAST._IExpr _65_over; - Defs._IOwnership _66___v49; - Dafny.ISet> _67_recIdents; - RAST._IExpr _out36; - Defs._IOwnership _out37; - Dafny.ISet> _out38; - (this).GenExpr(_63_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out36, out _out37, out _out38); - _65_over = _out36; - _66___v49 = _out37; - _67_recIdents = _out38; - if (((_63_overExpr).is_MapBoundedPool) || ((_63_overExpr).is_SetBoundedPool)) { - _65_over = ((_65_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); - } - RAST._IType _68_boundTpe; - RAST._IType _out39; - _out39 = (this).GenType(_62_boundType, Defs.GenTypeContext.@default()); - _68_boundTpe = _out39; - readIdents = _67_recIdents; - Dafny.ISequence _69_boundRName; - _69_boundRName = Defs.__default.escapeVar(_61_boundName); - RAST._IExpr _70_bodyExpr; - Dafny.ISet> _71_bodyIdents; - Defs._IEnvironment _72_bodyEnv; - RAST._IExpr _out40; - Dafny.ISet> _out41; - Defs._IEnvironment _out42; - (this).GenStmts(_64_body, selfIdent, (env).AddAssigned(_69_boundRName, _68_boundTpe), false, earlyReturn, out _out40, out _out41, out _out42); - _70_bodyExpr = _out40; - _71_bodyIdents = _out41; - _72_bodyEnv = _out42; - readIdents = Dafny.Set>.Difference(Dafny.Set>.Union(readIdents, _71_bodyIdents), Dafny.Set>.FromElements(_69_boundRName)); + RAST._IExpr _68_over; + Defs._IOwnership _69___v48; + Dafny.ISet> _70_recIdents; + RAST._IExpr _out38; + Defs._IOwnership _out39; + Dafny.ISet> _out40; + (this).GenExpr(_66_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out38, out _out39, out _out40); + _68_over = _out38; + _69___v48 = _out39; + _70_recIdents = _out40; + if (((_66_overExpr).is_MapBoundedPool) || ((_66_overExpr).is_SetBoundedPool)) { + _68_over = ((_68_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); + } + RAST._IType _71_boundTpe; + RAST._IType _out41; + _out41 = (this).GenType(_65_boundType, Defs.GenTypeContext.@default()); + _71_boundTpe = _out41; + readIdents = _70_recIdents; + Dafny.ISequence _72_boundRName; + _72_boundRName = Defs.__default.escapeVar(_64_boundName); + RAST._IExpr _73_bodyExpr; + Dafny.ISet> _74_bodyIdents; + Defs._IEnvironment _75_bodyEnv; + RAST._IExpr _out42; + Dafny.ISet> _out43; + Defs._IEnvironment _out44; + (this).GenStmts(_67_body, selfIdent, (env).AddAssigned(_72_boundRName, _71_boundTpe), false, earlyReturn, out _out42, out _out43, out _out44); + _73_bodyExpr = _out42; + _74_bodyIdents = _out43; + _75_bodyEnv = _out44; + readIdents = Dafny.Set>.Difference(Dafny.Set>.Union(readIdents, _74_bodyIdents), Dafny.Set>.FromElements(_72_boundRName)); newEnv = env; - generated = RAST.Expr.create_For(_69_boundRName, _65_over, _70_bodyExpr); + generated = RAST.Expr.create_For(_72_boundRName, _68_over, _73_bodyExpr); } goto after_match0; } } { if (_source0.is_Break) { - Std.Wrappers._IOption> _73_toLabel = _source0.dtor_toLabel; + Std.Wrappers._IOption> _76_toLabel = _source0.dtor_toLabel; { - Std.Wrappers._IOption> _source1 = _73_toLabel; + Std.Wrappers._IOption> _source1 = _76_toLabel; { if (_source1.is_Some) { - Dafny.ISequence _74_lbl = _source1.dtor_value; + Dafny.ISequence _77_lbl = _source1.dtor_value; { - generated = RAST.Expr.create_Break(Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _74_lbl))); + generated = RAST.Expr.create_Break(Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _77_lbl))); } goto after_match1; } @@ -2807,72 +2832,72 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_TailRecursive) { - Dafny.ISequence _75_body = _source0.dtor_body; + Dafny.ISequence _78_body = _source0.dtor_body; { generated = (this).InitEmptyExpr(); - Defs._IEnvironment _76_oldEnv; - _76_oldEnv = env; + Defs._IEnvironment _79_oldEnv; + _79_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { - RAST._IExpr _77_selfClone; - Defs._IOwnership _78___v50; - Dafny.ISet> _79___v51; - RAST._IExpr _out43; - Defs._IOwnership _out44; - Dafny.ISet> _out45; - (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out43, out _out44, out _out45); - _77_selfClone = _out43; - _78___v50 = _out44; - _79___v51 = _out45; - generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_77_selfClone))); - if (((_76_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { - _76_oldEnv = (_76_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); + RAST._IExpr _80_selfClone; + Defs._IOwnership _81___v49; + Dafny.ISet> _82___v50; + RAST._IExpr _out45; + Defs._IOwnership _out46; + Dafny.ISet> _out47; + (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out45, out _out46, out _out47); + _80_selfClone = _out45; + _81___v49 = _out46; + _82___v50 = _out47; + 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(_80_selfClone))); + if (((_79_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { + _79_oldEnv = (_79_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); } } - RAST._IExpr _80_loopBegin; - _80_loopBegin = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); + RAST._IExpr _83_loopBegin; + _83_loopBegin = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); newEnv = env; - BigInteger _hi1 = new BigInteger(((_76_oldEnv).dtor_names).Count); - for (BigInteger _81_paramI = BigInteger.Zero; _81_paramI < _hi1; _81_paramI++) { - Dafny.ISequence _82_param; - _82_param = ((_76_oldEnv).dtor_names).Select(_81_paramI); - if ((_82_param).Equals(Dafny.Sequence.UnicodeFromString("_accumulator"))) { + BigInteger _hi1 = new BigInteger(((_79_oldEnv).dtor_names).Count); + for (BigInteger _84_paramI = BigInteger.Zero; _84_paramI < _hi1; _84_paramI++) { + Dafny.ISequence _85_param; + _85_param = ((_79_oldEnv).dtor_names).Select(_84_paramI); + if ((_85_param).Equals(Dafny.Sequence.UnicodeFromString("_accumulator"))) { goto continue_4_0; } - RAST._IExpr _83_paramInit; - Defs._IOwnership _84___v52; - Dafny.ISet> _85___v53; - RAST._IExpr _out46; - Defs._IOwnership _out47; - Dafny.ISet> _out48; - (this).GenIdent(_82_param, selfIdent, _76_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out46, out _out47, out _out48); - _83_paramInit = _out46; - _84___v52 = _out47; - _85___v53 = _out48; - Dafny.ISequence _86_recVar; - _86_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_81_paramI)); - generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _86_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_83_paramInit))); - if (((_76_oldEnv).dtor_types).Contains(_82_param)) { - RAST._IType _87_declaredType; - _87_declaredType = (Dafny.Map, RAST._IType>.Select((_76_oldEnv).dtor_types,_82_param)).ToOwned(); - newEnv = (newEnv).AddAssigned(_82_param, _87_declaredType); - newEnv = (newEnv).AddAssigned(_86_recVar, _87_declaredType); + RAST._IExpr _86_paramInit; + Defs._IOwnership _87___v51; + Dafny.ISet> _88___v52; + RAST._IExpr _out48; + Defs._IOwnership _out49; + Dafny.ISet> _out50; + (this).GenIdent(_85_param, selfIdent, _79_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out48, out _out49, out _out50); + _86_paramInit = _out48; + _87___v51 = _out49; + _88___v52 = _out50; + Dafny.ISequence _89_recVar; + _89_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_84_paramI)); + generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _89_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_86_paramInit))); + if (((_79_oldEnv).dtor_types).Contains(_85_param)) { + RAST._IType _90_declaredType; + _90_declaredType = (Dafny.Map, RAST._IType>.Select((_79_oldEnv).dtor_types,_85_param)).ToOwned(); + newEnv = (newEnv).AddAssigned(_85_param, _90_declaredType); + newEnv = (newEnv).AddAssigned(_89_recVar, _90_declaredType); } - _80_loopBegin = (_80_loopBegin).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _82_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_86_recVar)))); + _83_loopBegin = (_83_loopBegin).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _85_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_89_recVar)))); continue_4_0: ; } after_4_0: ; - RAST._IExpr _88_bodyExpr; - Dafny.ISet> _89_bodyIdents; - Defs._IEnvironment _90_bodyEnv; - RAST._IExpr _out49; - Dafny.ISet> _out50; - Defs._IEnvironment _out51; - (this).GenStmts(_75_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), newEnv, false, earlyReturn, out _out49, out _out50, out _out51); - _88_bodyExpr = _out49; - _89_bodyIdents = _out50; - _90_bodyEnv = _out51; - readIdents = _89_bodyIdents; - generated = (generated).Then(RAST.Expr.create_Labelled(Dafny.Sequence.UnicodeFromString("TAIL_CALL_START"), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), (_80_loopBegin).Then(_88_bodyExpr)))); + RAST._IExpr _91_bodyExpr; + Dafny.ISet> _92_bodyIdents; + Defs._IEnvironment _93_bodyEnv; + RAST._IExpr _out51; + Dafny.ISet> _out52; + Defs._IEnvironment _out53; + (this).GenStmts(_78_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), newEnv, false, earlyReturn, out _out51, out _out52, out _out53); + _91_bodyExpr = _out51; + _92_bodyIdents = _out52; + _93_bodyEnv = _out53; + readIdents = _92_bodyIdents; + generated = (generated).Then(RAST.Expr.create_Labelled(Dafny.Sequence.UnicodeFromString("TAIL_CALL_START"), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), (_83_loopBegin).Then(_91_bodyExpr)))); } goto after_match0; } @@ -2889,43 +2914,44 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_Call) { - DAST._IExpression _91_on = _source0.dtor_on; - DAST._ICallName _92_name = _source0.dtor_callName; - Dafny.ISequence _93_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _94_args = _source0.dtor_args; - Std.Wrappers._IOption>> _95_maybeOutVars = _source0.dtor_outs; + DAST._IExpression _94_on = _source0.dtor_on; + DAST._ICallName _95_name = _source0.dtor_callName; + Dafny.ISequence _96_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _97_args = _source0.dtor_args; + Std.Wrappers._IOption>> _98_maybeOutVars = _source0.dtor_outs; { - RAST._IExpr _out52; - Dafny.ISet> _out53; - (this).GenOwnedCallPart(_91_on, selfIdent, _92_name, _93_typeArgs, _94_args, env, out _out52, out _out53); - generated = _out52; - readIdents = _out53; - if (((_95_maybeOutVars).is_Some) && ((new BigInteger(((_95_maybeOutVars).dtor_value).Count)) == (BigInteger.One))) { - Dafny.ISequence _96_outVar; - _96_outVar = Defs.__default.escapeVar(((_95_maybeOutVars).dtor_value).Select(BigInteger.Zero)); - if (!((env).CanReadWithoutClone(_96_outVar))) { + RAST._IExpr _out54; + Dafny.ISet> _out55; + (this).GenOwnedCallPart(_94_on, selfIdent, _95_name, _96_typeArgs, _97_args, env, out _out54, out _out55); + generated = _out54; + readIdents = _out55; + newEnv = env; + if (((_98_maybeOutVars).is_Some) && ((new BigInteger(((_98_maybeOutVars).dtor_value).Count)) == (BigInteger.One))) { + Dafny.ISequence _99_outVar; + _99_outVar = Defs.__default.escapeVar(((_98_maybeOutVars).dtor_value).Select(BigInteger.Zero)); + if ((env).IsMaybePlacebo(_99_outVar)) { generated = RAST.__default.MaybePlacebo(generated); } - generated = RAST.__default.AssignVar(_96_outVar, generated); - } else if (((_95_maybeOutVars).is_None) || ((new BigInteger(((_95_maybeOutVars).dtor_value).Count)).Sign == 0)) { + generated = RAST.__default.AssignVar(_99_outVar, generated); + } else if (((_98_maybeOutVars).is_None) || ((new BigInteger(((_98_maybeOutVars).dtor_value).Count)).Sign == 0)) { } else { - Dafny.ISequence _97_tmpVar; - _97_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); - RAST._IExpr _98_tmpId; - _98_tmpId = RAST.Expr.create_Identifier(_97_tmpVar); - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _97_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); - Dafny.ISequence> _99_outVars; - _99_outVars = (_95_maybeOutVars).dtor_value; - BigInteger _hi2 = new BigInteger((_99_outVars).Count); - for (BigInteger _100_outI = BigInteger.Zero; _100_outI < _hi2; _100_outI++) { - Dafny.ISequence _101_outVar; - _101_outVar = Defs.__default.escapeVar((_99_outVars).Select(_100_outI)); - RAST._IExpr _102_rhs; - _102_rhs = (_98_tmpId).Sel(Std.Strings.__default.OfNat(_100_outI)); - if (!((env).CanReadWithoutClone(_101_outVar))) { - _102_rhs = RAST.__default.MaybePlacebo(_102_rhs); + Dafny.ISequence _100_tmpVar; + _100_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); + RAST._IExpr _101_tmpId; + _101_tmpId = RAST.Expr.create_Identifier(_100_tmpVar); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _100_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); + Dafny.ISequence> _102_outVars; + _102_outVars = (_98_maybeOutVars).dtor_value; + BigInteger _hi2 = new BigInteger((_102_outVars).Count); + for (BigInteger _103_outI = BigInteger.Zero; _103_outI < _hi2; _103_outI++) { + Dafny.ISequence _104_outVar; + _104_outVar = Defs.__default.escapeVar((_102_outVars).Select(_103_outI)); + RAST._IExpr _105_rhs; + _105_rhs = (_101_tmpId).Sel(Std.Strings.__default.OfNat(_103_outI)); + if ((env).IsMaybePlacebo(_104_outVar)) { + _105_rhs = RAST.__default.MaybePlacebo(_105_rhs); } - generated = (generated).Then(RAST.__default.AssignVar(_101_outVar, _102_rhs)); + generated = (generated).Then(RAST.__default.AssignVar(_104_outVar, _105_rhs)); } } newEnv = env; @@ -2935,23 +2961,23 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_Return) { - DAST._IExpression _103_exprDafny = _source0.dtor_expr; + DAST._IExpression _106_exprDafny = _source0.dtor_expr; { - RAST._IExpr _104_expr; - Defs._IOwnership _105___v54; - Dafny.ISet> _106_recIdents; - RAST._IExpr _out54; - Defs._IOwnership _out55; - Dafny.ISet> _out56; - (this).GenExpr(_103_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out54, out _out55, out _out56); - _104_expr = _out54; - _105___v54 = _out55; - _106_recIdents = _out56; - readIdents = _106_recIdents; + RAST._IExpr _107_expr; + Defs._IOwnership _108___v53; + Dafny.ISet> _109_recIdents; + RAST._IExpr _out56; + Defs._IOwnership _out57; + Dafny.ISet> _out58; + (this).GenExpr(_106_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out56, out _out57, out _out58); + _107_expr = _out56; + _108___v53 = _out57; + _109_recIdents = _out58; + readIdents = _109_recIdents; if (isLast) { - generated = _104_expr; + generated = _107_expr; } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_104_expr)); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_107_expr)); } newEnv = env; } @@ -2969,27 +2995,27 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } } { - Dafny.ISequence> _107_rustIdents = _source2.dtor_value; - Dafny.ISequence _108_tupleArgs; - _108_tupleArgs = Dafny.Sequence.FromElements(); - BigInteger _hi3 = new BigInteger((_107_rustIdents).Count); - for (BigInteger _109_i = BigInteger.Zero; _109_i < _hi3; _109_i++) { - RAST._IExpr _110_rIdent; - Defs._IOwnership _111___v55; - Dafny.ISet> _112___v56; - RAST._IExpr _out57; - Defs._IOwnership _out58; - Dafny.ISet> _out59; - (this).GenIdent((_107_rustIdents).Select(_109_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out57, out _out58, out _out59); - _110_rIdent = _out57; - _111___v55 = _out58; - _112___v56 = _out59; - _108_tupleArgs = Dafny.Sequence.Concat(_108_tupleArgs, Dafny.Sequence.FromElements(_110_rIdent)); + Dafny.ISequence> _110_rustIdents = _source2.dtor_value; + Dafny.ISequence _111_tupleArgs; + _111_tupleArgs = Dafny.Sequence.FromElements(); + BigInteger _hi3 = new BigInteger((_110_rustIdents).Count); + for (BigInteger _112_i = BigInteger.Zero; _112_i < _hi3; _112_i++) { + RAST._IExpr _113_rIdent; + Defs._IOwnership _114___v54; + Dafny.ISet> _115___v55; + RAST._IExpr _out59; + Defs._IOwnership _out60; + Dafny.ISet> _out61; + (this).GenIdent((_110_rustIdents).Select(_112_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out59, out _out60, out _out61); + _113_rIdent = _out59; + _114___v54 = _out60; + _115___v55 = _out61; + _111_tupleArgs = Dafny.Sequence.Concat(_111_tupleArgs, Dafny.Sequence.FromElements(_113_rIdent)); } - if ((new BigInteger((_108_tupleArgs).Count)) == (BigInteger.One)) { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_108_tupleArgs).Select(BigInteger.Zero))); + if ((new BigInteger((_111_tupleArgs).Count)) == (BigInteger.One)) { + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_111_tupleArgs).Select(BigInteger.Zero))); } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_108_tupleArgs))); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_111_tupleArgs))); } } after_match2: ; @@ -3010,20 +3036,20 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } } { - DAST._IExpression _113_e = _source0.dtor_Print_a0; + DAST._IExpression _116_e = _source0.dtor_Print_a0; { - RAST._IExpr _114_printedExpr; - Defs._IOwnership _115_recOwnership; - Dafny.ISet> _116_recIdents; - RAST._IExpr _out60; - Defs._IOwnership _out61; - Dafny.ISet> _out62; - (this).GenExpr(_113_e, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out60, out _out61, out _out62); - _114_printedExpr = _out60; - _115_recOwnership = _out61; - _116_recIdents = _out62; - generated = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("print!"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("{}"), false, false), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrintWrapper"))).AsExpr()).Apply1(_114_printedExpr))); - readIdents = _116_recIdents; + RAST._IExpr _117_printedExpr; + Defs._IOwnership _118_recOwnership; + Dafny.ISet> _119_recIdents; + RAST._IExpr _out62; + Defs._IOwnership _out63; + Dafny.ISet> _out64; + (this).GenExpr(_116_e, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out62, out _out63, out _out64); + _117_printedExpr = _out62; + _118_recOwnership = _out63; + _119_recIdents = _out64; + generated = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("print!"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("{}"), false, false), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrintWrapper"))).AsExpr()).Apply1(_117_printedExpr))); + readIdents = _119_recIdents; newEnv = env; } } @@ -3379,24 +3405,24 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ _10_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); } RAST._IExpr _11_left; - Defs._IOwnership _12___v57; + Defs._IOwnership _12___v56; Dafny.ISet> _13_recIdentsL; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(_4_lExpr, selfIdent, env, _9_expectedLeftOwnership, out _out0, out _out1, out _out2); _11_left = _out0; - _12___v57 = _out1; + _12___v56 = _out1; _13_recIdentsL = _out2; RAST._IExpr _14_right; - Defs._IOwnership _15___v58; + Defs._IOwnership _15___v57; Dafny.ISet> _16_recIdentsR; RAST._IExpr _out3; Defs._IOwnership _out4; Dafny.ISet> _out5; (this).GenExpr(_5_rExpr, selfIdent, env, _10_expectedRightOwnership, out _out3, out _out4, out _out5); _14_right = _out3; - _15___v58 = _out4; + _15___v57 = _out4; _16_recIdentsR = _out5; DAST._IBinOp _source0 = _0_op; { @@ -4506,14 +4532,14 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v76; + Defs._IOwnership _5___v75; Dafny.ISet> _6_argIdents; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); _4_argExpr = _out1; - _5___v76 = _out2; + _5___v75 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -4711,14 +4737,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi1 = new BigInteger((_9_values).Count); for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13___v86; + Defs._IOwnership _13___v85; Dafny.ISet> _14_recIdents; RAST._IExpr _out16; Defs._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); _12_recursiveGen = _out16; - _13___v86 = _out17; + _13___v85 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -4767,14 +4793,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi3 = new BigInteger((_17_args).Count); for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { RAST._IExpr _23_recursiveGen; - Defs._IOwnership _24___v87; + Defs._IOwnership _24___v86; Dafny.ISet> _25_recIdents; RAST._IExpr _out23; Defs._IOwnership _out24; Dafny.ISet> _out25; (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); _23_recursiveGen = _out23; - _24___v87 = _out24; + _24___v86 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -4812,14 +4838,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi4 = new BigInteger((_26_dims).Count); for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { RAST._IExpr _31_recursiveGen; - Defs._IOwnership _32___v88; + Defs._IOwnership _32___v87; Dafny.ISet> _33_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr((_26_dims).Select(_30_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _31_recursiveGen = _out30; - _32___v88 = _out31; + _32___v87 = _out31; _33_recIdents = _out32; _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); @@ -4846,14 +4872,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _35_underlying = _source0.dtor_value; { RAST._IExpr _36_recursiveGen; - Defs._IOwnership _37___v89; + Defs._IOwnership _37___v88; Dafny.ISet> _38_recIdents; RAST._IExpr _out35; Defs._IOwnership _out36; Dafny.ISet> _out37; (this).GenExpr(_35_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out35, out _out36, out _out37); _36_recursiveGen = _out35; - _37___v89 = _out36; + _37___v88 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -4876,14 +4902,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out40 = (this).GenType(_40_typ, Defs.GenTypeContext.@default()); _41_tpe = _out40; RAST._IExpr _42_recursiveGen; - Defs._IOwnership _43___v90; + Defs._IOwnership _43___v89; Dafny.ISet> _44_recIdents; RAST._IExpr _out41; Defs._IOwnership _out42; Dafny.ISet> _out43; (this).GenExpr(_39_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); _42_recursiveGen = _out41; - _43___v90 = _out42; + _43___v89 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -4949,14 +4975,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; if (_50_isCo) { RAST._IExpr _59_recursiveGen; - Defs._IOwnership _60___v91; + Defs._IOwnership _60___v90; Dafny.ISet> _61_recIdents; RAST._IExpr _out50; Defs._IOwnership _out51; Dafny.ISet> _out52; (this).GenExpr(_58_value, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); _59_recursiveGen = _out50; - _60___v91 = _out51; + _60___v90 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -4979,14 +5005,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _64_wasAssigned))); } else { RAST._IExpr _65_recursiveGen; - Defs._IOwnership _66___v92; + Defs._IOwnership _66___v91; Dafny.ISet> _67_recIdents; RAST._IExpr _out53; Defs._IOwnership _out54; Dafny.ISet> _out55; (this).GenExpr(_58_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out53, out _out54, out _out55); _65_recursiveGen = _out53; - _66___v92 = _out54; + _66___v91 = _out54; _67_recIdents = _out55; _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _65_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); @@ -5026,24 +5052,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _69_expr = _source0.dtor_elem; { RAST._IExpr _70_recursiveGen; - Defs._IOwnership _71___v96; + Defs._IOwnership _71___v95; Dafny.ISet> _72_recIdents; RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; (this).GenExpr(_69_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); _70_recursiveGen = _out61; - _71___v96 = _out62; + _71___v95 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v97; + Defs._IOwnership _74___v96; Dafny.ISet> _75_lengthIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_68_length, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); _73_lengthGen = _out64; - _74___v97 = _out65; + _74___v96 = _out65; _75_lengthIdents = _out66; r = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("_initializer"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_70_recursiveGen)); RAST._IExpr _76_range; @@ -5082,14 +5108,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _82_args = Dafny.Sequence.FromElements(); while ((_81_i) < (new BigInteger((_78_exprs).Count))) { RAST._IExpr _83_recursiveGen; - Defs._IOwnership _84___v98; + Defs._IOwnership _84___v97; Dafny.ISet> _85_recIdents; RAST._IExpr _out70; Defs._IOwnership _out71; Dafny.ISet> _out72; (this).GenExpr((_78_exprs).Select(_81_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out70, out _out71, out _out72); _83_recursiveGen = _out70; - _84___v98 = _out71; + _84___v97 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -5120,14 +5146,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _88_i = BigInteger.Zero; while ((_88_i) < (new BigInteger((_86_exprs).Count))) { RAST._IExpr _89_recursiveGen; - Defs._IOwnership _90___v99; + Defs._IOwnership _90___v98; Dafny.ISet> _91_recIdents; RAST._IExpr _out75; Defs._IOwnership _out76; Dafny.ISet> _out77; (this).GenExpr((_86_exprs).Select(_88_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out75, out _out76, out _out77); _89_recursiveGen = _out75; - _90___v99 = _out76; + _90___v98 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -5155,14 +5181,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _94_i = BigInteger.Zero; while ((_94_i) < (new BigInteger((_92_exprs).Count))) { RAST._IExpr _95_recursiveGen; - Defs._IOwnership _96___v100; + Defs._IOwnership _96___v99; Dafny.ISet> _97_recIdents; RAST._IExpr _out80; Defs._IOwnership _out81; Dafny.ISet> _out82; (this).GenExpr((_92_exprs).Select(_94_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out80, out _out81, out _out82); _95_recursiveGen = _out80; - _96___v100 = _out81; + _96___v99 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -5184,14 +5210,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _98_expr = _source0.dtor_ToMultiset_a0; { RAST._IExpr _99_recursiveGen; - Defs._IOwnership _100___v101; + Defs._IOwnership _100___v100; Dafny.ISet> _101_recIdents; RAST._IExpr _out85; Defs._IOwnership _out86; Dafny.ISet> _out87; (this).GenExpr(_98_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out85, out _out86, out _out87); _99_recursiveGen = _out85; - _100___v101 = _out86; + _100___v100 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -5216,24 +5242,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _104_i = BigInteger.Zero; while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v102; + Defs._IOwnership _106___v101; Dafny.ISet> _107_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); _105_recursiveGenKey = _out90; - _106___v102 = _out91; + _106___v101 = _out91; _107_recIdentsKey = _out92; RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v103; + Defs._IOwnership _109___v102; Dafny.ISet> _110_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); _108_recursiveGenValue = _out93; - _109___v103 = _out94; + _109___v102 = _out94; _110_recIdentsValue = _out95; _103_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_103_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_105_recursiveGenKey, _108_recursiveGenValue))); readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _107_recIdentsKey), _110_recIdentsValue); @@ -5268,14 +5294,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _116_value = _source0.dtor_value; { RAST._IExpr _117_exprR; - Defs._IOwnership _118___v104; + Defs._IOwnership _118___v103; Dafny.ISet> _119_exprIdents; RAST._IExpr _out98; Defs._IOwnership _out99; Dafny.ISet> _out100; (this).GenExpr(_114_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out98, out _out99, out _out100); _117_exprR = _out98; - _118___v104 = _out99; + _118___v103 = _out99; _119_exprIdents = _out100; RAST._IExpr _120_indexR; Defs._IOwnership _121_indexOwnership; @@ -5316,14 +5342,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _128_value = _source0.dtor_value; { RAST._IExpr _129_exprR; - Defs._IOwnership _130___v105; + Defs._IOwnership _130___v104; Dafny.ISet> _131_exprIdents; RAST._IExpr _out109; Defs._IOwnership _out110; Dafny.ISet> _out111; (this).GenExpr(_126_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out109, out _out110, out _out111); _129_exprR = _out109; - _130___v105 = _out110; + _130___v104 = _out110; _131_exprIdents = _out111; RAST._IExpr _132_indexR; Defs._IOwnership _133_indexOwnership; @@ -5404,14 +5430,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _143_f = _source0.dtor_els; { RAST._IExpr _144_cond; - Defs._IOwnership _145___v106; + Defs._IOwnership _145___v105; Dafny.ISet> _146_recIdentsCond; RAST._IExpr _out126; Defs._IOwnership _out127; Dafny.ISet> _out128; (this).GenExpr(_141_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out126, out _out127, out _out128); _144_cond = _out126; - _145___v106 = _out127; + _145___v105 = _out127; _146_recIdentsCond = _out128; RAST._IExpr _147_fExpr; Defs._IOwnership _148_fOwned; @@ -5424,14 +5450,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _148_fOwned = _out130; _149_recIdentsF = _out131; RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v107; + Defs._IOwnership _151___v106; Dafny.ISet> _152_recIdentsT; RAST._IExpr _out132; Defs._IOwnership _out133; Dafny.ISet> _out134; (this).GenExpr(_142_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); _150_tExpr = _out132; - _151___v107 = _out133; + _151___v106 = _out133; _152_recIdentsT = _out134; r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); RAST._IExpr _out135; @@ -5453,14 +5479,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; { RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v108; + Defs._IOwnership _156___v107; Dafny.ISet> _157_recIdents; RAST._IExpr _out137; Defs._IOwnership _out138; Dafny.ISet> _out139; (this).GenExpr(_153_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out137, out _out138, out _out139); _155_recursiveGen = _out137; - _156___v108 = _out138; + _156___v107 = _out138; _157_recIdents = _out139; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); RAST._IExpr _out140; @@ -5483,14 +5509,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; { RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v109; + Defs._IOwnership _161___v108; Dafny.ISet> _162_recIdents; RAST._IExpr _out142; Defs._IOwnership _out143; Dafny.ISet> _out144; (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out142, out _out143, out _out144); _160_recursiveGen = _out142; - _161___v109 = _out143; + _161___v108 = _out143; _162_recIdents = _out144; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); RAST._IExpr _out145; @@ -5555,14 +5581,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _171_native = _source0.dtor_native; { RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v114; + Defs._IOwnership _173___v113; Dafny.ISet> _174_recIdents; RAST._IExpr _out155; Defs._IOwnership _out156; Dafny.ISet> _out157; (this).GenExpr(_168_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out155, out _out156, out _out157); _172_recursiveGen = _out155; - _173___v114 = _out156; + _173___v113 = _out156; _174_recIdents = _out157; RAST._IType _175_arrayType; RAST._IType _out158; @@ -5604,14 +5630,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _177_expr = _source0.dtor_expr; { RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v115; + Defs._IOwnership _179___v114; Dafny.ISet> _180_recIdents; RAST._IExpr _out162; Defs._IOwnership _out163; Dafny.ISet> _out164; (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); _178_recursiveGen = _out162; - _179___v115 = _out163; + _179___v114 = _out163; _180_recIdents = _out164; readIdents = _180_recIdents; r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); @@ -5630,14 +5656,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _181_expr = _source0.dtor_expr; { RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v116; + Defs._IOwnership _183___v115; Dafny.ISet> _184_recIdents; RAST._IExpr _out167; Defs._IOwnership _out168; Dafny.ISet> _out169; (this).GenExpr(_181_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); _182_recursiveGen = _out167; - _183___v116 = _out168; + _183___v115 = _out168; _184_recIdents = _out169; readIdents = _184_recIdents; r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); @@ -5656,14 +5682,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _185_expr = _source0.dtor_expr; { RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v117; + Defs._IOwnership _187___v116; Dafny.ISet> _188_recIdents; RAST._IExpr _out172; Defs._IOwnership _out173; Dafny.ISet> _out174; (this).GenExpr(_185_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out172, out _out173, out _out174); _186_recursiveGen = _out172; - _187___v117 = _out173; + _187___v116 = _out173; _188_recIdents = _out174; readIdents = _188_recIdents; r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); @@ -5735,15 +5761,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _209_name = _let_tmp_rhs1.dtor__0; RAST._IType _210_ty = _let_tmp_rhs1.dtor__1; RAST._IExpr _211_rIdent; - Defs._IOwnership _212___v118; - Dafny.ISet> _213___v119; + Defs._IOwnership _212___v117; + Dafny.ISet> _213___v118; RAST._IExpr _out181; Defs._IOwnership _out182; Dafny.ISet> _out183; (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((!(_193_isConstant)) && ((_210_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); _211_rIdent = _out181; - _212___v118 = _out182; - _213___v119 = _out183; + _212___v117 = _out182; + _213___v118 = _out183; _207_onExprArgs = Dafny.Sequence.Concat(_207_onExprArgs, Dafny.Sequence.FromElements(_211_rIdent)); } _206_body = (_206_body).Apply(_207_onExprArgs); @@ -6034,14 +6060,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _258_l = _source5.dtor_value; { RAST._IExpr _259_lExpr; - Defs._IOwnership _260___v122; + Defs._IOwnership _260___v121; Dafny.ISet> _261_recIdentsL; RAST._IExpr _out217; Defs._IOwnership _out218; Dafny.ISet> _out219; (this).GenExpr(_258_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out217, out _out218, out _out219); _259_lExpr = _out217; - _260___v122 = _out218; + _260___v121 = _out218; _261_recIdentsL = _out219; _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_259_lExpr)); readIdents = Dafny.Set>.Union(readIdents, _261_recIdentsL); @@ -6058,14 +6084,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _262_h = _source6.dtor_value; { RAST._IExpr _263_hExpr; - Defs._IOwnership _264___v123; + Defs._IOwnership _264___v122; Dafny.ISet> _265_recIdentsH; RAST._IExpr _out220; Defs._IOwnership _out221; Dafny.ISet> _out222; (this).GenExpr(_262_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out220, out _out221, out _out222); _263_hExpr = _out220; - _264___v123 = _out221; + _264___v122 = _out221; _265_recIdentsH = _out222; _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_263_hExpr)); readIdents = Dafny.Set>.Union(readIdents, _265_recIdentsH); @@ -6192,17 +6218,17 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _284_paramTypesMap = Dafny.Map, RAST._IType>.Update(_284_paramTypesMap, _286_name, ((_282_params).Select(_285_i)).dtor_tpe); } Defs._IEnvironment _287_subEnv; - _287_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_283_paramNames, _284_paramTypesMap)); + _287_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_283_paramNames, _284_paramTypesMap, Dafny.Set>.FromElements())); RAST._IExpr _288_recursiveGen; Dafny.ISet> _289_recIdents; - Defs._IEnvironment _290___v125; + Defs._IEnvironment _290___v124; RAST._IExpr _out235; Dafny.ISet> _out236; Defs._IEnvironment _out237; (this).GenStmts(_281_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _287_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out235, out _out236, out _out237); _288_recursiveGen = _out235; _289_recIdents = _out236; - _290___v125 = _out237; + _290___v124 = _out237; readIdents = Dafny.Set>.FromElements(); _289_recIdents = Dafny.Set>.Difference(_289_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_291_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); @@ -6228,15 +6254,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir after__ASSIGN_SUCH_THAT_1: ; if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_294_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { RAST._IExpr _295_selfCloned; - Defs._IOwnership _296___v126; - Dafny.ISet> _297___v127; + Defs._IOwnership _296___v125; + Dafny.ISet> _297___v126; RAST._IExpr _out238; Defs._IOwnership _out239; Dafny.ISet> _out240; (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out238, out _out239, out _out240); _295_selfCloned = _out238; - _296___v126 = _out239; - _297___v127 = _out240; + _296___v125 = _out239; + _297___v126 = _out240; _293_allReadCloned = (_293_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_295_selfCloned))); } else if (!((_283_paramNames).Contains(_294_next))) { RAST._IExpr _298_copy; @@ -6298,20 +6324,20 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out245 = (this).GenType((((_300_values).Select(_311_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); _312_typeGen = _out245; RAST._IExpr _313_valueGen; - Defs._IOwnership _314___v128; + Defs._IOwnership _314___v127; Dafny.ISet> _315_recIdents; RAST._IExpr _out246; Defs._IOwnership _out247; Dafny.ISet> _out248; (this).GenExpr(((_300_values).Select(_311_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out246, out _out247, out _out248); _313_valueGen = _out246; - _314___v128 = _out247; + _314___v127 = _out247; _315_recIdents = _out248; r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_300_values).Select(_311_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_312_typeGen), Std.Wrappers.Option.create_Some(_313_valueGen))); readIdents = Dafny.Set>.Union(readIdents, _315_recIdents); } Defs._IEnvironment _316_newEnv; - _316_newEnv = Defs.Environment.create(_303_paramNames, _306_paramTypes); + _316_newEnv = Defs.Environment.create(_303_paramNames, _306_paramTypes, Dafny.Set>.FromElements()); RAST._IExpr _317_recGen; Defs._IOwnership _318_recOwned; Dafny.ISet> _319_recIdents; @@ -6342,14 +6368,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _323_iifeBody = _source0.dtor_iifeBody; { RAST._IExpr _324_valueGen; - Defs._IOwnership _325___v129; + Defs._IOwnership _325___v128; Dafny.ISet> _326_recIdents; RAST._IExpr _out254; Defs._IOwnership _out255; Dafny.ISet> _out256; (this).GenExpr(_322_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out254, out _out255, out _out256); _324_valueGen = _out254; - _325___v129 = _out255; + _325___v128 = _out255; _326_recIdents = _out256; readIdents = _326_recIdents; RAST._IType _327_valueTypeGen; @@ -6359,14 +6385,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _328_iifeVar; _328_iifeVar = Defs.__default.escapeVar(_320_name); RAST._IExpr _329_bodyGen; - Defs._IOwnership _330___v130; + Defs._IOwnership _330___v129; Dafny.ISet> _331_bodyIdents; RAST._IExpr _out258; Defs._IOwnership _out259; Dafny.ISet> _out260; (this).GenExpr(_323_iifeBody, selfIdent, (env).AddAssigned(_328_iifeVar, _327_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out258, out _out259, out _out260); _329_bodyGen = _out258; - _330___v130 = _out259; + _330___v129 = _out259; _331_bodyIdents = _out260; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_331_bodyIdents, Dafny.Set>.FromElements(_328_iifeVar))); r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _328_iifeVar, Std.Wrappers.Option.create_Some(_327_valueTypeGen), Std.Wrappers.Option.create_Some(_324_valueGen))).Then(_329_bodyGen)); @@ -6386,14 +6412,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _333_args = _source0.dtor_args; { RAST._IExpr _334_funcExpr; - Defs._IOwnership _335___v131; + Defs._IOwnership _335___v130; Dafny.ISet> _336_recIdents; RAST._IExpr _out263; Defs._IOwnership _out264; Dafny.ISet> _out265; (this).GenExpr(_332_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out263, out _out264, out _out265); _334_funcExpr = _out263; - _335___v131 = _out264; + _335___v130 = _out264; _336_recIdents = _out265; readIdents = _336_recIdents; Dafny.ISequence _337_rArgs; @@ -6431,14 +6457,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _344_variant = _source0.dtor_variant; { RAST._IExpr _345_exprGen; - Defs._IOwnership _346___v132; + Defs._IOwnership _346___v131; Dafny.ISet> _347_recIdents; RAST._IExpr _out271; Defs._IOwnership _out272; Dafny.ISet> _out273; (this).GenExpr(_342_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out271, out _out272, out _out273); _345_exprGen = _out271; - _346___v132 = _out272; + _346___v131 = _out272; _347_recIdents = _out273; RAST._IExpr _348_variantExprPath; RAST._IExpr _out274; @@ -6553,14 +6579,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _363_of = _source0.dtor_of; { RAST._IExpr _364_exprGen; - Defs._IOwnership _365___v133; + Defs._IOwnership _365___v132; Dafny.ISet> _366_recIdents; RAST._IExpr _out290; Defs._IOwnership _out291; Dafny.ISet> _out292; (this).GenExpr(_363_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out290, out _out291, out _out292); _364_exprGen = _out290; - _365___v133 = _out291; + _365___v132 = _out291; _366_recIdents = _out292; r = ((_364_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out293; @@ -6580,14 +6606,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _368_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _369_exprGen; - Defs._IOwnership _370___v134; + Defs._IOwnership _370___v133; Dafny.ISet> _371_recIdents; RAST._IExpr _out295; Defs._IOwnership _out296; Dafny.ISet> _out297; (this).GenExpr(_367_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out295, out _out296, out _out297); _369_exprGen = _out295; - _370___v134 = _out296; + _370___v133 = _out296; _371_recIdents = _out297; r = ((_369_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_368_includeDuplicates)) { @@ -6610,14 +6636,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _373_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _374_exprGen; - Defs._IOwnership _375___v135; + Defs._IOwnership _375___v134; Dafny.ISet> _376_recIdents; RAST._IExpr _out300; Defs._IOwnership _out301; Dafny.ISet> _out302; (this).GenExpr(_372_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out300, out _out301, out _out302); _374_exprGen = _out300; - _375___v135 = _out301; + _375___v134 = _out301; _376_recIdents = _out302; r = ((_374_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_373_includeDuplicates)) { @@ -6639,14 +6665,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _377_of = _source0.dtor_of; { RAST._IExpr _378_exprGen; - Defs._IOwnership _379___v136; + Defs._IOwnership _379___v135; Dafny.ISet> _380_recIdents; RAST._IExpr _out305; Defs._IOwnership _out306; Dafny.ISet> _out307; (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out305, out _out306, out _out307); _378_exprGen = _out305; - _379___v136 = _out306; + _379___v135 = _out306; _380_recIdents = _out307; r = ((((_378_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); readIdents = _380_recIdents; @@ -6664,14 +6690,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _381_of = _source0.dtor_of; { RAST._IExpr _382_exprGen; - Defs._IOwnership _383___v137; + Defs._IOwnership _383___v136; Dafny.ISet> _384_recIdents; RAST._IExpr _out310; Defs._IOwnership _out311; Dafny.ISet> _out312; (this).GenExpr(_381_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out310, out _out311, out _out312); _382_exprGen = _out310; - _383___v137 = _out311; + _383___v136 = _out311; _384_recIdents = _out312; r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_382_exprGen); readIdents = _384_recIdents; @@ -6692,24 +6718,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _388_up = _source0.dtor_up; { RAST._IExpr _389_lo; - Defs._IOwnership _390___v138; + Defs._IOwnership _390___v137; Dafny.ISet> _391_recIdentsLo; RAST._IExpr _out315; Defs._IOwnership _out316; Dafny.ISet> _out317; (this).GenExpr(_386_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out315, out _out316, out _out317); _389_lo = _out315; - _390___v138 = _out316; + _390___v137 = _out316; _391_recIdentsLo = _out317; RAST._IExpr _392_hi; - Defs._IOwnership _393___v139; + Defs._IOwnership _393___v138; Dafny.ISet> _394_recIdentsHi; RAST._IExpr _out318; Defs._IOwnership _out319; Dafny.ISet> _out320; (this).GenExpr(_387_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out318, out _out319, out _out320); _392_hi = _out318; - _393___v139 = _out319; + _393___v138 = _out319; _394_recIdentsHi = _out320; if (_388_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_389_lo, _392_hi)); @@ -6740,14 +6766,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _397_up = _source0.dtor_up; { RAST._IExpr _398_start; - Defs._IOwnership _399___v140; + Defs._IOwnership _399___v139; Dafny.ISet> _400_recIdentStart; RAST._IExpr _out324; Defs._IOwnership _out325; Dafny.ISet> _out326; (this).GenExpr(_396_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out324, out _out325, out _out326); _398_start = _out324; - _399___v140 = _out325; + _399___v139 = _out325; _400_recIdentStart = _out326; if (_397_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_398_start); @@ -6821,14 +6847,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out336 = (this).GenType(_407_elemType, Defs.GenTypeContext.@default()); _411_tpe = _out336; RAST._IExpr _412_collectionGen; - Defs._IOwnership _413___v141; + Defs._IOwnership _413___v140; Dafny.ISet> _414_recIdents; RAST._IExpr _out337; Defs._IOwnership _out338; Dafny.ISet> _out339; (this).GenExpr(_408_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); _412_collectionGen = _out337; - _413___v141 = _out338; + _413___v140 = _out338; _414_recIdents = _out339; Dafny.ISequence _415_extraAttributes; _415_extraAttributes = Dafny.Sequence.FromElements(); @@ -6851,14 +6877,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _423_dt__update_hparams_h0 = _417_newFormals; _421_newLambda = DAST.Expression.create_Lambda(_423_dt__update_hparams_h0, (_422_dt__update__tmp_h1).dtor_retType, (_422_dt__update__tmp_h1).dtor_body); RAST._IExpr _424_lambdaGen; - Defs._IOwnership _425___v142; + Defs._IOwnership _425___v141; Dafny.ISet> _426_recLambdaIdents; RAST._IExpr _out340; Defs._IOwnership _out341; Dafny.ISet> _out342; (this).GenExpr(_421_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out340, out _out341, out _out342); _424_lambdaGen = _out340; - _425___v142 = _out341; + _425___v141 = _out341; _426_recLambdaIdents = _out342; Dafny.ISequence _427_fn; if (_409_is__forall) { @@ -6921,7 +6947,7 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul _0_externUseDecls = Dafny.Sequence.Concat(_0_externUseDecls, Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), ((RAST.__default.crate).MSel(_3_externalMod)).MSel(Dafny.Sequence.UnicodeFromString("*")))))); } if (!(_0_externUseDecls).Equals(Dafny.Sequence.FromElements())) { - s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(s, (RAST.Mod.create_Mod(Defs.__default.DAFNY__EXTERN__MODULE, Dafny.Sequence>.FromElements(), _0_externUseDecls))._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("\n")); + s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(s, (RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("Flattens all imported externs so that they can be accessed from this module"), Dafny.Sequence>.FromElements(), Defs.__default.DAFNY__EXTERN__MODULE, _0_externUseDecls))._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("\n")); } DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _5_allModules; _5_allModules = DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Empty(); @@ -6965,15 +6991,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v143; - Dafny.ISet> _2___v144; + Defs._IOwnership _1___v142; + Dafny.ISet> _2___v143; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v143 = _out1; - _2___v144 = _out2; + _1___v142 = _out1; + _2___v143 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index 0be243083a8..79963d8ec20 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -468,32 +468,41 @@ public static RAST._IExpr UnreachablePanicIfVerified(Defs._IPointerType pointerT return (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply1(RAST.Expr.create_LiteralString(optText, false, false)); } } + public static RAST._IModDecl DefaultDatatypeImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, RAST._IExpr datatypeName, Dafny.ISequence structAssignments) + { + Dafny.ISequence _0_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_0_defaultConstrainedTypeParams, RAST.__default.DefaultTrait, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("default"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(datatypeType), Std.Wrappers.Option.create_Some(RAST.Expr.create_StructBuild(datatypeName, structAssignments))))))); + } + public static RAST._IModDecl AsRefDatatypeImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType) + { + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsType()).Apply1(datatypeType), datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("as_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.self)))))); + } public static RAST._IModDecl DebugImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, Dafny.ISequence rTypeParams) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Debug"))).AsType(), datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("f"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType()))), Std.Wrappers.Option.create_Some((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(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))))))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Debug"))).AsType(), datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("f"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType()))), Std.Wrappers.Option.create_Some((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType()), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("f")), RAST.Expr.create_LiteralBool(true))))))))); } public static RAST._IModDecl PrintImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, Dafny.ISequence rTypeParams, RAST._IExpr printImplBody) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, RAST.__default.DafnyPrint, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("std::fmt::Result"))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(printImplBody)))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, RAST.__default.DafnyPrint, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("std::fmt::Result"))), Std.Wrappers.Option.create_Some(printImplBody)))))); } public static RAST._IModDecl CoerceImpl(Dafny.ISequence rTypeParamsDecls, Dafny.ISequence datatypeName, RAST._IType datatypeType, Dafny.ISequence rCoerceTypeParams, Dafny.ISequence coerceArguments, Dafny.ISequence coerceTypes, RAST._IExpr coerceImplBody) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("coerce"), rCoerceTypeParams, coerceArguments, Std.Wrappers.Option.create_Some(RAST.__default.Rc(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(datatypeType), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes))))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.RcNew(RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("this"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes)), coerceImplBody)))))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Given type parameter conversions, returns a lambda to convert this structure"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("coerce"), rCoerceTypeParams, coerceArguments, Std.Wrappers.Option.create_Some(RAST.__default.Rc(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(datatypeType), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes))))), Std.Wrappers.Option.create_Some(RAST.__default.RcNew(RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("this"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes)), coerceImplBody)))))))); } public static RAST._IModDecl SingletonsImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, RAST._IType instantiationType, Dafny.ISequence singletonConstructors) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_AllSingletonConstructors"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SequenceIter"))).AsType()).Apply(Dafny.Sequence.FromElements(instantiationType))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).AsExpr()).Apply(singletonConstructors)).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0())))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Enumerates all possible values of "), (datatypeType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_AllSingletonConstructors"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SequenceIter"))).AsType()).Apply(Dafny.Sequence.FromElements(instantiationType))), Std.Wrappers.Option.create_Some((((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).AsExpr()).Apply(singletonConstructors)).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0())))))); } public static RAST._IModDecl HashImpl(Dafny.ISequence rTypeParamsDeclsWithHash, RAST._IType datatypeOrNewtypeType, RAST._IExpr hashImplBody) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithHash, RAST.__default.Hash, datatypeOrNewtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(hashImplBody)))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithHash, RAST.__default.Hash, datatypeOrNewtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(hashImplBody)))))); } public static RAST._IImplMember eq__trait(RAST._IType fullTraitPath, RAST._IExpr fullTraitExpr) { - return 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.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(fullTraitPath))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((((((fullTraitExpr).FSel(Dafny.Sequence.UnicodeFromString("_as_any"))).Apply1(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())).Sel(Dafny.Sequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(RAST.__default.SelfOwned))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("map_or"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralBool(false), RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("x"), RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("_")))), Std.Wrappers.Option.create_None(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), DAST.Format.BinaryOpFormat.create_NoFormat()))))))); + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(fullTraitPath))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some((((((((fullTraitExpr).FSel(Dafny.Sequence.UnicodeFromString("_as_any"))).Apply1(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())).Sel(Dafny.Sequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(RAST.__default.SelfOwned))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("map_or"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralBool(false), RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("x"), RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("_")))), Std.Wrappers.Option.create_None(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), DAST.Format.BinaryOpFormat.create_NoFormat()))))))); } public static RAST._IImplMember clone__trait(RAST._IType fullTraitPath) { - return RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(fullTraitPath))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))); + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(fullTraitPath))), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))); } public static RAST._IModDecl UnaryOpsImpl(Dafny.Rune op, Dafny.ISequence rTypeParamsDecls, RAST._IType newtypeType, Dafny.ISequence newtypeConstructor) { @@ -505,7 +514,7 @@ public static RAST._IModDecl UnaryOpsImpl(Dafny.Rune op, Dafny.ISequence _0_traitName = _let_tmp_rhs0.dtor__0; Dafny.ISequence _1_methodName = _let_tmp_rhs0.dtor__1; - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(_0_traitName)).AsType(), newtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Output"), newtypeType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(_1_methodName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfOwned), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((RAST.Expr.create_Identifier(newtypeConstructor)).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.FromElements(op), (RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.UnaryOpFormat.create_NoFormat())))))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(_0_traitName)).AsType(), newtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Output"), newtypeType), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(_1_methodName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfOwned), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some((RAST.Expr.create_Identifier(newtypeConstructor)).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.FromElements(op), (RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.UnaryOpFormat.create_NoFormat())))))))); } public static RAST._IModDecl OpsImpl(Dafny.Rune op, Dafny.ISequence rTypeParamsDecls, RAST._IType newtypeType, Dafny.ISequence newtypeConstructor) { @@ -532,11 +541,11 @@ public static RAST._IModDecl OpsImpl(Dafny.Rune op, Dafny.ISequence _0_traitName = _let_tmp_rhs0.dtor__0; Dafny.ISequence _1_methodName = _let_tmp_rhs0.dtor__1; - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(_0_traitName)).AsType(), newtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Output"), newtypeType), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(_1_methodName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfOwned, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((RAST.Expr.create_Identifier(newtypeConstructor)).Apply1(RAST.Expr.create_BinaryOp(Dafny.Sequence.FromElements(op), (RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.BinaryOpFormat.create_NoFormat())))))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(_0_traitName)).AsType(), newtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Output"), newtypeType), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(_1_methodName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfOwned, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some((RAST.Expr.create_Identifier(newtypeConstructor)).Apply1(RAST.Expr.create_BinaryOp(Dafny.Sequence.FromElements(op), (RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0")), DAST.Format.BinaryOpFormat.create_NoFormat())))))))); } public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType newtypeType, Dafny.ISequence newtypeConstructor) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsType(), newtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("partial_cmp"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("option"))).MSel(Dafny.Sequence.UnicodeFromString("Option"))).AsType()).Apply1((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Ordering"))).AsType())), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("partial_cmp"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.__default.Borrow((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsType(), newtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("partial_cmp"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("option"))).MSel(Dafny.Sequence.UnicodeFromString("Option"))).AsType()).Apply1((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Ordering"))).AsType())), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialOrd"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("partial_cmp"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.__default.Borrow((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); } public static Std.Wrappers._IOption DowncastTraitDeclFor(Dafny.ISequence rTypeParamsDecls, RAST._IType fullType) { @@ -545,7 +554,7 @@ public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence(); } else { RAST._IType _1_downcast__type = (_0_valueOrError0).Extract(); - return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(rTypeParamsDecls, _1_downcast__type, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(fullType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_None())))))); + return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(RAST.__default.NoDoc, RAST.__default.NoAttr, rTypeParamsDecls, _1_downcast__type, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(fullType), Std.Wrappers.Option.create_None())))))); } } public static Std.Wrappers._IOption DowncastImplFor(Dafny.ISequence rTypeParamsDecls, RAST._IType typeToDowncastTo, RAST._IType forType) @@ -559,7 +568,90 @@ public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence((RAST.__default.self).Clone(), _pat_let25_0 => Dafny.Helpers.Let(_pat_let25_0, _5_body => (((_pat_let_tv0).IsRc()) ? (RAST.__default.RcNew(_5_body)) : (_5_body))))) : ((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply1(RAST.Expr.create_LiteralString(Dafny.Sequence.Concat(Dafny.Sequence.Concat((_2_forTypeRaw)._ToString(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString(" is not a ")), (typeToDowncastTo)._ToString(Dafny.Sequence.UnicodeFromString(""))), false, true)))); - return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, forType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.Expr.create_LiteralBool(_3_sameType)))), RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(forType), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(_4_asBody))))))); + return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, forType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(RAST.Expr.create_LiteralBool(_3_sameType)))), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(forType), Std.Wrappers.Option.create_Some(_4_asBody))))))); + } + } + public static Defs._IAssignmentStatus DetectAssignmentStatus(Dafny.ISequence stmts__remainder, Dafny.ISequence dafny__name) + { + if ((new BigInteger((stmts__remainder).Count)).Sign == 0) { + return Defs.AssignmentStatus.create_NotAssigned(); + } else { + DAST._IStatement _0_stmt = (stmts__remainder).Select(BigInteger.Zero); + DAST._IStatement _source0 = _0_stmt; + { + if (_source0.is_Assign) { + DAST._IAssignLhs lhs0 = _source0.dtor_lhs; + if (lhs0.is_Ident) { + Dafny.ISequence _1_assign__name = lhs0.dtor_ident; + if (object.Equals(_1_assign__name, dafny__name)) { + return Defs.AssignmentStatus.create_SurelyAssigned(); + } else { + return Defs.__default.DetectAssignmentStatus((stmts__remainder).Drop(BigInteger.One), dafny__name); + } + } + } + } + { + if (_source0.is_If) { + DAST._IExpression _2_cond = _source0.dtor_cond; + Dafny.ISequence _3_thn = _source0.dtor_thn; + Dafny.ISequence _4_els = _source0.dtor_els; + return (Defs.__default.DetectAssignmentStatus(_3_thn, dafny__name)).Join(Defs.__default.DetectAssignmentStatus(_4_els, dafny__name)); + } + } + { + if (_source0.is_Call) { + DAST._IExpression _5_on = _source0.dtor_on; + DAST._ICallName _6_callName = _source0.dtor_callName; + Dafny.ISequence _7_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _8_args = _source0.dtor_args; + Std.Wrappers._IOption>> _9_outs = _source0.dtor_outs; + if (((_9_outs).is_Some) && (((_9_outs).dtor_value).Contains(dafny__name))) { + return Defs.AssignmentStatus.create_SurelyAssigned(); + } else { + return Defs.__default.DetectAssignmentStatus((stmts__remainder).Drop(BigInteger.One), dafny__name); + } + } + } + { + if (_source0.is_Labeled) { + Dafny.ISequence _10_stmts = _source0.dtor_body; + return (Defs.__default.DetectAssignmentStatus(_10_stmts, dafny__name)).Then(Defs.__default.DetectAssignmentStatus((stmts__remainder).Drop(BigInteger.One), dafny__name)); + } + } + { + if (_source0.is_DeclareVar) { + Dafny.ISequence _11_name = _source0.dtor_name; + if (object.Equals(_11_name, dafny__name)) { + return Defs.AssignmentStatus.create_NotAssigned(); + } else { + return Defs.__default.DetectAssignmentStatus((stmts__remainder).Drop(BigInteger.One), dafny__name); + } + } + } + { + bool disjunctiveMatch0 = false; + if (_source0.is_Return) { + disjunctiveMatch0 = true; + } + if (_source0.is_EarlyReturn) { + disjunctiveMatch0 = true; + } + if (_source0.is_JumpTailCallStart) { + disjunctiveMatch0 = true; + } + if (disjunctiveMatch0) { + return Defs.AssignmentStatus.create_NotAssigned(); + } + } + { + if (_source0.is_Print) { + return Defs.__default.DetectAssignmentStatus((stmts__remainder).Drop(BigInteger.One), dafny__name); + } + } + { + return Defs.AssignmentStatus.create_Unknown(); + } } } public static Dafny.ISet> reserved__rust { get { @@ -587,7 +679,7 @@ public static RAST._IType fmt__print__result { get { return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Result"))).AsType(); } } public static RAST._IImplMember print__trait { get { - return RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq"))))))); + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq"))))))); } } public static Dafny.ISequence IND { get { return RAST.__default.IND; @@ -611,10 +703,10 @@ public static RAST._IExpr hash__function { get { return ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hash"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("hash")); } } public static RAST._IImplMember hasher__trait { get { - return RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("hasher"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("DefaultHasher"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0()))).Then((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&mut"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher")), DAST.Format.UnaryOpFormat.create_NoFormat()))).Then(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher"))).Sel(Dafny.Sequence.UnicodeFromString("finish"))).Apply0()))))); + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Std.Wrappers.Option.create_Some((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("hasher"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("DefaultHasher"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0()))).Then((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&mut"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher")), DAST.Format.UnaryOpFormat.create_NoFormat()))).Then(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher"))).Sel(Dafny.Sequence.UnicodeFromString("finish"))).Apply0()))))); } } public static RAST._IImplMember as__any__trait { get { - return RAST.ImplMember.create_FnDecl(RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType()))), Dafny.Sequence.UnicodeFromString(""), Std.Wrappers.Option.create_Some(RAST.__default.self))); + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType()))), Std.Wrappers.Option.create_Some(RAST.__default.self))); } } } @@ -751,6 +843,7 @@ public interface _IEnvironment { bool is_Environment { get; } Dafny.ISequence> dtor_names { get; } Dafny.IMap,RAST._IType> dtor_types { get; } + Dafny.ISet> dtor_assignmentStatusKnown { get; } _IEnvironment DowncastClone(); Defs._IEnvironment ToOwned(); bool CanReadWithoutClone(Dafny.ISequence name); @@ -760,30 +853,36 @@ public interface _IEnvironment { bool IsBorrowedMut(Dafny.ISequence name); bool IsBoxed(Dafny.ISequence name); bool NeedsAsRefForBorrow(Dafny.ISequence name); + bool IsMaybePlacebo(Dafny.ISequence name); Defs._IEnvironment AddAssigned(Dafny.ISequence name, RAST._IType tpe); Defs._IEnvironment merge(Defs._IEnvironment other); Defs._IEnvironment RemoveAssigned(Dafny.ISequence name); + Defs._IEnvironment AddAssignmentStatus(Dafny.ISequence name, Defs._IAssignmentStatus assignmentStatus); + bool IsAssignmentStatusKnown(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) { + public readonly Dafny.ISet> _assignmentStatusKnown; + public Environment(Dafny.ISequence> names, Dafny.IMap,RAST._IType> types, Dafny.ISet> assignmentStatusKnown) { this._names = names; this._types = types; + this._assignmentStatusKnown = assignmentStatusKnown; } public _IEnvironment DowncastClone() { if (this is _IEnvironment dt) { return dt; } - return new Environment(_names, _types); + return new Environment(_names, _types, _assignmentStatusKnown); } public override bool Equals(object other) { var oth = other as Defs.Environment; - return oth != null && object.Equals(this._names, oth._names) && object.Equals(this._types, oth._types); + return oth != null && object.Equals(this._names, oth._names) && object.Equals(this._types, oth._types) && object.Equals(this._assignmentStatusKnown, oth._assignmentStatusKnown); } 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)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._assignmentStatusKnown)); return (int) hash; } public override string ToString() { @@ -792,10 +891,12 @@ public override string ToString() { s += Dafny.Helpers.ToString(this._names); s += ", "; s += Dafny.Helpers.ToString(this._types); + s += ", "; + s += Dafny.Helpers.ToString(this._assignmentStatusKnown); s += ")"; return s; } - private static readonly Defs._IEnvironment theDefault = create(Dafny.Sequence>.Empty, Dafny.Map, RAST._IType>.Empty); + private static readonly Defs._IEnvironment theDefault = create(Dafny.Sequence>.Empty, Dafny.Map, RAST._IType>.Empty, Dafny.Set>.Empty); public static Defs._IEnvironment Default() { return theDefault; } @@ -803,11 +904,11 @@ public static Defs._IEnvironment 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(Dafny.ISequence> names, Dafny.IMap,RAST._IType> types, Dafny.ISet> assignmentStatusKnown) { + return new Environment(names, types, assignmentStatusKnown); } - public static _IEnvironment create_Environment(Dafny.ISequence> names, Dafny.IMap,RAST._IType> types) { - return create(names, types); + public static _IEnvironment create_Environment(Dafny.ISequence> names, Dafny.IMap,RAST._IType> types, Dafny.ISet> assignmentStatusKnown) { + return create(names, types, assignmentStatusKnown); } public bool is_Environment { get { return true; } } public Dafny.ISequence> dtor_names { @@ -820,6 +921,11 @@ public Dafny.ISequence> dtor_names { return this._types; } } + public Dafny.ISet> dtor_assignmentStatusKnown { + get { + return this._assignmentStatusKnown; + } + } public Defs._IEnvironment ToOwned() { Defs._IEnvironment _0_dt__update__tmp_h0 = this; Dafny.IMap,RAST._IType> _1_dt__update_htypes_h0 = ((System.Func,RAST._IType>>)(() => { @@ -832,10 +938,10 @@ public Defs._IEnvironment ToOwned() { } return Dafny.Map,RAST._IType>.FromCollection(_coll0); }))(); - return Defs.Environment.create((_0_dt__update__tmp_h0).dtor_names, _1_dt__update_htypes_h0); + return Defs.Environment.create((_0_dt__update__tmp_h0).dtor_names, _1_dt__update_htypes_h0, (_0_dt__update__tmp_h0).dtor_assignmentStatusKnown); } public static Defs._IEnvironment Empty() { - return Defs.Environment.create(Dafny.Sequence>.FromElements(), Dafny.Map, RAST._IType>.FromElements()); + return Defs.Environment.create(Dafny.Sequence>.FromElements(), Dafny.Map, RAST._IType>.FromElements(), Dafny.Set>.FromElements()); } public bool CanReadWithoutClone(Dafny.ISequence name) { return (((this).dtor_types).Contains(name)) && ((Dafny.Map, RAST._IType>.Select((this).dtor_types,name)).CanReadWithoutClone()); @@ -862,16 +968,26 @@ public bool IsBoxed(Dafny.ISequence name) { public bool NeedsAsRefForBorrow(Dafny.ISequence name) { return (((this).dtor_types).Contains(name)) && ((Dafny.Map, RAST._IType>.Select((this).dtor_types,name)).NeedsAsRefForBorrow()); } + public bool IsMaybePlacebo(Dafny.ISequence name) { + return (((this).dtor_types).Contains(name)) && (((Dafny.Map, RAST._IType>.Select((this).dtor_types,name)).ExtractMaybePlacebo()).is_Some); + } public Defs._IEnvironment AddAssigned(Dafny.ISequence name, RAST._IType tpe) { - return Defs.Environment.create(Dafny.Sequence>.Concat((this).dtor_names, Dafny.Sequence>.FromElements(name)), Dafny.Map, RAST._IType>.Update((this).dtor_types, name, tpe)); + return Defs.Environment.create(Dafny.Sequence>.Concat((this).dtor_names, Dafny.Sequence>.FromElements(name)), Dafny.Map, RAST._IType>.Update((this).dtor_types, name, tpe), Dafny.Set>.Difference((this).dtor_assignmentStatusKnown, Dafny.Set>.FromElements(name))); } public Defs._IEnvironment merge(Defs._IEnvironment other) { - return Defs.Environment.create(Dafny.Sequence>.Concat((this).dtor_names, (other).dtor_names), Dafny.Map, RAST._IType>.Merge((this).dtor_types, (other).dtor_types)); + return Defs.Environment.create(Dafny.Sequence>.Concat((this).dtor_names, (other).dtor_names), Dafny.Map, RAST._IType>.Merge((this).dtor_types, (other).dtor_types), Dafny.Set>.Union((this).dtor_assignmentStatusKnown, (other).dtor_assignmentStatusKnown)); } public Defs._IEnvironment RemoveAssigned(Dafny.ISequence name) { BigInteger _0_indexInEnv = Std.Collections.Seq.__default.IndexOf>((this).dtor_names, name); - return Defs.Environment.create(Dafny.Sequence>.Concat(((this).dtor_names).Subsequence(BigInteger.Zero, _0_indexInEnv), ((this).dtor_names).Drop((_0_indexInEnv) + (BigInteger.One))), Dafny.Map, RAST._IType>.Subtract((this).dtor_types, Dafny.Set>.FromElements(name))); + return Defs.Environment.create(Dafny.Sequence>.Concat(((this).dtor_names).Subsequence(BigInteger.Zero, _0_indexInEnv), ((this).dtor_names).Drop((_0_indexInEnv) + (BigInteger.One))), Dafny.Map, RAST._IType>.Subtract((this).dtor_types, Dafny.Set>.FromElements(name)), Dafny.Set>.Difference((this).dtor_assignmentStatusKnown, Dafny.Set>.FromElements(name))); + } + public Defs._IEnvironment AddAssignmentStatus(Dafny.ISequence name, Defs._IAssignmentStatus assignmentStatus) + { + return Defs.Environment.create((this).dtor_names, (this).dtor_types, (((assignmentStatus).is_Unknown) ? (Dafny.Set>.Difference((this).dtor_assignmentStatusKnown, Dafny.Set>.FromElements(name))) : (Dafny.Set>.Union((this).dtor_assignmentStatusKnown, Dafny.Set>.FromElements(name))))); + } + public bool IsAssignmentStatusKnown(Dafny.ISequence name) { + return ((this).dtor_assignmentStatusKnown).Contains(name); } } @@ -1427,4 +1543,126 @@ public override string ToString() { return s; } } + + public interface _IAssignmentStatus { + bool is_NotAssigned { get; } + bool is_SurelyAssigned { get; } + bool is_Unknown { get; } + _IAssignmentStatus DowncastClone(); + Defs._IAssignmentStatus Join(Defs._IAssignmentStatus other); + Defs._IAssignmentStatus Then(Defs._IAssignmentStatus other); + } + public abstract class AssignmentStatus : _IAssignmentStatus { + public AssignmentStatus() { + } + private static readonly Defs._IAssignmentStatus theDefault = create_NotAssigned(); + public static Defs._IAssignmentStatus Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(Defs.AssignmentStatus.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IAssignmentStatus create_NotAssigned() { + return new AssignmentStatus_NotAssigned(); + } + public static _IAssignmentStatus create_SurelyAssigned() { + return new AssignmentStatus_SurelyAssigned(); + } + public static _IAssignmentStatus create_Unknown() { + return new AssignmentStatus_Unknown(); + } + public bool is_NotAssigned { get { return this is AssignmentStatus_NotAssigned; } } + public bool is_SurelyAssigned { get { return this is AssignmentStatus_SurelyAssigned; } } + public bool is_Unknown { get { return this is AssignmentStatus_Unknown; } } + public static System.Collections.Generic.IEnumerable<_IAssignmentStatus> AllSingletonConstructors { + get { + yield return AssignmentStatus.create_NotAssigned(); + yield return AssignmentStatus.create_SurelyAssigned(); + yield return AssignmentStatus.create_Unknown(); + } + } + public abstract _IAssignmentStatus DowncastClone(); + public Defs._IAssignmentStatus Join(Defs._IAssignmentStatus other) { + if (((this).is_SurelyAssigned) && ((other).is_SurelyAssigned)) { + return Defs.AssignmentStatus.create_SurelyAssigned(); + } else if (((this).is_NotAssigned) && ((other).is_NotAssigned)) { + return Defs.AssignmentStatus.create_NotAssigned(); + } else { + return Defs.AssignmentStatus.create_Unknown(); + } + } + public Defs._IAssignmentStatus Then(Defs._IAssignmentStatus other) { + if ((this).is_SurelyAssigned) { + return Defs.AssignmentStatus.create_SurelyAssigned(); + } else if ((this).is_NotAssigned) { + return other; + } else { + return Defs.AssignmentStatus.create_Unknown(); + } + } + } + public class AssignmentStatus_NotAssigned : AssignmentStatus { + public AssignmentStatus_NotAssigned() : base() { + } + public override _IAssignmentStatus DowncastClone() { + if (this is _IAssignmentStatus dt) { return dt; } + return new AssignmentStatus_NotAssigned(); + } + public override bool Equals(object other) { + var oth = other as Defs.AssignmentStatus_NotAssigned; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + return (int) hash; + } + public override string ToString() { + string s = "DafnyToRustCompilerDefinitions.AssignmentStatus.NotAssigned"; + return s; + } + } + public class AssignmentStatus_SurelyAssigned : AssignmentStatus { + public AssignmentStatus_SurelyAssigned() : base() { + } + public override _IAssignmentStatus DowncastClone() { + if (this is _IAssignmentStatus dt) { return dt; } + return new AssignmentStatus_SurelyAssigned(); + } + public override bool Equals(object other) { + var oth = other as Defs.AssignmentStatus_SurelyAssigned; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + return (int) hash; + } + public override string ToString() { + string s = "DafnyToRustCompilerDefinitions.AssignmentStatus.SurelyAssigned"; + return s; + } + } + public class AssignmentStatus_Unknown : AssignmentStatus { + public AssignmentStatus_Unknown() : base() { + } + public override _IAssignmentStatus DowncastClone() { + if (this is _IAssignmentStatus dt) { return dt; } + return new AssignmentStatus_Unknown(); + } + public override bool Equals(object other) { + var oth = other as Defs.AssignmentStatus_Unknown; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 2; + return (int) hash; + } + public override string ToString() { + string s = "DafnyToRustCompilerDefinitions.AssignmentStatus.Unknown"; + return s; + } + } } // end of namespace Defs \ No newline at end of file diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index 3c4394e3494..26a5134071a 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -30,6 +30,14 @@ public static __A FoldLeft<__A, __T>(Func<__A, __T, __A> f, __A init, Dafny.ISeq goto TAIL_CALL_START; } } + public static Dafny.ISequence ToDocstringPrefix(Dafny.ISequence docString, Dafny.ISequence ind) + { + if ((docString).Equals(Dafny.Sequence.UnicodeFromString(""))) { + return Dafny.Sequence.UnicodeFromString(""); + } else { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("/// "), RAST.__default.AddIndent(docString, Dafny.Sequence.Concat(ind, Dafny.Sequence.UnicodeFromString("/// ")))), Dafny.Sequence.UnicodeFromString("\n")), ind); + } + } public static Dafny.ISequence SeqToString<__T>(Dafny.ISequence<__T> s, Func<__T, Dafny.ISequence> f, Dafny.ISequence separator) { if ((new BigInteger((s).Count)).Sign == 0) { @@ -213,6 +221,9 @@ public static bool IsBorrowUpcastBox(RAST._IExpr r) { return false; } } + public static Dafny.ISequence IND { get { + return Dafny.Sequence.UnicodeFromString(" "); + } } public static RAST._IType SelfOwned { get { return (RAST.Path.create_Self()).AsType(); } } @@ -306,9 +317,6 @@ public static RAST._IExpr MaybeUninitExpr { get { public static RAST._IPath MaybePlaceboPath { get { return (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MaybePlacebo")); } } - public static Dafny.ISequence IND { get { - return Dafny.Sequence.UnicodeFromString(" "); - } } public static RAST._IExpr self { get { return RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self")); } } @@ -348,9 +356,15 @@ public static RAST._IExpr std__rc__Rc__new { get { public static RAST._IExpr std__default__Default__default { get { return ((RAST.__default.std__default__Default).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0(); } } + public static Dafny.ISequence> NoAttr { get { + return Dafny.Sequence>.FromElements(); + } } public static BigInteger MAX__TUPLE__SIZE { get { return new BigInteger(12); } } + public static Dafny.ISequence NoDoc { get { + return Dafny.Sequence.UnicodeFromString(""); + } } } public interface _IRASTTopDownVisitor { @@ -503,7 +517,7 @@ public T VisitModMapping(T acc, RAST._IModDecl modDecl, RAST._IPath SelfPath) { if (_source0.is_TypeDecl) { RAST._ITypeSynonym tpe0 = _source0.dtor_tpe; - Dafny.ISequence> _3_attributes = tpe0.dtor_attributes; + Dafny.ISequence _3_attributes = tpe0.dtor_docString; Dafny.ISequence _4_name = tpe0.dtor_name; Dafny.ISequence _5_typeParams = tpe0.dtor_typeParams; RAST._IType _6_tpe = tpe0.dtor_tpe; @@ -515,7 +529,7 @@ public T VisitModMapping(T acc, RAST._IModDecl modDecl, RAST._IPath SelfPath) { if (_source0.is_ConstDecl) { RAST._IConstant c0 = _source0.dtor_c; - Dafny.ISequence> _9_attributes = c0.dtor_attributes; + Dafny.ISequence _9_attributes = c0.dtor_docString; Dafny.ISequence _10_name = c0.dtor_name; RAST._IType _11_tpe = c0.dtor_tpe; RAST._IExpr _12_value = c0.dtor_value; @@ -527,7 +541,7 @@ public T VisitModMapping(T acc, RAST._IModDecl modDecl, RAST._IPath SelfPath) { if (_source0.is_EnumDecl) { RAST._IEnum enum0 = _source0.dtor_enum; - Dafny.ISequence> _15_attributes = enum0.dtor_attributes; + Dafny.ISequence _15_attributes = enum0.dtor_docString; Dafny.ISequence _16_name = enum0.dtor_name; Dafny.ISequence _17_typeParams = enum0.dtor_typeParams; Dafny.ISequence _18_variants = enum0.dtor_variants; @@ -639,21 +653,23 @@ public T VisitMember(T acc, RAST._IImplMember member) } { if (_source0.is_FnDecl) { - RAST._IVisibility _1_pub = _source0.dtor_pub; - RAST._IFn _2_fun = _source0.dtor_fun; - return (this).VisitFn(acc, _2_fun); + Dafny.ISequence _1_docString = _source0.dtor_docString; + Dafny.ISequence> _2_attributes = _source0.dtor_attributes; + RAST._IVisibility _3_pub = _source0.dtor_pub; + RAST._IFn _4_fun = _source0.dtor_fun; + return (this).VisitFn(acc, _4_fun); } } { if (_source0.is_TypeDeclMember) { - Dafny.ISequence _3_name = _source0.dtor_name; - RAST._IType _4_tpe = _source0.dtor_rhs; - return (this).VisitType(acc, _4_tpe); + Dafny.ISequence _5_name = _source0.dtor_name; + RAST._IType _6_tpe = _source0.dtor_rhs; + return (this).VisitType(acc, _6_tpe); } } { - RAST._IExpr _5_expr = _source0.dtor_expr; - return (_5_expr).Fold(acc, (this).dtor_VisitExprSingle, (this).dtor_VisitTypeSingle); + RAST._IExpr _7_expr = _source0.dtor_expr; + return (_7_expr).Fold(acc, (this).dtor_VisitExprSingle, (this).dtor_VisitTypeSingle); } } public T VisitFn(T acc, RAST._IFn fn) @@ -664,15 +680,14 @@ public T VisitFn(T acc, RAST._IFn fn) Dafny.ISequence _1_typeParams = _source0.dtor_typeParams; Dafny.ISequence _2_formals = _source0.dtor_formals; Std.Wrappers._IOption _3_returnType = _source0.dtor_returnType; - Dafny.ISequence _4_where = _source0.dtor_where; - Std.Wrappers._IOption _5_body = _source0.dtor_body; - T _6_acc = (this).VisitTypeParams(acc, _1_typeParams); - T _7_acc = RAST.__default.FoldLeft(Dafny.Helpers.Id, Func>>((_8_formals) => ((System.Func)((_9_acc, _10_f) => { - return ((_10_f).dtor_tpe).Fold(_9_acc, (this).dtor_VisitTypeSingle); - })))(_2_formals), _6_acc, _2_formals); - T _11_acc = (((_3_returnType).is_None) ? (_7_acc) : (((_3_returnType).dtor_value).Fold(_7_acc, (this).dtor_VisitTypeSingle))); - T _12_acc = (((_5_body).is_None) ? (_11_acc) : (((_5_body).dtor_value).Fold(_11_acc, (this).dtor_VisitExprSingle, (this).dtor_VisitTypeSingle))); - return _12_acc; + Std.Wrappers._IOption _4_body = _source0.dtor_body; + T _5_acc = (this).VisitTypeParams(acc, _1_typeParams); + T _6_acc = RAST.__default.FoldLeft(Dafny.Helpers.Id, Func>>((_7_formals) => ((System.Func)((_8_acc, _9_f) => { + return ((_9_f).dtor_tpe).Fold(_8_acc, (this).dtor_VisitTypeSingle); + })))(_2_formals), _5_acc, _2_formals); + T _10_acc = (((_3_returnType).is_None) ? (_6_acc) : (((_3_returnType).dtor_value).Fold(_6_acc, (this).dtor_VisitTypeSingle))); + T _11_acc = (((_4_body).is_None) ? (_10_acc) : (((_4_body).dtor_value).Fold(_10_acc, (this).dtor_VisitExprSingle, (this).dtor_VisitTypeSingle))); + return _11_acc; } } } @@ -778,7 +793,7 @@ public RAST._IMod ReplaceMod(RAST._IMod mod, RAST._IPath SelfPath) })))(SelfPath, mod)); RAST._IMod _5_dt__update__tmp_h0 = mod; Dafny.ISequence _6_dt__update_hbody_h0 = _0_newModDeclarations; - return RAST.Mod.create_Mod((_5_dt__update__tmp_h0).dtor_name, (_5_dt__update__tmp_h0).dtor_attributes, _6_dt__update_hbody_h0); + return RAST.Mod.create_Mod((_5_dt__update__tmp_h0).dtor_docString, (_5_dt__update__tmp_h0).dtor_attributes, (_5_dt__update__tmp_h0).dtor_name, _6_dt__update_hbody_h0); } } public RAST._IModDecl ReplaceModDecl(RAST._IModDecl modDecl, RAST._IPath SelfPath) @@ -840,51 +855,56 @@ public RAST._IModDecl ReplaceModDecl(RAST._IModDecl modDecl, RAST._IPath SelfPat public RAST._IStruct ReplaceStruct(RAST._IStruct @struct) { RAST._IStruct _source0 = @struct; { - Dafny.ISequence> _0_attributes = _source0.dtor_attributes; - Dafny.ISequence _1_name = _source0.dtor_name; - Dafny.ISequence _2_typeParams = _source0.dtor_typeParams; - RAST._IFields _3_fields = _source0.dtor_fields; - return RAST.Struct.create(_0_attributes, _1_name, (this).ReplaceTypeParams(_2_typeParams), (this).ReplaceFields(_3_fields)); + Dafny.ISequence _0_docString = _source0.dtor_docString; + Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _2_name = _source0.dtor_name; + Dafny.ISequence _3_typeParams = _source0.dtor_typeParams; + RAST._IFields _4_fields = _source0.dtor_fields; + return RAST.Struct.create(_0_docString, _1_attributes, _2_name, (this).ReplaceTypeParams(_3_typeParams), (this).ReplaceFields(_4_fields)); } } public RAST._ITypeSynonym ReplaceTypeDecl(RAST._ITypeSynonym t) { RAST._ITypeSynonym _source0 = t; { - Dafny.ISequence> _0_attributes = _source0.dtor_attributes; - Dafny.ISequence _1_name = _source0.dtor_name; - Dafny.ISequence _2_typeParams = _source0.dtor_typeParams; - RAST._IType _3_tpe = _source0.dtor_tpe; - return RAST.TypeSynonym.create(_0_attributes, _1_name, (this).ReplaceTypeParams(_2_typeParams), (this).ReplaceType(_3_tpe)); + Dafny.ISequence _0_docString = _source0.dtor_docString; + Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _2_name = _source0.dtor_name; + Dafny.ISequence _3_typeParams = _source0.dtor_typeParams; + RAST._IType _4_tpe = _source0.dtor_tpe; + return RAST.TypeSynonym.create(_0_docString, _1_attributes, _2_name, (this).ReplaceTypeParams(_3_typeParams), (this).ReplaceType(_4_tpe)); } } public RAST._IConstant ReplaceConst(RAST._IConstant t) { RAST._IConstant _source0 = t; { - Dafny.ISequence> _0_attributes = _source0.dtor_attributes; - Dafny.ISequence _1_name = _source0.dtor_name; - RAST._IType _2_tpe = _source0.dtor_tpe; - RAST._IExpr _3_value = _source0.dtor_value; - return RAST.Constant.create(_0_attributes, _1_name, (this).ReplaceType(_2_tpe), (this).ReplaceExpr(_3_value)); + Dafny.ISequence _0_docString = _source0.dtor_docString; + Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _2_name = _source0.dtor_name; + RAST._IType _3_tpe = _source0.dtor_tpe; + RAST._IExpr _4_value = _source0.dtor_value; + return RAST.Constant.create(_0_docString, _1_attributes, _2_name, (this).ReplaceType(_3_tpe), (this).ReplaceExpr(_4_value)); } } public RAST._IEnum ReplaceEnum(RAST._IEnum @enum) { RAST._IEnum _source0 = @enum; { - Dafny.ISequence> _0_attributes = _source0.dtor_attributes; - Dafny.ISequence _1_name = _source0.dtor_name; - Dafny.ISequence _2_typeParams = _source0.dtor_typeParams; - Dafny.ISequence _3_variants = _source0.dtor_variants; - return RAST.Enum.create(_0_attributes, _1_name, (this).ReplaceTypeParams(_2_typeParams), Std.Collections.Seq.__default.Map(((System.Func)((_4_t) => { - return (this).ReplaceEnumCase(_4_t); -})), _3_variants)); + Dafny.ISequence _0_docString = _source0.dtor_docString; + Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _2_name = _source0.dtor_name; + Dafny.ISequence _3_typeParams = _source0.dtor_typeParams; + Dafny.ISequence _4_variants = _source0.dtor_variants; + return RAST.Enum.create(_0_docString, _1_attributes, _2_name, (this).ReplaceTypeParams(_3_typeParams), Std.Collections.Seq.__default.Map(((System.Func)((_5_t) => { + return (this).ReplaceEnumCase(_5_t); +})), _4_variants)); } } public RAST._IEnumCase ReplaceEnumCase(RAST._IEnumCase enumCase) { RAST._IEnumCase _source0 = enumCase; { - Dafny.ISequence _0_name = _source0.dtor_name; - RAST._IFields _1_fields = _source0.dtor_fields; - return RAST.EnumCase.create(_0_name, (this).ReplaceFields(_1_fields)); + Dafny.ISequence _0_docString = _source0.dtor_docString; + Dafny.ISequence _1_name = _source0.dtor_name; + RAST._IFields _2_fields = _source0.dtor_fields; + return RAST.EnumCase.create(_0_docString, _1_name, (this).ReplaceFields(_2_fields)); } } public RAST._IImpl ReplaceImplDecl(RAST._IImpl impl) { @@ -908,22 +928,25 @@ public RAST._IImpl ReplaceImplDecl(RAST._IImpl impl) { public RAST._ITrait ReplaceTrait(RAST._ITrait tr) { RAST._ITrait _source0 = tr; { - Dafny.ISequence _0_typeParams = _source0.dtor_typeParams; - RAST._IType _1_tpe = _source0.dtor_tpe; - Dafny.ISequence _2_parents = _source0.dtor_parents; - Dafny.ISequence _3_body = _source0.dtor_body; - return RAST.Trait.create((this).ReplaceTypeParams(_0_typeParams), (this).ReplaceType(_1_tpe), Std.Collections.Seq.__default.Map(((System.Func)((_4_t) => { - return (this).ReplaceType(_4_t); -})), _2_parents), (this).ReplaceBody(_3_body)); + Dafny.ISequence _0_docString = _source0.dtor_docString; + Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _2_typeParams = _source0.dtor_typeParams; + RAST._IType _3_tpe = _source0.dtor_tpe; + Dafny.ISequence _4_parents = _source0.dtor_parents; + Dafny.ISequence _5_body = _source0.dtor_body; + return RAST.Trait.create(_0_docString, _1_attributes, (this).ReplaceTypeParams(_2_typeParams), (this).ReplaceType(_3_tpe), Std.Collections.Seq.__default.Map(((System.Func)((_6_t) => { + return (this).ReplaceType(_6_t); +})), _4_parents), (this).ReplaceBody(_5_body)); } } public RAST._ITopFnDecl ReplaceTopFn(RAST._ITopFnDecl t) { RAST._ITopFnDecl _source0 = t; { - Dafny.ISequence> _0_attributes = _source0.dtor_attributes; - RAST._IVisibility _1_visibility = _source0.dtor_visibility; - RAST._IFn _2_fn = _source0.dtor_fn; - return RAST.TopFnDecl.create(_0_attributes, _1_visibility, (this).ReplaceFn(_2_fn)); + Dafny.ISequence _0_docString = _source0.dtor_docString; + Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + RAST._IVisibility _2_visibility = _source0.dtor_visibility; + RAST._IFn _3_fn = _source0.dtor_fn; + return RAST.TopFnDecl.create(_0_docString, _1_attributes, _2_visibility, (this).ReplaceFn(_3_fn)); } } public RAST._IFn ReplaceFn(RAST._IFn t) { @@ -933,11 +956,10 @@ public RAST._IFn ReplaceFn(RAST._IFn t) { Dafny.ISequence _1_typeParams = _source0.dtor_typeParams; Dafny.ISequence _2_formals = _source0.dtor_formals; Std.Wrappers._IOption _3_returnType = _source0.dtor_returnType; - Dafny.ISequence _4_where = _source0.dtor_where; - Std.Wrappers._IOption _5_body = _source0.dtor_body; - return RAST.Fn.create(_0_name, (this).ReplaceTypeParams(_1_typeParams), Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Func>>((_6_formals) => ((System.Func)((_7_f) => { - return (_7_f).Replace(this.ReplaceType); -})))(_2_formals), _2_formals), (((_3_returnType).is_None) ? (Std.Wrappers.Option.create_None()) : (Std.Wrappers.Option.create_Some(((_3_returnType).dtor_value).Replace(this.ReplaceType)))), _4_where, (((_5_body).is_None) ? (Std.Wrappers.Option.create_None()) : (Std.Wrappers.Option.create_Some(((_5_body).dtor_value).Replace(this.ReplaceExpr, this.ReplaceType))))); + Std.Wrappers._IOption _4_body = _source0.dtor_body; + return RAST.Fn.create(_0_name, (this).ReplaceTypeParams(_1_typeParams), Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Func>>((_5_formals) => ((System.Func)((_6_f) => { + return (_6_f).Replace(this.ReplaceType); +})))(_2_formals), _2_formals), (((_3_returnType).is_None) ? (Std.Wrappers.Option.create_None()) : (Std.Wrappers.Option.create_Some(((_3_returnType).dtor_value).Replace(this.ReplaceType)))), (((_4_body).is_None) ? (Std.Wrappers.Option.create_None()) : (Std.Wrappers.Option.create_Some(((_4_body).dtor_value).Replace(this.ReplaceExpr, this.ReplaceType))))); } } public RAST._IUse ReplaceUse(RAST._IUse use) { @@ -963,21 +985,23 @@ public RAST._IImplMember ReplaceImplMember(RAST._IImplMember t) { } { if (_source0.is_FnDecl) { - RAST._IVisibility _1_pub = _source0.dtor_pub; - RAST._IFn _2_fun = _source0.dtor_fun; - return RAST.ImplMember.create_FnDecl(_1_pub, (this).ReplaceFn(_2_fun)); + Dafny.ISequence _1_docString = _source0.dtor_docString; + Dafny.ISequence> _2_attributes = _source0.dtor_attributes; + RAST._IVisibility _3_pub = _source0.dtor_pub; + RAST._IFn _4_fun = _source0.dtor_fun; + return RAST.ImplMember.create_FnDecl(_1_docString, _2_attributes, _3_pub, (this).ReplaceFn(_4_fun)); } } { if (_source0.is_TypeDeclMember) { - Dafny.ISequence _3_name = _source0.dtor_name; - RAST._IType _4_tpe = _source0.dtor_rhs; - return RAST.ImplMember.create_TypeDeclMember(_3_name, (this).ReplaceType(_4_tpe)); + Dafny.ISequence _5_name = _source0.dtor_name; + RAST._IType _6_tpe = _source0.dtor_rhs; + return RAST.ImplMember.create_TypeDeclMember(_5_name, (this).ReplaceType(_6_tpe)); } } { - RAST._IExpr _5_expr = _source0.dtor_expr; - return RAST.ImplMember.create_ImplMemberMacro((this).ReplaceExpr(_5_expr)); + RAST._IExpr _7_expr = _source0.dtor_expr; + return RAST.ImplMember.create_ImplMemberMacro((this).ReplaceExpr(_7_expr)); } } public RAST._IExpr ReplaceExpr(RAST._IExpr e) { @@ -1015,8 +1039,9 @@ public RAST._IFields ReplaceFields(RAST._IFields fields) { public interface _IMod { bool is_Mod { get; } bool is_ExternMod { get; } - Dafny.ISequence dtor_name { get; } + Dafny.ISequence dtor_docString { get; } Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_body { get; } _IMod DowncastClone(); __T Fold<__T>(__T acc, Func<__T, RAST._IModDecl, __T> accBuilder); @@ -1025,7 +1050,7 @@ public interface _IMod { public abstract class Mod : _IMod { public Mod() { } - private static readonly RAST._IMod theDefault = create_Mod(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty); + private static readonly RAST._IMod theDefault = create_Mod(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static RAST._IMod Default() { return theDefault; } @@ -1033,19 +1058,18 @@ public static RAST._IMod Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IMod create_Mod(Dafny.ISequence name, Dafny.ISequence> attributes, Dafny.ISequence body) { - return new Mod_Mod(name, attributes, body); + public static _IMod create_Mod(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence body) { + return new Mod_Mod(docString, attributes, name, body); } public static _IMod create_ExternMod(Dafny.ISequence name) { return new Mod_ExternMod(name); } public bool is_Mod { get { return this is Mod_Mod; } } public bool is_ExternMod { get { return this is Mod_ExternMod; } } - public Dafny.ISequence dtor_name { + public Dafny.ISequence dtor_docString { get { var d = this; - if (d is Mod_Mod) { return ((Mod_Mod)d)._name; } - return ((Mod_ExternMod)d)._name; + return ((Mod_Mod)d)._docString; } } public Dafny.ISequence> dtor_attributes { @@ -1054,6 +1078,13 @@ public Dafny.ISequence> dtor_attributes { return ((Mod_Mod)d)._attributes; } } + public Dafny.ISequence dtor_name { + get { + var d = this; + if (d is Mod_Mod) { return ((Mod_Mod)d)._name; } + return ((Mod_ExternMod)d)._name; + } + } public Dafny.ISequence dtor_body { get { var d = this; @@ -1084,47 +1115,53 @@ public __T Fold<__T>(__T acc, Func<__T, RAST._IModDecl, __T> accBuilder) } } { - Dafny.ISequence _1_name = _source0.dtor_name; + Dafny.ISequence _1_docString = _source0.dtor_docString; Dafny.ISequence> _2_attributes = _source0.dtor_attributes; - Dafny.ISequence _3_body = _source0.dtor_body; - return Dafny.Sequence.Concat(RAST.Attribute.ToStringMultiple(_2_attributes, ind), Dafny.Helpers.Let>(((new BigInteger((_3_body).Count)).Sign == 1) && (((_3_body).Select(BigInteger.Zero)).is_UseDecl), _pat_let13_0 => Dafny.Helpers.Let>(_pat_let13_0, _4_startWithUse => Dafny.Helpers.Let, Dafny.ISequence>(((_4_startWithUse) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _pat_let_tv0), RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(""))), _pat_let14_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let14_0, _5_prefixIfNotUseDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_4_startWithUse) ? (Dafny.Sequence.Concat(_pat_let_tv1, RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(""))), _pat_let15_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let15_0, _6_prefixIfUseDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_4_startWithUse) ? (Dafny.Sequence.UnicodeFromString("\n")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n\n"), _pat_let_tv2), RAST.__default.IND))), _pat_let16_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let16_0, _7_infixDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_4_startWithUse) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(_pat_let_tv3, RAST.__default.IND))), _pat_let17_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let17_0, _8_initialIdent => Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("pub mod "), _1_name), Dafny.Sequence.UnicodeFromString(" {")), Dafny.Sequence.UnicodeFromString("\n")), _8_initialIdent), RAST.__default.SeqToString(_3_body, Dafny.Helpers.Id, Dafny.ISequence, Dafny.ISequence, Func>>>((_9_prefixIfUseDecl, _10_prefixIfNotUseDecl, _11_ind) => ((System.Func>)((_12_modDecl) => { - return Dafny.Sequence.Concat((((_12_modDecl).is_UseDecl) ? (_9_prefixIfUseDecl) : (_10_prefixIfNotUseDecl)), (_12_modDecl)._ToString(Dafny.Sequence.Concat(_11_ind, RAST.__default.IND))); - })))(_6_prefixIfUseDecl, _5_prefixIfNotUseDecl, _pat_let_tv4), _7_infixDecl)), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv5), Dafny.Sequence.UnicodeFromString("}"))))))))))))); + Dafny.ISequence _3_name = _source0.dtor_name; + Dafny.ISequence _4_body = _source0.dtor_body; + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.__default.ToDocstringPrefix(_1_docString, ind), RAST.Attribute.ToStringMultiple(_2_attributes, ind)), Dafny.Helpers.Let>(((new BigInteger((_4_body).Count)).Sign == 1) && (((_4_body).Select(BigInteger.Zero)).is_UseDecl), _pat_let13_0 => Dafny.Helpers.Let>(_pat_let13_0, _5_startWithUse => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _pat_let_tv0), RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(""))), _pat_let14_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let14_0, _6_prefixIfNotUseDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.Concat(_pat_let_tv1, RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(""))), _pat_let15_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let15_0, _7_prefixIfUseDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.UnicodeFromString("\n")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n\n"), _pat_let_tv2), RAST.__default.IND))), _pat_let16_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let16_0, _8_infixDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(_pat_let_tv3, RAST.__default.IND))), _pat_let17_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let17_0, _9_initialIdent => Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("pub mod "), _3_name), Dafny.Sequence.UnicodeFromString(" {")), Dafny.Sequence.UnicodeFromString("\n")), _9_initialIdent), RAST.__default.SeqToString(_4_body, Dafny.Helpers.Id, Dafny.ISequence, Dafny.ISequence, Func>>>((_10_prefixIfUseDecl, _11_prefixIfNotUseDecl, _12_ind) => ((System.Func>)((_13_modDecl) => { + return Dafny.Sequence.Concat((((_13_modDecl).is_UseDecl) ? (_10_prefixIfUseDecl) : (_11_prefixIfNotUseDecl)), (_13_modDecl)._ToString(Dafny.Sequence.Concat(_12_ind, RAST.__default.IND))); + })))(_7_prefixIfUseDecl, _6_prefixIfNotUseDecl, _pat_let_tv4), _8_infixDecl)), Dafny.Sequence.UnicodeFromString("\n")), _pat_let_tv5), Dafny.Sequence.UnicodeFromString("}"))))))))))))); } } } public class Mod_Mod : Mod { - public readonly Dafny.ISequence _name; + public readonly Dafny.ISequence _docString; public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _body; - public Mod_Mod(Dafny.ISequence name, Dafny.ISequence> attributes, Dafny.ISequence body) : base() { - this._name = name; + public Mod_Mod(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence body) : base() { + this._docString = docString; this._attributes = attributes; + this._name = name; this._body = body; } public override _IMod DowncastClone() { if (this is _IMod dt) { return dt; } - return new Mod_Mod(_name, _attributes, _body); + return new Mod_Mod(_docString, _attributes, _name, _body); } public override bool Equals(object other) { var oth = other as RAST.Mod_Mod; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._body, oth._body); + return oth != null && object.Equals(this._docString, oth._docString) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._name, oth._name) && 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._docString)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); return (int) hash; } public override string ToString() { string s = "RAST.Mod.Mod"; s += "("; - s += this._name.ToVerbatimString(true); + s += this._docString.ToVerbatimString(true); s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ", "; + s += this._name.ToVerbatimString(true); + s += ", "; s += Dafny.Helpers.ToString(this._body); s += ")"; return s; @@ -1618,6 +1655,7 @@ public RAST._IPath dtor_path { public interface _ITopFnDecl { bool is_TopFn { get; } + Dafny.ISequence dtor_docString { get; } Dafny.ISequence> dtor_attributes { get; } RAST._IVisibility dtor_visibility { get; } RAST._IFn dtor_fn { get; } @@ -1625,25 +1663,28 @@ public interface _ITopFnDecl { Dafny.ISequence _ToString(Dafny.ISequence ind); } public class TopFnDecl : _ITopFnDecl { + public readonly Dafny.ISequence _docString; public readonly Dafny.ISequence> _attributes; public readonly RAST._IVisibility _visibility; public readonly RAST._IFn _fn; - public TopFnDecl(Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { + public TopFnDecl(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { + this._docString = docString; this._attributes = attributes; this._visibility = visibility; this._fn = fn; } public _ITopFnDecl DowncastClone() { if (this is _ITopFnDecl dt) { return dt; } - return new TopFnDecl(_attributes, _visibility, _fn); + return new TopFnDecl(_docString, _attributes, _visibility, _fn); } public override bool Equals(object other) { var oth = other as RAST.TopFnDecl; - return oth != null && object.Equals(this._attributes, oth._attributes) && object.Equals(this._visibility, oth._visibility) && object.Equals(this._fn, oth._fn); + return oth != null && object.Equals(this._docString, oth._docString) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._visibility, oth._visibility) && object.Equals(this._fn, oth._fn); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._docString)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._visibility)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fn)); @@ -1652,6 +1693,8 @@ public override int GetHashCode() { public override string ToString() { string s = "RAST.TopFnDecl.TopFn"; s += "("; + s += this._docString.ToVerbatimString(true); + s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ", "; s += Dafny.Helpers.ToString(this._visibility); @@ -1660,7 +1703,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._ITopFnDecl theDefault = create(Dafny.Sequence>.Empty, RAST.Visibility.Default(), RAST.Fn.Default()); + private static readonly RAST._ITopFnDecl theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, RAST.Visibility.Default(), RAST.Fn.Default()); public static RAST._ITopFnDecl Default() { return theDefault; } @@ -1668,13 +1711,18 @@ public static RAST._ITopFnDecl Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITopFnDecl create(Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { - return new TopFnDecl(attributes, visibility, fn); + public static _ITopFnDecl create(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { + return new TopFnDecl(docString, attributes, visibility, fn); } - public static _ITopFnDecl create_TopFn(Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { - return create(attributes, visibility, fn); + public static _ITopFnDecl create_TopFn(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { + return create(docString, attributes, visibility, fn); } public bool is_TopFn { get { return true; } } + public Dafny.ISequence dtor_docString { + get { + return this._docString; + } + } public Dafny.ISequence> dtor_attributes { get { return this._attributes; @@ -1691,7 +1739,7 @@ public RAST._IFn dtor_fn { } } public Dafny.ISequence _ToString(Dafny.ISequence ind) { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind), ((this).dtor_visibility)._ToString()), ((this).dtor_fn)._ToString(ind)); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.__default.ToDocstringPrefix((this).dtor_docString, ind), RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind)), ((this).dtor_visibility)._ToString()), ((this).dtor_fn)._ToString(ind)); } } @@ -1754,6 +1802,7 @@ public Dafny.ISequence dtor_content { public interface _IStruct { bool is_Struct { get; } + Dafny.ISequence dtor_docString { get; } Dafny.ISequence> dtor_attributes { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } @@ -1762,11 +1811,13 @@ public interface _IStruct { Dafny.ISequence _ToString(Dafny.ISequence ind); } public class Struct : _IStruct { + public readonly Dafny.ISequence _docString; public readonly Dafny.ISequence> _attributes; public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _typeParams; public readonly RAST._IFields _fields; - public Struct(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { + public Struct(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { + this._docString = docString; this._attributes = attributes; this._name = name; this._typeParams = typeParams; @@ -1774,15 +1825,16 @@ public Struct(Dafny.ISequence> attributes, Dafny.ISe } public _IStruct DowncastClone() { if (this is _IStruct dt) { return dt; } - return new Struct(_attributes, _name, _typeParams, _fields); + return new Struct(_docString, _attributes, _name, _typeParams, _fields); } public override bool Equals(object other) { var oth = other as RAST.Struct; - return oth != null && object.Equals(this._attributes, oth._attributes) && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._fields, oth._fields); + return oth != null && object.Equals(this._docString, oth._docString) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._fields, oth._fields); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._docString)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParams)); @@ -1792,6 +1844,8 @@ public override int GetHashCode() { public override string ToString() { string s = "RAST.Struct.Struct"; s += "("; + s += this._docString.ToVerbatimString(true); + s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ", "; s += this._name.ToVerbatimString(true); @@ -1802,7 +1856,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.Fields.Default()); + private static readonly RAST._IStruct theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Fields.Default()); public static RAST._IStruct Default() { return theDefault; } @@ -1810,13 +1864,18 @@ 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._IFields fields) { - return new Struct(attributes, name, typeParams, fields); + public static _IStruct create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { + return new Struct(docString, attributes, name, typeParams, fields); } - public static _IStruct create_Struct(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { - return create(attributes, name, typeParams, fields); + public static _IStruct create_Struct(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { + return create(docString, attributes, name, typeParams, fields); } public bool is_Struct { get { return true; } } + public Dafny.ISequence dtor_docString { + get { + return this._docString; + } + } public Dafny.ISequence> dtor_attributes { get { return this._attributes; @@ -1838,12 +1897,13 @@ public RAST._IFields dtor_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.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("")))); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.__default.ToDocstringPrefix((this).dtor_docString, ind), 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 _ITypeSynonym { bool is_TypeSynonym { get; } + Dafny.ISequence dtor_docString { get; } Dafny.ISequence> dtor_attributes { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } @@ -1852,11 +1912,13 @@ public interface _ITypeSynonym { Dafny.ISequence _ToString(Dafny.ISequence ind); } public class TypeSynonym : _ITypeSynonym { + public readonly Dafny.ISequence _docString; public readonly Dafny.ISequence> _attributes; public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _typeParams; public readonly RAST._IType _tpe; - public TypeSynonym(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { + public TypeSynonym(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { + this._docString = docString; this._attributes = attributes; this._name = name; this._typeParams = typeParams; @@ -1864,15 +1926,16 @@ public TypeSynonym(Dafny.ISequence> attributes, Dafn } public _ITypeSynonym DowncastClone() { if (this is _ITypeSynonym dt) { return dt; } - return new TypeSynonym(_attributes, _name, _typeParams, _tpe); + return new TypeSynonym(_docString, _attributes, _name, _typeParams, _tpe); } public override bool Equals(object other) { var oth = other as RAST.TypeSynonym; - return oth != null && object.Equals(this._attributes, oth._attributes) && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._tpe, oth._tpe); + return oth != null && object.Equals(this._docString, oth._docString) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._tpe, oth._tpe); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._docString)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParams)); @@ -1882,6 +1945,8 @@ public override int GetHashCode() { public override string ToString() { string s = "RAST.TypeSynonym.TypeSynonym"; s += "("; + s += this._docString.ToVerbatimString(true); + s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ", "; s += this._name.ToVerbatimString(true); @@ -1892,7 +1957,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._ITypeSynonym theDefault = create(Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Type.Default()); + private static readonly RAST._ITypeSynonym theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Type.Default()); public static RAST._ITypeSynonym Default() { return theDefault; } @@ -1900,13 +1965,18 @@ public static RAST._ITypeSynonym Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITypeSynonym create(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { - return new TypeSynonym(attributes, name, typeParams, tpe); + public static _ITypeSynonym create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { + return new TypeSynonym(docString, attributes, name, typeParams, tpe); } - public static _ITypeSynonym create_TypeSynonym(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { - return create(attributes, name, typeParams, tpe); + public static _ITypeSynonym create_TypeSynonym(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { + return create(docString, attributes, name, typeParams, tpe); } public bool is_TypeSynonym { get { return true; } } + public Dafny.ISequence dtor_docString { + get { + return this._docString; + } + } public Dafny.ISequence> dtor_attributes { get { return this._attributes; @@ -1928,12 +1998,13 @@ public RAST._IType dtor_tpe { } } 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(RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind), Dafny.Sequence.UnicodeFromString("pub type ")), (this).dtor_name), RAST.TypeParamDecl.ToStringMultiple((this).dtor_typeParams, ind)), Dafny.Sequence.UnicodeFromString(" = ")), ((this).dtor_tpe)._ToString(ind)), Dafny.Sequence.UnicodeFromString(";")); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.__default.ToDocstringPrefix((this).dtor_docString, ind), RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind)), Dafny.Sequence.UnicodeFromString("pub type ")), (this).dtor_name), RAST.TypeParamDecl.ToStringMultiple((this).dtor_typeParams, ind)), Dafny.Sequence.UnicodeFromString(" = ")), ((this).dtor_tpe)._ToString(ind)), Dafny.Sequence.UnicodeFromString(";")); } } public interface _IConstant { bool is_Constant { get; } + Dafny.ISequence dtor_docString { get; } Dafny.ISequence> dtor_attributes { get; } Dafny.ISequence dtor_name { get; } RAST._IType dtor_tpe { get; } @@ -1942,11 +2013,13 @@ public interface _IConstant { Dafny.ISequence _ToString(Dafny.ISequence ind); } public class Constant : _IConstant { + public readonly Dafny.ISequence _docString; public readonly Dafny.ISequence> _attributes; public readonly Dafny.ISequence _name; public readonly RAST._IType _tpe; public readonly RAST._IExpr _value; - public Constant(Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { + public Constant(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { + this._docString = docString; this._attributes = attributes; this._name = name; this._tpe = tpe; @@ -1954,15 +2027,16 @@ public Constant(Dafny.ISequence> attributes, Dafny.I } public _IConstant DowncastClone() { if (this is _IConstant dt) { return dt; } - return new Constant(_attributes, _name, _tpe, _value); + return new Constant(_docString, _attributes, _name, _tpe, _value); } public override bool Equals(object other) { var oth = other as RAST.Constant; - return oth != null && object.Equals(this._attributes, oth._attributes) && object.Equals(this._name, oth._name) && object.Equals(this._tpe, oth._tpe) && object.Equals(this._value, oth._value); + return oth != null && object.Equals(this._docString, oth._docString) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._name, oth._name) && object.Equals(this._tpe, oth._tpe) && object.Equals(this._value, oth._value); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._docString)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._tpe)); @@ -1972,6 +2046,8 @@ public override int GetHashCode() { public override string ToString() { string s = "RAST.Constant.Constant"; s += "("; + s += this._docString.ToVerbatimString(true); + s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ", "; s += this._name.ToVerbatimString(true); @@ -1982,7 +2058,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._IConstant theDefault = create(Dafny.Sequence>.Empty, Dafny.Sequence.Empty, RAST.Type.Default(), RAST.Expr.Default()); + private static readonly RAST._IConstant theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, RAST.Type.Default(), RAST.Expr.Default()); public static RAST._IConstant Default() { return theDefault; } @@ -1990,13 +2066,18 @@ public static RAST._IConstant Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IConstant create(Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { - return new Constant(attributes, name, tpe, @value); + public static _IConstant create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { + return new Constant(docString, attributes, name, tpe, @value); } - public static _IConstant create_Constant(Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { - return create(attributes, name, tpe, @value); + public static _IConstant create_Constant(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { + return create(docString, attributes, name, tpe, @value); } public bool is_Constant { get { return true; } } + public Dafny.ISequence dtor_docString { + get { + return this._docString; + } + } public Dafny.ISequence> dtor_attributes { get { return this._attributes; @@ -2018,7 +2099,7 @@ public RAST._IExpr dtor_value { } } 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(RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind), Dafny.Sequence.UnicodeFromString("pub const ")), (this).dtor_name), Dafny.Sequence.UnicodeFromString(": ")), ((this).dtor_tpe)._ToString(ind)), Dafny.Sequence.UnicodeFromString(" = ")), ((this).dtor_value)._ToString(ind)), Dafny.Sequence.UnicodeFromString(";")); + 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.__default.ToDocstringPrefix((this).dtor_docString, ind), RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind)), Dafny.Sequence.UnicodeFromString("pub const ")), (this).dtor_name), Dafny.Sequence.UnicodeFromString(": ")), ((this).dtor_tpe)._ToString(ind)), Dafny.Sequence.UnicodeFromString(" = ")), ((this).dtor_value)._ToString(ind)), Dafny.Sequence.UnicodeFromString(";")); } } @@ -2289,29 +2370,33 @@ public override string ToString() { public interface _IEnumCase { bool is_EnumCase { get; } + Dafny.ISequence dtor_docString { get; } Dafny.ISequence dtor_name { get; } RAST._IFields dtor_fields { get; } _IEnumCase DowncastClone(); Dafny.ISequence _ToString(Dafny.ISequence ind, bool newLine); } public class EnumCase : _IEnumCase { + public readonly Dafny.ISequence _docString; public readonly Dafny.ISequence _name; public readonly RAST._IFields _fields; - public EnumCase(Dafny.ISequence name, RAST._IFields fields) { + public EnumCase(Dafny.ISequence docString, Dafny.ISequence name, RAST._IFields fields) { + this._docString = docString; this._name = name; this._fields = fields; } public _IEnumCase DowncastClone() { if (this is _IEnumCase dt) { return dt; } - return new EnumCase(_name, _fields); + return new EnumCase(_docString, _name, _fields); } public override bool Equals(object other) { var oth = other as RAST.EnumCase; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._fields, oth._fields); + return oth != null && object.Equals(this._docString, oth._docString) && object.Equals(this._name, oth._name) && object.Equals(this._fields, oth._fields); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._docString)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fields)); return (int) hash; @@ -2319,13 +2404,15 @@ public override int GetHashCode() { public override string ToString() { string s = "RAST.EnumCase.EnumCase"; s += "("; + s += this._docString.ToVerbatimString(true); + s += ", "; s += this._name.ToVerbatimString(true); s += ", "; s += Dafny.Helpers.ToString(this._fields); s += ")"; return s; } - private static readonly RAST._IEnumCase theDefault = create(Dafny.Sequence.Empty, RAST.Fields.Default()); + private static readonly RAST._IEnumCase theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Fields.Default()); public static RAST._IEnumCase Default() { return theDefault; } @@ -2333,13 +2420,18 @@ public static RAST._IEnumCase Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IEnumCase create(Dafny.ISequence name, RAST._IFields fields) { - return new EnumCase(name, fields); + public static _IEnumCase create(Dafny.ISequence docString, Dafny.ISequence name, RAST._IFields fields) { + return new EnumCase(docString, name, fields); } - public static _IEnumCase create_EnumCase(Dafny.ISequence name, RAST._IFields fields) { - return create(name, fields); + public static _IEnumCase create_EnumCase(Dafny.ISequence docString, Dafny.ISequence name, RAST._IFields fields) { + return create(docString, name, fields); } public bool is_EnumCase { get { return true; } } + public Dafny.ISequence dtor_docString { + get { + return this._docString; + } + } public Dafny.ISequence dtor_name { get { return this._name; @@ -2352,12 +2444,13 @@ public RAST._IFields dtor_fields { } public Dafny.ISequence _ToString(Dafny.ISequence ind, bool newLine) { - return Dafny.Sequence.Concat((this).dtor_name, ((this).dtor_fields)._ToString(ind, newLine)); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.__default.ToDocstringPrefix((this).dtor_docString, ind), (this).dtor_name), ((this).dtor_fields)._ToString(ind, newLine)); } } public interface _IEnum { bool is_Enum { get; } + Dafny.ISequence dtor_docString { get; } Dafny.ISequence> dtor_attributes { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } @@ -2366,11 +2459,13 @@ public interface _IEnum { Dafny.ISequence _ToString(Dafny.ISequence ind); } public class Enum : _IEnum { + public readonly Dafny.ISequence _docString; public readonly Dafny.ISequence> _attributes; public readonly Dafny.ISequence _name; 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 docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + this._docString = docString; this._attributes = attributes; this._name = name; this._typeParams = typeParams; @@ -2378,15 +2473,16 @@ public Enum(Dafny.ISequence> attributes, Dafny.ISequ } public _IEnum DowncastClone() { if (this is _IEnum dt) { return dt; } - return new Enum(_attributes, _name, _typeParams, _variants); + return new Enum(_docString, _attributes, _name, _typeParams, _variants); } public override bool Equals(object other) { var oth = other as RAST.Enum; - return oth != null && object.Equals(this._attributes, oth._attributes) && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._variants, oth._variants); + return oth != null && object.Equals(this._docString, oth._docString) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._variants, oth._variants); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._docString)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParams)); @@ -2396,6 +2492,8 @@ public override int GetHashCode() { public override string ToString() { string s = "RAST.Enum.Enum"; s += "("; + s += this._docString.ToVerbatimString(true); + s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ", "; s += this._name.ToVerbatimString(true); @@ -2406,7 +2504,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, Dafny.Sequence.Empty); public static RAST._IEnum Default() { return theDefault; } @@ -2414,13 +2512,18 @@ 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) { - return new Enum(attributes, name, typeParams, variants); + public static _IEnum create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + return new Enum(docString, attributes, name, typeParams, variants); } - public static _IEnum create_Enum(Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { - return create(attributes, name, typeParams, variants); + public static _IEnum create_Enum(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + return create(docString, attributes, name, typeParams, variants); } public bool is_Enum { get { return true; } } + public Dafny.ISequence dtor_docString { + get { + return this._docString; + } + } public Dafny.ISequence> dtor_attributes { get { return this._attributes; @@ -2442,7 +2545,7 @@ 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.TypeParamDecl.ToStringMultiple((this).dtor_typeParams, ind)), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString((this).dtor_variants, Dafny.Helpers.Id, Func>>>((_0_ind) => ((System.Func>)((_1_variant) => { + 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(RAST.__default.ToDocstringPrefix((this).dtor_docString, ind), 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>>>((_0_ind) => ((System.Func>)((_1_variant) => { return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _0_ind), RAST.__default.IND), (_1_variant)._ToString(Dafny.Sequence.Concat(_0_ind, RAST.__default.IND), true)); })))(ind), Dafny.Sequence.UnicodeFromString(","))), Dafny.Sequence.UnicodeFromString("\n")), ind), Dafny.Sequence.UnicodeFromString("}")); } @@ -4622,6 +4725,8 @@ public override string ToString() { public interface _ITrait { bool is_Trait { get; } + Dafny.ISequence dtor_docString { get; } + Dafny.ISequence> dtor_attributes { get; } Dafny.ISequence dtor_typeParams { get; } RAST._IType dtor_tpe { get; } Dafny.ISequence dtor_parents { get; } @@ -4630,11 +4735,15 @@ public interface _ITrait { Dafny.ISequence _ToString(Dafny.ISequence ind); } public class Trait : _ITrait { + public readonly Dafny.ISequence _docString; + public readonly Dafny.ISequence> _attributes; public readonly Dafny.ISequence _typeParams; public readonly RAST._IType _tpe; public readonly Dafny.ISequence _parents; public readonly Dafny.ISequence _body; - public Trait(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { + public Trait(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { + this._docString = docString; + this._attributes = attributes; this._typeParams = typeParams; this._tpe = tpe; this._parents = parents; @@ -4642,15 +4751,17 @@ public Trait(Dafny.ISequence typeParams, RAST._IType tpe, } public _ITrait DowncastClone() { if (this is _ITrait dt) { return dt; } - return new Trait(_typeParams, _tpe, _parents, _body); + return new Trait(_docString, _attributes, _typeParams, _tpe, _parents, _body); } public override bool Equals(object other) { var oth = other as RAST.Trait; - return oth != null && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._tpe, oth._tpe) && object.Equals(this._parents, oth._parents) && object.Equals(this._body, oth._body); + return oth != null && object.Equals(this._docString, oth._docString) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._tpe, oth._tpe) && object.Equals(this._parents, oth._parents) && 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._docString)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParams)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._tpe)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._parents)); @@ -4660,6 +4771,10 @@ public override int GetHashCode() { public override string ToString() { string s = "RAST.Trait.Trait"; s += "("; + s += this._docString.ToVerbatimString(true); + s += ", "; + s += Dafny.Helpers.ToString(this._attributes); + s += ", "; s += Dafny.Helpers.ToString(this._typeParams); s += ", "; s += Dafny.Helpers.ToString(this._tpe); @@ -4670,7 +4785,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, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, RAST.Type.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static RAST._ITrait Default() { return theDefault; } @@ -4678,13 +4793,23 @@ public static RAST._ITrait Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITrait create(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { - return new Trait(typeParams, tpe, parents, body); + public static _ITrait create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { + return new Trait(docString, attributes, typeParams, tpe, parents, body); } - public static _ITrait create_Trait(Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { - return create(typeParams, tpe, parents, body); + public static _ITrait create_Trait(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { + return create(docString, attributes, typeParams, tpe, parents, body); } public bool is_Trait { get { return true; } } + public Dafny.ISequence dtor_docString { + get { + return this._docString; + } + } + public Dafny.ISequence> dtor_attributes { + get { + return this._attributes; + } + } public Dafny.ISequence dtor_typeParams { get { return this._typeParams; @@ -4716,7 +4841,7 @@ public Dafny.ISequence dtor_body { return (_7_t)._ToString(Dafny.Sequence.Concat(_6_ind, RAST.__default.IND)); })))(ind), Dafny.Sequence.UnicodeFromString(" + "))))); Dafny.ISequence _8_where = (((_2_additionalConstraints).Equals(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("\n"), ind), RAST.__default.IND), Dafny.Sequence.UnicodeFromString("where\n")), ind), RAST.__default.IND), _2_additionalConstraints))); - 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 "), ((this).dtor_tpe)._ToString(ind)), _5_parents), _8_where), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString((this).dtor_body, Dafny.Helpers.Id, Func>>>((_9_ind) => ((System.Func>)((_10_member) => { + 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(RAST.__default.ToDocstringPrefix((this).dtor_docString, ind), RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind)), Dafny.Sequence.UnicodeFromString("pub trait ")), ((this).dtor_tpe)._ToString(ind)), _5_parents), _8_where), Dafny.Sequence.UnicodeFromString(" {")), RAST.__default.SeqToString((this).dtor_body, Dafny.Helpers.Id, Func>>>((_9_ind) => ((System.Func>)((_10_member) => { return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _9_ind), RAST.__default.IND), (_10_member)._ToString(Dafny.Sequence.Concat(_9_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("}")); } @@ -4873,6 +4998,8 @@ public interface _IImplMember { Dafny.ISequence dtor_content { get; } Dafny.ISequence dtor_name { get; } RAST._IType dtor_rhs { get; } + Dafny.ISequence dtor_docString { get; } + Dafny.ISequence> dtor_attributes { get; } RAST._IVisibility dtor_pub { get; } RAST._IFn dtor_fun { get; } RAST._IExpr dtor_expr { get; } @@ -4896,8 +5023,8 @@ public static _IImplMember create_RawImplMember(Dafny.ISequence cont public static _IImplMember create_TypeDeclMember(Dafny.ISequence name, RAST._IType rhs) { return new ImplMember_TypeDeclMember(name, rhs); } - public static _IImplMember create_FnDecl(RAST._IVisibility pub, RAST._IFn fun) { - return new ImplMember_FnDecl(pub, fun); + public static _IImplMember create_FnDecl(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility pub, RAST._IFn fun) { + return new ImplMember_FnDecl(docString, attributes, pub, fun); } public static _IImplMember create_ImplMemberMacro(RAST._IExpr expr) { return new ImplMember_ImplMemberMacro(expr); @@ -4924,6 +5051,18 @@ public RAST._IType dtor_rhs { return ((ImplMember_TypeDeclMember)d)._rhs; } } + public Dafny.ISequence dtor_docString { + get { + var d = this; + return ((ImplMember_FnDecl)d)._docString; + } + } + public Dafny.ISequence> dtor_attributes { + get { + var d = this; + return ((ImplMember_FnDecl)d)._attributes; + } + } public RAST._IVisibility dtor_pub { get { var d = this; @@ -4945,7 +5084,7 @@ public RAST._IExpr dtor_expr { public abstract _IImplMember DowncastClone(); public Dafny.ISequence _ToString(Dafny.ISequence ind) { if ((this).is_FnDecl) { - return Dafny.Sequence.Concat(((this).dtor_pub)._ToString(), ((this).dtor_fun)._ToString(ind)); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.__default.ToDocstringPrefix((this).dtor_docString, ind), RAST.Attribute.ToStringMultiple((this).dtor_attributes, ind)), ((this).dtor_pub)._ToString()), ((this).dtor_fun)._ToString(ind)); } else if ((this).is_ImplMemberMacro) { return Dafny.Sequence.Concat(((this).dtor_expr)._ToString(ind), Dafny.Sequence.UnicodeFromString(";")); } else if ((this).is_TypeDeclMember) { @@ -5015,23 +5154,29 @@ public override string ToString() { } } public class ImplMember_FnDecl : ImplMember { + public readonly Dafny.ISequence _docString; + public readonly Dafny.ISequence> _attributes; public readonly RAST._IVisibility _pub; public readonly RAST._IFn _fun; - public ImplMember_FnDecl(RAST._IVisibility pub, RAST._IFn fun) : base() { + public ImplMember_FnDecl(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility pub, RAST._IFn fun) : base() { + this._docString = docString; + this._attributes = attributes; this._pub = pub; this._fun = fun; } public override _IImplMember DowncastClone() { if (this is _IImplMember dt) { return dt; } - return new ImplMember_FnDecl(_pub, _fun); + return new ImplMember_FnDecl(_docString, _attributes, _pub, _fun); } public override bool Equals(object other) { var oth = other as RAST.ImplMember_FnDecl; - return oth != null && object.Equals(this._pub, oth._pub) && object.Equals(this._fun, oth._fun); + return oth != null && object.Equals(this._docString, oth._docString) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._pub, oth._pub) && object.Equals(this._fun, oth._fun); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._docString)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._pub)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fun)); return (int) hash; @@ -5039,6 +5184,10 @@ public override int GetHashCode() { public override string ToString() { string s = "RAST.ImplMember.FnDecl"; s += "("; + s += this._docString.ToVerbatimString(true); + s += ", "; + s += Dafny.Helpers.ToString(this._attributes); + s += ", "; s += Dafny.Helpers.ToString(this._pub); s += ", "; s += Dafny.Helpers.ToString(this._fun); @@ -8840,7 +8989,6 @@ public interface _IFn { Dafny.ISequence dtor_typeParams { get; } Dafny.ISequence dtor_formals { get; } Std.Wrappers._IOption dtor_returnType { get; } - Dafny.ISequence dtor_where { get; } Std.Wrappers._IOption dtor_body { get; } _IFn DowncastClone(); Dafny.ISequence _ToString(Dafny.ISequence ind); @@ -8850,23 +8998,21 @@ public class Fn : _IFn { 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, Std.Wrappers._IOption body) { this._name = name; this._typeParams = typeParams; this._formals = formals; this._returnType = returnType; - this._where = @where; this._body = body; } public _IFn DowncastClone() { if (this is _IFn dt) { return dt; } - return new Fn(_name, _typeParams, _formals, _returnType, _where, _body); + return new Fn(_name, _typeParams, _formals, _returnType, _body); } public override bool Equals(object other) { var oth = other as RAST.Fn; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._formals, oth._formals) && object.Equals(this._returnType, oth._returnType) && object.Equals(this._where, oth._where) && object.Equals(this._body, oth._body); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._formals, oth._formals) && object.Equals(this._returnType, oth._returnType) && object.Equals(this._body, oth._body); } public override int GetHashCode() { ulong hash = 5381; @@ -8875,7 +9021,6 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParams)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._formals)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._returnType)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._where)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); return (int) hash; } @@ -8890,13 +9035,11 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._returnType); s += ", "; - s += this._where.ToVerbatimString(true); - s += ", "; s += Dafny.Helpers.ToString(this._body); 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(), Std.Wrappers.Option.Default()); public static RAST._IFn Default() { return theDefault; } @@ -8904,11 +9047,11 @@ 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) { - return new Fn(name, typeParams, formals, returnType, @where, body); + public static _IFn create(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence formals, Std.Wrappers._IOption returnType, Std.Wrappers._IOption body) { + return new Fn(name, typeParams, formals, returnType, 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 static _IFn create_Fn(Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence formals, Std.Wrappers._IOption returnType, Std.Wrappers._IOption body) { + return create(name, typeParams, formals, returnType, body); } public bool is_Fn { get { return true; } } public Dafny.ISequence dtor_name { @@ -8931,18 +9074,13 @@ public Std.Wrappers._IOption dtor_returnType { return this._returnType; } } - public Dafny.ISequence dtor_where { - get { - return this._where; - } - } public Std.Wrappers._IOption dtor_body { get { return this._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.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>>>((_0_ind) => ((System.Func>)((_1_formal) => { + 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("fn "), (this).dtor_name), RAST.TypeParamDecl.ToStringMultiple((this).dtor_typeParams, ind)), Dafny.Sequence.UnicodeFromString("(")), RAST.__default.SeqToString((this).dtor_formals, Dafny.Helpers.Id, Func>>>((_0_ind) => ((System.Func>)((_1_formal) => { return (_1_formal)._ToString(_0_ind); })))(ind), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(")")), ((System.Func>)(() => { Std.Wrappers._IOption _source0 = (this).dtor_returnType; @@ -8955,7 +9093,7 @@ public Std.Wrappers._IOption dtor_body { { return Dafny.Sequence.UnicodeFromString(""); } - }))()), ((((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>)(() => { + }))()), ((System.Func>)(() => { Std.Wrappers._IOption _source1 = (this).dtor_body; { if (_source1.is_None) { From b199b249f4eac85260644bf989abb09d2e9fa3ed Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 6 Dec 2024 03:06:27 +0100 Subject: [PATCH 21/69] Only negative downcasts remaining --- .../AST/TypeDeclarations/TraitDecl.cs | 2 + Source/DafnyCore/Backends/Dafny/AST.dfy | 19 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 44 +- .../Rust/Dafny-compiler-rust-definitions.dfy | 96 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 160 +- .../SinglePassCodeGenerator.cs | 56 +- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 166 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 2130 +++++++++-------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 40 +- .../DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 9 + .../DafnyRuntimeRust/src/tests/mod.rs | 117 +- 11 files changed, 1651 insertions(+), 1188 deletions(-) diff --git a/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs b/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs index eaf9a399c76..16af1a8a98f 100644 --- a/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs +++ b/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs @@ -9,6 +9,8 @@ public class TraitDecl : ClassLikeDecl { public bool IsParent { set; get; } public override bool AcceptThis => true; + [FilledInDuringResolution] public List ChildrenTraitDecl = new(); + internal void SetUpAsReferenceType(bool isReferenceType) { // Note, it's important to set .NonNullTypeDecl first, before calling NewSelfSynonym(), since the latter will look at the former. Contract.Assert(NonNullTypeDecl == null); // SetUpAsReferenceType should be called only once diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 66b18dbd8b1..ee8504ff5c6 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -157,6 +157,14 @@ module {:extern "DAST"} DAST { } } + predicate IsClassOrObjectTrait() { + match this { + case UserDefined(ResolvedType(_, _, base, _, _, _)) => + base.Class? || (base.Trait? && base.traitType.ObjectTrait?) + case _ => false + } + } + predicate IsDatatype() { match this { case UserDefined(ResolvedType(_, _, typeKind, _, _, _)) => @@ -414,6 +422,9 @@ module {:extern "DAST"} DAST { Submultiset() | ProperSubmultiset() | MultisetDisjoint() | Concat() | Passthrough(string) + + datatype SelectContext = + SelectContextDatatype | SelectContextGeneralTrait | SelectContextClassOrObjectTrait datatype Expression = Literal(Literal) | @@ -445,7 +456,7 @@ module {:extern "DAST"} DAST { MapKeys(expr: Expression) | MapValues(expr: Expression) | MapItems(expr: Expression) | - Select(expr: Expression, field: VarName, fieldMutability: FieldMutability, isDatatype: bool, fieldType: Type) | + Select(expr: Expression, field: VarName, fieldMutability: FieldMutability, selectContext: SelectContext, isfieldType: Type) | SelectFn(expr: Expression, field: VarName, onDatatype: bool, isStatic: bool, isConstant: bool, arguments: seq) | Index(expr: Expression, collKind: CollKind, indices: seq) | IndexRange(expr: Expression, isArray: bool, low: Option, high: Option) | @@ -466,7 +477,11 @@ module {:extern "DAST"} DAST { ExactBoundedPool(of: Expression) | IntRange(elemType: Type, lo: Expression, hi: Expression, up: bool) | UnboundedIntRange(start: Expression, up: bool) | - Quantifier(elemType: Type, collection: Expression, is_forall: bool, lambda: Expression) + Quantifier(elemType: Type, collection: Expression, is_forall: bool, lambda: Expression) { + predicate IsThisUpcast() { + Convert? && value.This? && from.Extends(typ) + } + } // Since constant fields need to be set up in the constructor, // accessing constant fields is done in two ways: diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 1e314fed9a5..07a1a327700 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -1976,6 +1976,13 @@ protected override void GetSpecialFieldInfo(SpecialField.ID id, object idParam, } } + _ISelectContext GetSelectContext(TopLevelDecl decl) { + return decl is DatatypeDecl or NewtypeDecl ? SelectContext.create_SelectContextDatatype() : + decl is TraitDecl { IsReferenceTypeDecl: false} ? + SelectContext.create_SelectContextGeneralTrait() : + SelectContext.create_SelectContextClassOrObjectTrait(); + } + protected override ILvalue EmitMemberSelect(Action obj, Type objType, MemberDecl member, List typeArgs, Dictionary typeMap, Type expectedType, string additionalCustomParameter = null, bool internalAccess = false) { @@ -2005,7 +2012,7 @@ protected override ILvalue EmitMemberSelect(Action obj, Type objExpr, Sequence.UnicodeFromString(compileName), FieldMutabilityOf(member), - member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) + GetSelectContext(member.EnclosingClass), GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)), @@ -2050,7 +2057,7 @@ member is ConstantField objExpr, Sequence.UnicodeFromString(compiledName), FieldMutabilityOf(member), - member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) + GetSelectContext(member.EnclosingClass), GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(compiledName), @@ -2083,7 +2090,7 @@ member is ConstantField objExpr, Sequence.UnicodeFromString(InternalFieldPrefix + member.GetCompileName(Options)), FieldMutabilityOf(member, isInternal: true), - member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) + GetSelectContext(member.EnclosingClass), GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(InternalFieldPrefix + member.GetCompileName(Options)), @@ -2094,7 +2101,7 @@ member is ConstantField objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)), FieldMutabilityOf(member), - member.EnclosingClass is DatatypeDecl or NewtypeDecl, GenType(expectedType) + GetSelectContext(member.EnclosingClass), GenType(expectedType) ), (DAST.AssignLhs)DAST.AssignLhs.create_Select( objExpr, Sequence.UnicodeFromString(member.GetCompileName(Options)), @@ -2376,7 +2383,7 @@ protected override void EmitDestructor(Action source, Formal sourceAST, Sequence.UnicodeFromString(compileName), new FieldMutability_InternalClassConstantFieldOrDatatypeDestructor(), - true, GenType(dtor.Type) + GetSelectContext(ctor.EnclosingDatatype), GenType(dtor.Type) )); } } @@ -2952,17 +2959,34 @@ protected override void EmitConstructorCheck(string source, DatatypeCtor ctor, C } protected override void EmitTypeTest(string localName, Type fromType, Type toType, IOrigin tok, ConcreteSyntaxTree wr) { + // This method needs to be implemented, but because we override EmitTypeTestExpr, it's never going to be called Still, we leave the body for completeness and maintenance. if (GetExprBuilder(wr, out var builder)) { - builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_Is( - DAST.Expression.create_Ident(Sequence.UnicodeFromString(localName)), - GenType(fromType), - GenType(toType) - )); + EmitTypeTestDAST(fromType, toType, builder, + (DAST.Expression)DAST.Expression.create_Ident(Sequence.UnicodeFromString(localName))); } else { throw new InvalidOperationException(); } } + protected override void EmitTypeTestExpr(Expression expr, Type fromType, Type toType, IOrigin tok, + bool inLetExprBody, ConcreteSyntaxTree wr, ref ConcreteSyntaxTree wStmts) { + if (GetExprConverter(wr, wStmts, out var builder, out var convert)) { + var exprDAST = convert(expr); + EmitTypeTestDAST(fromType, toType, builder, exprDAST); + } else { + throw new InvalidOperationException();//TODO + } + } + + private void EmitTypeTestDAST(Type fromType, Type toType, BuilderSyntaxTree builder, DAST.Expression exprDAST) + { + builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_Is( + exprDAST, + GenType(fromType), + GenType(toType) + )); + } + protected override void EmitIsIntegerTest(Expression source, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) { AddUnsupportedFeature(source.Tok, Feature.TypeTests); } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 90639ce2dcf..0539bed9712 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -291,6 +291,12 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { predicate IsSelf() { ThisTyped? && rSelfName == "self" } + predicate IsGeneralTrait() { + ThisTyped? && dafnyType.IsGeneralTrait() + } + predicate IsClassOrObjectTrait() { + ThisTyped? && dafnyType.IsClassOrObjectTrait() + } } datatype ExternAttribute = @@ -742,7 +748,7 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { R.NoDoc, R.NoAttr, R.PRIV, R.Fn( - "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.std.MSel("any").MSel("Any").AsType()))), + "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.AnyTrait))), Some(R.self))) function UnaryOpsImpl( @@ -855,7 +861,7 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { /* pub trait _Downcast_BDatatype { fn _is(&self) -> bool; - fn _as(&self) -> Rc>; + fn _as(&self) -> Rc> or ADatatype or Box; } */ function DowncastTraitDeclFor( rTypeParamsDecls: seq, @@ -889,40 +895,66 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { } /* - impl _Downcast_ADatatype for ADatatype { + impl _Downcast_TypeToDowncastTo for dyn Any { fn _is(&self) -> bool { - true + self.downcast_ref::().is_some() } - fn _as(&self) -> ADatatype { - self.clone() + fn _as(&self) -> TypeToDowncastTo { // Possibly wrapped with rc + self.downcast_ref::().unwrap().clone() // Optimization: Could be unwrap_unchecked } + } */ + function DowncastImplFor( + rTypeParamsDecls: seq, + datatypeType: R.Type + ): Option { + var downcast_type :- datatypeType.ToDowncast(); + var isRc := datatypeType.IsRc(); + var datatypeTypeRaw := if isRc then datatypeType.RcUnderlying() else datatypeType; + var isBody := + R.self.Sel("downcast_ref").ApplyType([datatypeTypeRaw]).Apply0().Sel("is_some").Apply0(); + var asBody := + R.self.Sel("downcast_ref").ApplyType([datatypeTypeRaw]).Apply0().Sel("unwrap").Apply0().Sel("clone").Apply0(); + var asBody := if isRc then R.RcNew(asBody) else asBody; + Some( + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + downcast_type, + R.DynType(R.AnyTrait), + [ R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn("_is", [], [R.Formal.selfBorrowed], Some(R.Bool), Some(isBody))), + R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn("_as", [], [R.Formal.selfBorrowed], Some(datatypeType), Some(asBody))) + ])) + ) } - impl _Downcast_BDatatype for ADatatype { + /* + impl _Downcast_SuperSubTrait for ADatatype { fn _is(&self) -> bool { - false + true } - fn _as(&self) -> Rc { - panic!("ADatatype is not a BDatatype") + fn _as(&self) -> Box { + Box::new(self.clone()) } - } */ - function DowncastImplFor( + } + */ + function DowncastImplTraitFor( rTypeParamsDecls: seq, - typeToDowncastTo: R.Type, - forType: R.Type + traitType: R.Type, + implementsTrait: bool, + datatypeType: R.Type ): Option { - var downcast_type :- typeToDowncastTo.ToDowncast(); - var forTypeRaw := if forType.IsRc() then forType.RcUnderlying() else forType; - var sameType := typeToDowncastTo == forType; - var asBody := - if sameType then - var body := R.self.Clone(); - if forType.IsRc() then - R.RcNew(body) - else - body - else - R.Identifier("panic!").Apply1(R.LiteralString(forTypeRaw.ToString("")+" is not a "+typeToDowncastTo.ToString(""), false, true)); + var downcast_type :- traitType.ToDowncast(); + var isRc := datatypeType.IsRc(); + var forType := if isRc then datatypeType.RcUnderlying() else datatypeType; + var resultType := traitType; + var isBody := R.LiteralBool(implementsTrait); + var asBody := R.BoxNew(R.self.Clone()); Some( R.ImplDecl( R.ImplFor( @@ -932,19 +964,11 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { [ R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, - R.Fn( - "_is", [], - [R.Formal.selfBorrowed], - Some(R.Bool), - Some(R.LiteralBool(sameType)))), + R.Fn("_is", [], [R.Formal.selfBorrowed], Some(R.Bool), Some(isBody))), R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, - R.Fn( - "_as", [], - [R.Formal.selfBorrowed], - Some(forType), - Some(asBody))) + R.Fn("_as", [], [R.Formal.selfBorrowed], Some(resultType), Some(asBody))) ])) ) } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 0e0ff93f396..eb312643a15 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -595,7 +595,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } implBodyImplementingOtherTraits := implBodyImplementingOtherTraits - {otherTrait}; } - var parents := []; + var parents: seq := []; var upcastImplemented := []; for i := 0 to |t.parents| { var parentTyp := t.parents[i]; @@ -610,30 +610,19 @@ module {:extern "DCOMP"} DafnyToRustCompiler { parents := parents + [parentTpe]; var upcastTrait := if parentTyp.IsGeneralTrait() then "UpcastBox" else Upcast; parents := parents + [R.dafny_runtime.MSel(upcastTrait).AsType().Apply1(R.DynType(parentTpe))]; - if parentTyp.IsGeneralTrait() { - /*impl UpcastBox for Box { - fn upcast(&self) -> ::std::boxed::Box { - GeneralTrait::::_clone(self.as_ref()) - } - }*/ - upcastImplemented := upcastImplemented + [ - R.ImplDecl( - R.ImplFor( - rTypeParamsDecls, - R.dafny_runtime.MSel("UpcastBox").AsType().Apply1(R.DynType(parentTpe)), - R.Box(R.DynType(traitFullType)), - [ R.FnDecl( - R.NoDoc, R.NoAttr, - R.PRIV, - R.Fn( - "upcast", - [], [R.Formal.selfBorrowed], - Some(R.Box(R.DynType(parentTpe))), - Some(parentTpeExpr.FSel("_clone").Apply1(R.self.Sel("as_ref").Apply0())) - ) - )])) - ]; + } + var downcastDefinition := []; + var instantiatedFullType := R.Box(R.DynType(traitFullType)); + if |t.parents| > 0 { // We will need to downcast + var downcastDefinitionOpt := DowncastTraitDeclFor(rTypeParamsDecls, instantiatedFullType); + if downcastDefinitionOpt.None? { + var dummy := Error("Could not generate downcast definition for " + instantiatedFullType.ToString("")); + } else { + downcastDefinition := [downcastDefinitionOpt.value]; } + } else if t.traitType.GeneralTrait? { + // Any top-most general trait must extend AnyRef so that we can perform downcasts to actual datatypes + parents := [R.dafny_runtime.MSel("AnyRef").AsType()] + parents; } s := [ R.TraitDecl( @@ -643,15 +632,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { parents, implBody ))]; - if |t.parents| > 0 { // We will need to downcast - var instantiatedFullType := R.Box(R.DynType(traitFullType)); - var downcastDefinitionOpt := DowncastTraitDeclFor(rTypeParamsDecls, instantiatedFullType); - if downcastDefinitionOpt.None? { - var dummy := Error("Could not generate downcast definition for " + instantiatedFullType.ToString("")); - } else { - s := s + [downcastDefinitionOpt.value]; - } - } + s := s + downcastDefinition; if t.traitType.GeneralTrait? { s := s + [ /*impl Clone for Box { @@ -1227,13 +1208,27 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } else { s := s + [downcastDefinitionOpt.value]; } - var downcastImplementationsOpt := DowncastImplFor(rTypeParamsDecls, fullType, fullType); + var downcastImplementationsOpt := DowncastImplFor(rTypeParamsDecls, fullType); if downcastImplementationsOpt.None? { var dummy := Error("Could not generate downcast implementation for " + fullType.ToString("")); - // TODO: Do all cousin types } else { s := s + [downcastImplementationsOpt.value]; } + for i := 0 to |c.superTraitTypes| { + var c := c.superTraitTypes[i]; + if c.UserDefined? && c.resolved.kind.Trait? && |c.resolved.extendedTypes| == 0 { + continue; // No need to generate this Downcast implementation + } + var cType := GenType(c, GenTypeContext.default()); + // TODO: Gather also all trait that traits know they extend but are not among the traits the datatype extends. + var isImplementing := true; + var downcastImplementationsOpt := DowncastImplTraitFor(rTypeParamsDecls, cType, isImplementing, fullType); + if downcastImplementationsOpt.None? { + var dummy := Error("Could not generate downcast implementation of "+cType.ToString("")+" for " + fullType.ToString("")); + } else { + s := s + [downcastImplementationsOpt.value]; + } + } } var printImplBodyCases: seq := []; @@ -2095,9 +2090,16 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // General traits borrow their self, from a Box // The underlying type is a Box, self: Datatype or Rc // 'on' is going to return an owned version of this box. - onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); - onExpr := FromGeneralBorrowToSelfBorrow(onExpr, recOwnership, env); - readIdents := readIdents + recIdents; + + /*if on.IsThisUpcast() { + // Special case, in Rust, we don't need to upcast "self" because upcasted methods are automatically available + onExpr := R.self; // Already self borrow + readIdents := readIdents + {"self"}; + } else {*/ + onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); + onExpr := FromGeneralBorrowToSelfBorrow(onExpr, recOwnership, env); + readIdents := readIdents + recIdents; + //} } else if base.Newtype? && IsNewtypeCopy(base.range) { // The self type of a newtype that is copy is also copy onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); @@ -2109,7 +2111,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } r := fullPath.ApplyType(onTypeExprs).FSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); case _ => // Infix call on.name(args) or Companion::name(args) - var onExpr, _, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); + var onExpr, recIdents, dummy; + /*if on.IsThisUpcast() { + // Special case, in Rust, we don't need to upcast "self" because upcasted methods are automatically available + onExpr := R.self; // Already self borrow + recIdents := {"self"}; + } else {*/ + onExpr, dummy, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); + //} readIdents := readIdents + recIdents; var renderedName := GetMethodName(on, name); // Pointers in the role of "self" must be converted to borrowed versions. @@ -3075,7 +3084,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { underlying else underlying.Clone() // Auto-borrow allows for implicit code - case _ => expr.Clone() + case _ => + expr.Clone() } method GenExprConvertOther( @@ -3119,7 +3129,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } } - newExpr := FromGeneralBorrowToSelfBorrow(expr, OwnershipBorrowed, env); + newExpr := FromGeneralBorrowToSelfBorrow(newExpr, OwnershipBorrowed, env); + if isDatatype { + newExpr := R.dafny_runtime.MSel("AnyRef").AsExpr().FSel("as_any_ref").Apply1(newExpr); + } r := toTpeRawDowncastOpt.value.FSel("_as").Apply1(newExpr); r, resultingOwnership := FromOwnership(r, OwnershipOwned, expectedOwnership); return; @@ -3138,8 +3151,20 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if upcastConverter.Success? { var conversionLambda := upcastConverter.value; if exprOwnership == OwnershipBorrowed { - // we need the value to be owned for conversion - r := BorrowedToOwned(r, env); + if fromTyp.IsGeneralTrait() && r == R.Identifier("self") { + // The self in this case does not implement the clone method, we need to call _clone from the trait + // Similar to the code at the end of GenIdent() + var traitType := GenType(fromTyp, GenTypeContext.ForTraitParents()); + var traitExpr := traitType.ToExpr(); + if traitExpr.None? { + r := Error("Could not convert " + traitType.ToString("") + " to an expression"); + } else { + r := traitExpr.value.FSel("_clone").Apply1(r); + } + } else { + // we need the value to be owned for conversion + r := BorrowedToOwned(r, env); + } } r := conversionLambda.Apply1(r); r, resultingOwnership := FromOwnership(r, OwnershipOwned, expectedOwnership); @@ -3217,18 +3242,25 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } resultingOwnership := OwnershipBorrowedMut; } else if expectedOwnership == OwnershipOwned { - var needObjectFromRef := - isSelf && - match selfIdent.dafnyType { - case UserDefined(ResolvedType(_, _, base, attributes, _, _)) => - base.Class? || (base.Trait? && base.traitType.ObjectTrait?) - case _ => false - }; + var needObjectFromRef := isSelf && selfIdent.IsClassOrObjectTrait(); if needObjectFromRef { r := R.dafny_runtime.MSel("Object").AsExpr().ApplyType([R.TIdentifier("_")]).FSel("from_ref").Apply([r]); } else { if !noNeedOfClone { - r := r.Clone(); // We don't transfer the ownership of an identifier + var needUnderscoreClone := isSelf && selfIdent.IsGeneralTrait(); + if needUnderscoreClone { + // In the case when self: &Self and self is a general trait, self.Clone() == self so it's useless. + // What we need is to build self._clone(), and since _clone() can be ambiguous, we need the full trait type instead. + var traitType := GenType(selfIdent.dafnyType, GenTypeContext.ForTraitParents()); + var traitExpr := traitType.ToExpr(); + if traitExpr.None? { + r := Error("Could not convert " + traitType.ToString("") + " to an expression"); + } else { + r := traitExpr.value.FSel("_clone").Apply1(r); + } + } else { + r := r.Clone(); // We don't transfer the ownership of an identifier + } } } resultingOwnership := OwnershipOwned; @@ -3836,7 +3868,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := recIdents; return; } - case Select(on, field, fieldMutability, isDatatype, fieldType) => { + case Select(on, field, fieldMutability, selectContext, fieldType) => { if on.Companion? || on.ExternCompanion? { var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); @@ -3846,7 +3878,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; return; - } else if isDatatype { + } else if selectContext.SelectContextDatatype? { var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); // onExpr.field() r := onExpr.Sel(escapeVar(field)).Apply0(); @@ -3862,6 +3894,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // All fields are returned as addresses for now until we have something more clever r, resultingOwnership := FromOwnership(r, originalMutability, expectedOwnership); readIdents := recIdents; + } else if selectContext.SelectContextGeneralTrait? { + var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); + r := onExpr; + if onExpr != R.self { + r := R.std.MSel("convert").MSel("AsRef").AsExpr().FSel("as_ref").Apply1(r); + } + r := r.Sel(escapeVar(field)).Apply0(); + r, resultingOwnership := FromOwned(r, expectedOwnership); + readIdents := recIdents; } else { var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); r := onExpr; @@ -4111,12 +4152,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case Is(expr, fromTyp, toTyp) => { - var expr, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); var fromTpe := GenType(fromTyp, GenTypeContext.default()); var toTpe := GenType(toTyp, GenTypeContext.default()); if fromTpe.IsObjectOrPointer() && toTpe.IsObjectOrPointer() { + var expr, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipOwned); r := expr.Sel("is_instance_of").ApplyType([toTpe.ObjectOrPointerUnderlying()]).Apply0(); + r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); + readIdents := recIdents; } else { + var expr, recOwned, recIdents := GenExpr(expr, selfIdent, env, OwnershipBorrowed); var isDatatype := toTyp.IsDatatype(); var isGeneralTrait := !isDatatype && toTyp.IsGeneralTrait(); if isDatatype || isGeneralTrait { // TODO: Detect downcast/upcast @@ -4126,6 +4170,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var toTpeRaw := GenType(underlyingType, GenTypeContext.default()); var toTpeRawDowncastOpt: Option := toTpeRaw.ToDowncastExpr(); if toTpeRawDowncastOpt.Some? { + expr := FromGeneralBorrowToSelfBorrow(expr, OwnershipBorrowed, env); + if isDatatype { + expr := R.dafny_runtime.MSel("AnyRef").AsExpr().FSel("as_any_ref").Apply1(expr); + } r := toTpeRawDowncastOpt.value.FSel("_is").Apply1(expr); recOwned := OwnershipOwned(); } else { @@ -4137,9 +4185,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } else { r := Error("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"); } + r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); + readIdents := recIdents; } - r, resultingOwnership := FromOwnership(r, recOwned, expectedOwnership); - readIdents := recIdents; return; } case BoolBoundedPool() => { diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index d4c1b5bd1a9..8c5011bc01f 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -1439,6 +1439,14 @@ protected virtual void CompileBinOp(BinaryExpr.ResolvedOpcode op, /// protected abstract void EmitTypeTest(string localName, Type fromType, Type toType, IOrigin tok, ConcreteSyntaxTree wr); + + protected virtual void EmitTypeTestExpr(Expression expr, Type fromType, Type toType, IOrigin tok, + bool inLetExprBody, ConcreteSyntaxTree wr, ref ConcreteSyntaxTree wStmts) { + var name = $"_is_{GetUniqueAstNumber(expr)}"; + wr = CreateIIFE_ExprBody(name, fromType, tok, expr, inLetExprBody, Type.Bool, expr.tok, wr, ref wStmts); + EmitTypeTest(name, fromType, toType, tok, wr); + } + /// /// Emit a conjunct that tests if the Dafny real number "source" is an integer, like: /// "TestIsInteger(source) && " @@ -2170,25 +2178,29 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite } else if (c is TraitDecl) { RedeclareInheritedMember(member, classWriter); } else if (member is ConstantField) { - var cf = (ConstantField)member; - var cfType = cf.Type.Subst(c.ParentFormalTypeParametersToActuals); - if (cf.Rhs == null && c is ClassLikeDecl) { - // create a backing field, since this constant field may be assigned in constructors - Contract.Assert(!cf.IsStatic); // as checked above, only instance members can be inherited - classWriter.DeclareField(InternalFieldPrefix + cf.GetCompileName(Options), c, false, false, cfType, cf.tok, PlaceboValue(cfType, errorWr, cf.tok, true), cf); - } - var w = CreateFunctionOrGetter(cf, IdName(cf), c, false, true, true, classWriter); - Contract.Assert(w != null); // since the previous line asked for a body - if (cf.Rhs != null) { - EmitCallToInheritedConstRHS(cf, w); - } else if (!cf.IsStatic && c is ClassLikeDecl) { - var sw = EmitReturnExpr(w); - sw = EmitCoercionIfNecessary(cfType, cf.Type, cf.tok, sw); - // get { return this._{0}; } - EmitThis(sw); - sw.Write(".{0}{1}", InternalFieldPrefix, cf.GetCompileName(Options)); - } else { - EmitReturnExpr(PlaceboValue(cfType, errorWr, cf.tok, true), w); + if (canRedeclareMemberDefinedInTrait) { + var cf = (ConstantField)member; + var cfType = cf.Type.Subst(c.ParentFormalTypeParametersToActuals); + if (cf.Rhs == null && c is ClassLikeDecl) { + // create a backing field, since this constant field may be assigned in constructors + Contract.Assert(!cf.IsStatic); // as checked above, only instance members can be inherited + classWriter.DeclareField(InternalFieldPrefix + cf.GetCompileName(Options), c, false, false, cfType, + cf.tok, PlaceboValue(cfType, errorWr, cf.tok, true), cf); + } + + var w = CreateFunctionOrGetter(cf, IdName(cf), c, false, true, true, classWriter); + Contract.Assert(w != null); // since the previous line asked for a body + if (cf.Rhs != null) { + EmitCallToInheritedConstRHS(cf, w); + } else if (!cf.IsStatic && c is ClassLikeDecl) { + var sw = EmitReturnExpr(w); + sw = EmitCoercionIfNecessary(cfType, cf.Type, cf.tok, sw); + // get { return this._{0}; } + EmitThis(sw); + sw.Write(".{0}{1}", InternalFieldPrefix, cf.GetCompileName(Options)); + } else { + EmitReturnExpr(PlaceboValue(cfType, errorWr, cf.tok, true), w); + } } } else if (member is Field f) { var fType = f.Type.Subst(c.ParentFormalTypeParametersToActuals); @@ -2280,7 +2292,7 @@ void CompileClassMembers(Program program, TopLevelDeclWithMembers c, IClassWrite // that takes a parameter, because trait-equivalents in target languages don't allow implementations. wBody = classWriter.CreateFunction(IdName(cf), CombineAllTypeArguments(cf), new List(), cf.Type, cf.tok, InstanceConstAreStatic(), true, cf, false, true); Contract.Assert(wBody != null); // since the previous line asked for a body - if (c is TraitDecl) { + if (c is TraitDecl && !InstanceMethodsCanOnlyCallOverridenTraitMethods) { // also declare a function for the field in the interface var wBodyInterface = CreateFunctionOrGetter(cf, IdName(cf), c, false, false, false, classWriter); Contract.Assert(wBodyInterface == null); // since the previous line said not to create a body @@ -4850,9 +4862,7 @@ private void CompileTypeTest(TypeTestExpr expr, bool inLetExprBody, ConcreteSynt // Notes: // - The constraint of a non-null reference type can be omitted in some cases, see note (c) above. if (fromType.IsTraitType || fromType.IsRefType) { - var name = $"_is_{GetUniqueAstNumber(expr)}"; - wr = CreateIIFE_ExprBody(name, fromType, expr.tok, expr.E, inLetExprBody, Type.Bool, expr.tok, wr, ref wStmts); - EmitTypeTest(name, fromType, expr.ToType, expr.tok, wr); + EmitTypeTestExpr(expr.E, fromType, expr.ToType, expr.tok, inLetExprBody, wr, ref wStmts); return; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 245a374a006..7a1fe477045 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -572,6 +572,7 @@ public interface _IType { bool IsPrimitiveInt(); bool IsGeneralTrait(); DAST._IType GetGeneralTraitType(); + bool IsClassOrObjectTrait(); bool IsDatatype(); DAST._IType GetDatatypeType(); bool Extends(DAST._IType other); @@ -880,6 +881,19 @@ public DAST._IType GetGeneralTraitType() { } } } + public bool IsClassOrObjectTrait() { + DAST._IType _source0 = this; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase _0_base = resolved0.dtor_kind; + return ((_0_base).is_Class) || (((_0_base).is_Trait) && (((_0_base).dtor_traitType).is_ObjectTrait)); + } + } + { + return false; + } + } public bool IsDatatype() { _IType _this = this; TAIL_CALL_START: ; @@ -6458,6 +6472,108 @@ public override string ToString() { } } + public interface _ISelectContext { + bool is_SelectContextDatatype { get; } + bool is_SelectContextGeneralTrait { get; } + bool is_SelectContextClassOrObjectTrait { get; } + _ISelectContext DowncastClone(); + } + public abstract class SelectContext : _ISelectContext { + public SelectContext() { + } + private static readonly DAST._ISelectContext theDefault = create_SelectContextDatatype(); + public static DAST._ISelectContext Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.SelectContext.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _ISelectContext create_SelectContextDatatype() { + return new SelectContext_SelectContextDatatype(); + } + public static _ISelectContext create_SelectContextGeneralTrait() { + return new SelectContext_SelectContextGeneralTrait(); + } + public static _ISelectContext create_SelectContextClassOrObjectTrait() { + return new SelectContext_SelectContextClassOrObjectTrait(); + } + public bool is_SelectContextDatatype { get { return this is SelectContext_SelectContextDatatype; } } + public bool is_SelectContextGeneralTrait { get { return this is SelectContext_SelectContextGeneralTrait; } } + public bool is_SelectContextClassOrObjectTrait { get { return this is SelectContext_SelectContextClassOrObjectTrait; } } + public static System.Collections.Generic.IEnumerable<_ISelectContext> AllSingletonConstructors { + get { + yield return SelectContext.create_SelectContextDatatype(); + yield return SelectContext.create_SelectContextGeneralTrait(); + yield return SelectContext.create_SelectContextClassOrObjectTrait(); + } + } + public abstract _ISelectContext DowncastClone(); + } + public class SelectContext_SelectContextDatatype : SelectContext { + public SelectContext_SelectContextDatatype() : base() { + } + public override _ISelectContext DowncastClone() { + if (this is _ISelectContext dt) { return dt; } + return new SelectContext_SelectContextDatatype(); + } + public override bool Equals(object other) { + var oth = other as DAST.SelectContext_SelectContextDatatype; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + return (int) hash; + } + public override string ToString() { + string s = "DAST.SelectContext.SelectContextDatatype"; + return s; + } + } + public class SelectContext_SelectContextGeneralTrait : SelectContext { + public SelectContext_SelectContextGeneralTrait() : base() { + } + public override _ISelectContext DowncastClone() { + if (this is _ISelectContext dt) { return dt; } + return new SelectContext_SelectContextGeneralTrait(); + } + public override bool Equals(object other) { + var oth = other as DAST.SelectContext_SelectContextGeneralTrait; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + return (int) hash; + } + public override string ToString() { + string s = "DAST.SelectContext.SelectContextGeneralTrait"; + return s; + } + } + public class SelectContext_SelectContextClassOrObjectTrait : SelectContext { + public SelectContext_SelectContextClassOrObjectTrait() : base() { + } + public override _ISelectContext DowncastClone() { + if (this is _ISelectContext dt) { return dt; } + return new SelectContext_SelectContextClassOrObjectTrait(); + } + public override bool Equals(object other) { + var oth = other as DAST.SelectContext_SelectContextClassOrObjectTrait; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 2; + return (int) hash; + } + public override string ToString() { + string s = "DAST.SelectContext.SelectContextClassOrObjectTrait"; + return s; + } + } + public interface _IExpression { bool is_Literal { get; } bool is_Ident { get; } @@ -6550,8 +6666,8 @@ public interface _IExpression { bool dtor_native { get; } Dafny.ISequence dtor_field { get; } DAST._IFieldMutability dtor_fieldMutability { get; } - bool dtor_isDatatype { get; } - DAST._IType dtor_fieldType { get; } + DAST._ISelectContext dtor_selectContext { get; } + DAST._IType dtor_isfieldType { get; } bool dtor_onDatatype { get; } bool dtor_isStatic { get; } bool dtor_isConstant { get; } @@ -6562,6 +6678,7 @@ public interface _IExpression { Std.Wrappers._IOption dtor_low { get; } Std.Wrappers._IOption dtor_high { get; } BigInteger dtor_index { get; } + DAST._IType dtor_fieldType { get; } DAST._IExpression dtor_on { get; } DAST._ICallName dtor_callName { get; } Dafny.ISequence dtor_params { get; } @@ -6583,6 +6700,7 @@ public interface _IExpression { bool dtor_is__forall { get; } DAST._IExpression dtor_lambda { get; } _IExpression DowncastClone(); + bool IsThisUpcast(); } public abstract class Expression : _IExpression { public Expression() { @@ -6682,8 +6800,8 @@ public static _IExpression create_MapValues(DAST._IExpression expr) { public static _IExpression create_MapItems(DAST._IExpression expr) { return new Expression_MapItems(expr); } - public static _IExpression create_Select(DAST._IExpression expr, Dafny.ISequence field, DAST._IFieldMutability fieldMutability, bool isDatatype, DAST._IType fieldType) { - return new Expression_Select(expr, field, fieldMutability, isDatatype, fieldType); + public static _IExpression create_Select(DAST._IExpression expr, Dafny.ISequence field, DAST._IFieldMutability fieldMutability, DAST._ISelectContext selectContext, DAST._IType isfieldType) { + return new Expression_Select(expr, field, fieldMutability, selectContext, isfieldType); } public static _IExpression create_SelectFn(DAST._IExpression expr, Dafny.ISequence field, bool onDatatype, bool isStatic, bool isConstant, Dafny.ISequence arguments) { return new Expression_SelectFn(expr, field, onDatatype, isStatic, isConstant, arguments); @@ -7075,17 +7193,16 @@ public DAST._IFieldMutability dtor_fieldMutability { return ((Expression_Select)d)._fieldMutability; } } - public bool dtor_isDatatype { + public DAST._ISelectContext dtor_selectContext { get { var d = this; - return ((Expression_Select)d)._isDatatype; + return ((Expression_Select)d)._selectContext; } } - public DAST._IType dtor_fieldType { + public DAST._IType dtor_isfieldType { get { var d = this; - if (d is Expression_Select) { return ((Expression_Select)d)._fieldType; } - return ((Expression_TupleSelect)d)._fieldType; + return ((Expression_Select)d)._isfieldType; } } public bool dtor_onDatatype { @@ -7148,6 +7265,12 @@ public BigInteger dtor_index { return ((Expression_TupleSelect)d)._index; } } + public DAST._IType dtor_fieldType { + get { + var d = this; + return ((Expression_TupleSelect)d)._fieldType; + } + } public DAST._IExpression dtor_on { get { var d = this; @@ -7277,6 +7400,9 @@ public DAST._IExpression dtor_lambda { } } public abstract _IExpression DowncastClone(); + public bool IsThisUpcast() { + return (((this).is_Convert) && (((this).dtor_value).is_This)) && (((this).dtor_from).Extends((this).dtor_typ)); + } } public class Expression_Literal : Expression { public readonly DAST._ILiteral _a0; @@ -8199,22 +8325,22 @@ public class Expression_Select : Expression { public readonly DAST._IExpression _expr; public readonly Dafny.ISequence _field; public readonly DAST._IFieldMutability _fieldMutability; - public readonly bool _isDatatype; - public readonly DAST._IType _fieldType; - public Expression_Select(DAST._IExpression expr, Dafny.ISequence field, DAST._IFieldMutability fieldMutability, bool isDatatype, DAST._IType fieldType) : base() { + public readonly DAST._ISelectContext _selectContext; + public readonly DAST._IType _isfieldType; + public Expression_Select(DAST._IExpression expr, Dafny.ISequence field, DAST._IFieldMutability fieldMutability, DAST._ISelectContext selectContext, DAST._IType isfieldType) : base() { this._expr = expr; this._field = field; this._fieldMutability = fieldMutability; - this._isDatatype = isDatatype; - this._fieldType = fieldType; + this._selectContext = selectContext; + this._isfieldType = isfieldType; } public override _IExpression DowncastClone() { if (this is _IExpression dt) { return dt; } - return new Expression_Select(_expr, _field, _fieldMutability, _isDatatype, _fieldType); + return new Expression_Select(_expr, _field, _fieldMutability, _selectContext, _isfieldType); } public override bool Equals(object other) { var oth = other as DAST.Expression_Select; - return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._field, oth._field) && object.Equals(this._fieldMutability, oth._fieldMutability) && this._isDatatype == oth._isDatatype && object.Equals(this._fieldType, oth._fieldType); + return oth != null && object.Equals(this._expr, oth._expr) && object.Equals(this._field, oth._field) && object.Equals(this._fieldMutability, oth._fieldMutability) && object.Equals(this._selectContext, oth._selectContext) && object.Equals(this._isfieldType, oth._isfieldType); } public override int GetHashCode() { ulong hash = 5381; @@ -8222,8 +8348,8 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._expr)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._field)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fieldMutability)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isDatatype)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._fieldType)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._selectContext)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isfieldType)); return (int) hash; } public override string ToString() { @@ -8235,9 +8361,9 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._fieldMutability); s += ", "; - s += Dafny.Helpers.ToString(this._isDatatype); + s += Dafny.Helpers.ToString(this._selectContext); s += ", "; - s += Dafny.Helpers.ToString(this._fieldType); + s += Dafny.Helpers.ToString(this._isfieldType); s += ")"; return s; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 3311de84d33..dcf9a60021b 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -599,25 +599,27 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _24_upcastTrait = (this).Upcast; } _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_24_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_21_parentTpe)))); - if ((_20_parentTyp).IsGeneralTrait()) { - _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply1(RAST.Type.create_DynType(_21_parentTpe)), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_21_parentTpe))), Std.Wrappers.Option.create_Some(((_23_parentTpeExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))))); - } } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create((t).dtor_docString, Dafny.Sequence>.FromElements(), _1_rTypeParamsDecls, _10_traitFullType, _17_parents, _12_implBody))); + Dafny.ISequence _25_downcastDefinition; + _25_downcastDefinition = Dafny.Sequence.FromElements(); + RAST._IType _26_instantiatedFullType; + _26_instantiatedFullType = RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)); if ((new BigInteger(((t).dtor_parents).Count)).Sign == 1) { - RAST._IType _25_instantiatedFullType; - _25_instantiatedFullType = RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)); - Std.Wrappers._IOption _26_downcastDefinitionOpt; - _26_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_1_rTypeParamsDecls, _25_instantiatedFullType); - if ((_26_downcastDefinitionOpt).is_None) { - RAST._IExpr _27_dummy; + Std.Wrappers._IOption _27_downcastDefinitionOpt; + _27_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_1_rTypeParamsDecls, _26_instantiatedFullType); + if ((_27_downcastDefinitionOpt).is_None) { + RAST._IExpr _28_dummy; RAST._IExpr _out7; - _out7 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_25_instantiatedFullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _27_dummy = _out7; + _out7 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_26_instantiatedFullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _28_dummy = _out7; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_26_downcastDefinitionOpt).dtor_value)); + _25_downcastDefinition = Dafny.Sequence.FromElements((_27_downcastDefinitionOpt).dtor_value); } + } else if (((t).dtor_traitType).is_GeneralTrait) { + _17_parents = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsType()), _17_parents); } + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create((t).dtor_docString, Dafny.Sequence>.FromElements(), _1_rTypeParamsDecls, _10_traitFullType, _17_parents, _12_implBody))); + s = Dafny.Sequence.Concat(s, _25_downcastDefinition); if (((t).dtor_traitType).is_GeneralTrait) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialEq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_eq"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Eq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.Hash, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_hash"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))))))))); } @@ -1182,7 +1184,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_71_downcastDefinitionOpt).dtor_value)); } Std.Wrappers._IOption _73_downcastImplementationsOpt; - _73_downcastImplementationsOpt = Defs.__default.DowncastImplFor(_3_rTypeParamsDecls, _70_fullType, _70_fullType); + _73_downcastImplementationsOpt = Defs.__default.DowncastImplFor(_3_rTypeParamsDecls, _70_fullType); if ((_73_downcastImplementationsOpt).is_None) { RAST._IExpr _74_dummy; RAST._IExpr _out16; @@ -1191,159 +1193,185 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } else { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_73_downcastImplementationsOpt).dtor_value)); } - } - Dafny.ISequence _75_printImplBodyCases; - _75_printImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _76_hashImplBodyCases; - _76_hashImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _77_coerceImplBodyCases; - _77_coerceImplBodyCases = Dafny.Sequence.FromElements(); - BigInteger _hi7 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _78_i = BigInteger.Zero; _78_i < _hi7; _78_i++) { - DAST._IDatatypeCtor _79_ctor; - _79_ctor = ((c).dtor_ctors).Select(_78_i); - Dafny.ISequence _80_ctorMatch; - _80_ctorMatch = Defs.__default.escapeName((_79_ctor).dtor_name); - Dafny.ISequence _81_modulePrefix; + BigInteger _hi7 = new BigInteger(((c).dtor_superTraitTypes).Count); + for (BigInteger _75_i = BigInteger.Zero; _75_i < _hi7; _75_i++) { + DAST._IType _76_c; + _76_c = ((c).dtor_superTraitTypes).Select(_75_i); + if ((((_76_c).is_UserDefined) && ((((_76_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_76_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { + goto continue_3_0; + } + RAST._IType _77_cType; + RAST._IType _out17; + _out17 = (this).GenType(_76_c, Defs.GenTypeContext.@default()); + _77_cType = _out17; + bool _78_isImplementing; + _78_isImplementing = true; + Std.Wrappers._IOption _79_downcastImplementationsOpt; + _79_downcastImplementationsOpt = Defs.__default.DowncastImplTraitFor(_3_rTypeParamsDecls, _77_cType, _78_isImplementing, _70_fullType); + if ((_79_downcastImplementationsOpt).is_None) { + RAST._IExpr _80_dummy; + RAST._IExpr _out18; + _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation of "), (_77_cType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" for ")), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _80_dummy = _out18; + } else { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_79_downcastImplementationsOpt).dtor_value)); + } + continue_3_0: ; + } + after_3_0: ; + } + Dafny.ISequence _81_printImplBodyCases; + _81_printImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _82_hashImplBodyCases; + _82_hashImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _83_coerceImplBodyCases; + _83_coerceImplBodyCases = Dafny.Sequence.FromElements(); + BigInteger _hi8 = new BigInteger(((c).dtor_ctors).Count); + for (BigInteger _84_i = BigInteger.Zero; _84_i < _hi8; _84_i++) { + DAST._IDatatypeCtor _85_ctor; + _85_ctor = ((c).dtor_ctors).Select(_84_i); + Dafny.ISequence _86_ctorMatch; + _86_ctorMatch = Defs.__default.escapeName((_85_ctor).dtor_name); + Dafny.ISequence _87_modulePrefix; if (((((c).dtor_enclosingModule))).Equals(Dafny.Sequence.UnicodeFromString("_module"))) { - _81_modulePrefix = Dafny.Sequence.UnicodeFromString(""); + _87_modulePrefix = Dafny.Sequence.UnicodeFromString(""); } else { - _81_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); - } - Dafny.ISequence _82_ctorName; - _82_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_81_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_79_ctor).dtor_name)); - if (((new BigInteger((_82_ctorName).Count)) >= (new BigInteger(13))) && (((_82_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { - _82_ctorName = Dafny.Sequence.UnicodeFromString(""); - } - RAST._IExpr _83_printRhs; - _83_printRhs = (this).writeStr(Dafny.Sequence.Concat(_82_ctorName, (((_79_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); - RAST._IExpr _84_hashRhs; - _84_hashRhs = (this).InitEmptyExpr(); - Dafny.ISequence _85_coerceRhsArgs; - _85_coerceRhsArgs = Dafny.Sequence.FromElements(); - bool _86_isNumeric; - _86_isNumeric = false; - Dafny.ISequence _87_ctorMatchInner; - _87_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); - BigInteger _hi8 = new BigInteger(((_79_ctor).dtor_args).Count); - for (BigInteger _88_j = BigInteger.Zero; _88_j < _hi8; _88_j++) { - DAST._IDatatypeDtor _89_dtor; - _89_dtor = ((_79_ctor).dtor_args).Select(_88_j); - Dafny.ISequence _90_patternName; - _90_patternName = Defs.__default.escapeVar(((_89_dtor).dtor_formal).dtor_name); - DAST._IType _91_formalType; - _91_formalType = ((_89_dtor).dtor_formal).dtor_typ; - if (((_88_j).Sign == 0) && ((_90_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _86_isNumeric = true; - } - if (_86_isNumeric) { - _90_patternName = Std.Wrappers.Option>.GetOr((_89_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_88_j))); - } - if ((_91_formalType).is_Arrow) { - _84_hashRhs = (_84_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + _87_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); + } + Dafny.ISequence _88_ctorName; + _88_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_87_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_85_ctor).dtor_name)); + if (((new BigInteger((_88_ctorName).Count)) >= (new BigInteger(13))) && (((_88_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { + _88_ctorName = Dafny.Sequence.UnicodeFromString(""); + } + RAST._IExpr _89_printRhs; + _89_printRhs = (this).writeStr(Dafny.Sequence.Concat(_88_ctorName, (((_85_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); + RAST._IExpr _90_hashRhs; + _90_hashRhs = (this).InitEmptyExpr(); + Dafny.ISequence _91_coerceRhsArgs; + _91_coerceRhsArgs = Dafny.Sequence.FromElements(); + bool _92_isNumeric; + _92_isNumeric = false; + Dafny.ISequence _93_ctorMatchInner; + _93_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); + BigInteger _hi9 = new BigInteger(((_85_ctor).dtor_args).Count); + for (BigInteger _94_j = BigInteger.Zero; _94_j < _hi9; _94_j++) { + DAST._IDatatypeDtor _95_dtor; + _95_dtor = ((_85_ctor).dtor_args).Select(_94_j); + Dafny.ISequence _96_patternName; + _96_patternName = Defs.__default.escapeVar(((_95_dtor).dtor_formal).dtor_name); + DAST._IType _97_formalType; + _97_formalType = ((_95_dtor).dtor_formal).dtor_typ; + if (((_94_j).Sign == 0) && ((_96_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _92_isNumeric = true; + } + if (_92_isNumeric) { + _96_patternName = Std.Wrappers.Option>.GetOr((_95_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_94_j))); + } + if ((_97_formalType).is_Arrow) { + _90_hashRhs = (_90_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); } else { - _84_hashRhs = (_84_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_90_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); - } - _87_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_87_ctorMatchInner, _90_patternName), Dafny.Sequence.UnicodeFromString(", ")); - if ((_88_j).Sign == 1) { - _83_printRhs = (_83_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); - } - _83_printRhs = (_83_printRhs).Then((((_91_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_90_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); - RAST._IExpr _92_coerceRhsArg = RAST.Expr.Default(); - RAST._IType _93_formalTpe; - RAST._IType _out17; - _out17 = (this).GenType(_91_formalType, Defs.GenTypeContext.@default()); - _93_formalTpe = _out17; - DAST._IType _94_newFormalType; - _94_newFormalType = (_91_formalType).Replace(_51_coerceMap); - RAST._IType _95_newFormalTpe; - _95_newFormalTpe = (_93_formalTpe).ReplaceMap(_52_rCoerceMap); - Std.Wrappers._IResult,RAST._IExpr>>> _96_upcastConverter; - _96_upcastConverter = (this).UpcastConversionLambda(_91_formalType, _93_formalTpe, _94_newFormalType, _95_newFormalTpe, _53_coerceMapToArg); - if ((_96_upcastConverter).is_Success) { - RAST._IExpr _97_coercionFunction; - _97_coercionFunction = (_96_upcastConverter).dtor_value; - _92_coerceRhsArg = (_97_coercionFunction).Apply1(RAST.Expr.create_Identifier(_90_patternName)); + _90_hashRhs = (_90_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_96_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); + } + _93_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatchInner, _96_patternName), Dafny.Sequence.UnicodeFromString(", ")); + if ((_94_j).Sign == 1) { + _89_printRhs = (_89_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); + } + _89_printRhs = (_89_printRhs).Then((((_97_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_96_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); + RAST._IExpr _98_coerceRhsArg = RAST.Expr.Default(); + RAST._IType _99_formalTpe; + RAST._IType _out19; + _out19 = (this).GenType(_97_formalType, Defs.GenTypeContext.@default()); + _99_formalTpe = _out19; + DAST._IType _100_newFormalType; + _100_newFormalType = (_97_formalType).Replace(_51_coerceMap); + RAST._IType _101_newFormalTpe; + _101_newFormalTpe = (_99_formalTpe).ReplaceMap(_52_rCoerceMap); + Std.Wrappers._IResult,RAST._IExpr>>> _102_upcastConverter; + _102_upcastConverter = (this).UpcastConversionLambda(_97_formalType, _99_formalTpe, _100_newFormalType, _101_newFormalTpe, _53_coerceMapToArg); + if ((_102_upcastConverter).is_Success) { + RAST._IExpr _103_coercionFunction; + _103_coercionFunction = (_102_upcastConverter).dtor_value; + _98_coerceRhsArg = (_103_coercionFunction).Apply1(RAST.Expr.create_Identifier(_96_patternName)); } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_88_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); - _92_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_94_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); + _98_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); } - _85_coerceRhsArgs = Dafny.Sequence.Concat(_85_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_90_patternName, _92_coerceRhsArg))); + _91_coerceRhsArgs = Dafny.Sequence.Concat(_91_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_96_patternName, _98_coerceRhsArg))); } - RAST._IExpr _98_coerceRhs; - _98_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_79_ctor).dtor_name)), _85_coerceRhsArgs); - if (_86_isNumeric) { - _80_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_80_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _87_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + RAST._IExpr _104_coerceRhs; + _104_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_85_ctor).dtor_name)), _91_coerceRhsArgs); + if (_92_isNumeric) { + _86_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_86_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _93_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); } else { - _80_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_80_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _87_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + _86_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_86_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _93_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); } - if ((_79_ctor).dtor_hasAnyArgs) { - _83_printRhs = (_83_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); + if ((_85_ctor).dtor_hasAnyArgs) { + _89_printRhs = (_89_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); } - _83_printRhs = (_83_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); - _75_printImplBodyCases = Dafny.Sequence.Concat(_75_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _80_ctorMatch), RAST.Expr.create_Block(_83_printRhs)))); - _76_hashImplBodyCases = Dafny.Sequence.Concat(_76_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _80_ctorMatch), RAST.Expr.create_Block(_84_hashRhs)))); - _77_coerceImplBodyCases = Dafny.Sequence.Concat(_77_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _80_ctorMatch), RAST.Expr.create_Block(_98_coerceRhs)))); + _89_printRhs = (_89_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); + _81_printImplBodyCases = Dafny.Sequence.Concat(_81_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _86_ctorMatch), RAST.Expr.create_Block(_89_printRhs)))); + _82_hashImplBodyCases = Dafny.Sequence.Concat(_82_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _86_ctorMatch), RAST.Expr.create_Block(_90_hashRhs)))); + _83_coerceImplBodyCases = Dafny.Sequence.Concat(_83_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _86_ctorMatch), RAST.Expr.create_Block(_104_coerceRhs)))); } if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { - Dafny.ISequence _99_extraCases; - _99_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); - _75_printImplBodyCases = Dafny.Sequence.Concat(_75_printImplBodyCases, _99_extraCases); - _76_hashImplBodyCases = Dafny.Sequence.Concat(_76_hashImplBodyCases, _99_extraCases); - _77_coerceImplBodyCases = Dafny.Sequence.Concat(_77_coerceImplBodyCases, _99_extraCases); - } - Dafny.ISequence _100_defaultConstrainedTypeParams; - _100_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - Dafny.ISequence _101_rTypeParamsDeclsWithEq; - _101_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); - Dafny.ISequence _102_rTypeParamsDeclsWithHash; - _102_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - RAST._IExpr _103_printImplBody; - _103_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _75_printImplBodyCases); - RAST._IExpr _104_hashImplBody; - _104_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _76_hashImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams, _103_printImplBody))); + Dafny.ISequence _105_extraCases; + _105_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + _81_printImplBodyCases = Dafny.Sequence.Concat(_81_printImplBodyCases, _105_extraCases); + _82_hashImplBodyCases = Dafny.Sequence.Concat(_82_hashImplBodyCases, _105_extraCases); + _83_coerceImplBodyCases = Dafny.Sequence.Concat(_83_coerceImplBodyCases, _105_extraCases); + } + Dafny.ISequence _106_defaultConstrainedTypeParams; + _106_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + Dafny.ISequence _107_rTypeParamsDeclsWithEq; + _107_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); + Dafny.ISequence _108_rTypeParamsDeclsWithHash; + _108_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); + RAST._IExpr _109_printImplBody; + _109_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _81_printImplBodyCases); + RAST._IExpr _110_hashImplBody; + _110_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _82_hashImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams, _109_printImplBody))); if ((new BigInteger((_49_rCoerceTypeParams).Count)).Sign == 1) { - RAST._IExpr _105_coerceImplBody; - _105_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _77_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _69_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _105_coerceImplBody))); + RAST._IExpr _111_coerceImplBody; + _111_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _83_coerceImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _69_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _111_coerceImplBody))); } if ((new BigInteger((_9_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { - RAST._IType _106_instantiationType; + RAST._IType _112_instantiationType; if (_0_isRcWrapped) { - _106_instantiationType = RAST.__default.Rc(_69_datatypeType); + _112_instantiationType = RAST.__default.Rc(_69_datatypeType); } else { - _106_instantiationType = _69_datatypeType; + _112_instantiationType = _69_datatypeType; } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _69_datatypeType, _106_instantiationType, _9_singletonConstructors))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _69_datatypeType, _112_instantiationType, _9_singletonConstructors))); } if (_68_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_101_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), Dafny.Sequence.FromElements())))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_107_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), Dafny.Sequence.FromElements())))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_102_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), _104_hashImplBody))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_108_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), _110_hashImplBody))); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - RAST._IExpr _107_structName; - _107_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _108_structAssignments; - _108_structAssignments = Dafny.Sequence.FromElements(); - BigInteger _hi9 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); - for (BigInteger _109_i = BigInteger.Zero; _109_i < _hi9; _109_i++) { - DAST._IDatatypeDtor _110_dtor; - _110_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_109_i); - _108_structAssignments = Dafny.Sequence.Concat(_108_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_110_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); - } - RAST._IType _111_fullType; - _111_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); + RAST._IExpr _113_structName; + _113_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _114_structAssignments; + _114_structAssignments = Dafny.Sequence.FromElements(); + BigInteger _hi10 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); + for (BigInteger _115_i = BigInteger.Zero; _115_i < _hi10; _115_i++) { + DAST._IDatatypeDtor _116_dtor; + _116_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_115_i); + _114_structAssignments = Dafny.Sequence.Concat(_114_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_116_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); + } + RAST._IType _117_fullType; + _117_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); if ((false) && (_68_cIsEq)) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _111_fullType, _107_structName, _108_structAssignments))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _117_fullType, _113_structName, _114_structAssignments))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _111_fullType))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _117_fullType))); } - Dafny.ISequence _112_superTraitImplementations; - Dafny.ISequence _out18; - _out18 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, Dafny.Sequence.UnicodeFromString("datatype")); - _112_superTraitImplementations = _out18; - s = Dafny.Sequence.Concat(s, _112_superTraitImplementations); + Dafny.ISequence _118_superTraitImplementations; + Dafny.ISequence _out20; + _out20 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, Dafny.Sequence.UnicodeFromString("datatype")); + _118_superTraitImplementations = _out20; + s = Dafny.Sequence.Concat(s, _118_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -1879,7 +1907,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e { if (_source0.is_UserDefined) { DAST._IResolvedType _11_r = _source0.dtor_resolved; - _10_instanceType = DAST.Type.create_UserDefined(Dafny.Helpers.Let(_11_r, _pat_let26_0 => Dafny.Helpers.Let(_pat_let26_0, _12_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let_tv0, _pat_let27_0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let27_0, _13_dt__update_htypeArgs_h0 => DAST.ResolvedType.create((_12_dt__update__tmp_h0).dtor_path, _13_dt__update_htypeArgs_h0, (_12_dt__update__tmp_h0).dtor_kind, (_12_dt__update__tmp_h0).dtor_attributes, (_12_dt__update__tmp_h0).dtor_properMethods, (_12_dt__update__tmp_h0).dtor_extendedTypes)))))); + _10_instanceType = DAST.Type.create_UserDefined(Dafny.Helpers.Let(_11_r, _pat_let25_0 => Dafny.Helpers.Let(_pat_let25_0, _12_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let_tv0, _pat_let26_0 => Dafny.Helpers.Let, DAST._IResolvedType>(_pat_let26_0, _13_dt__update_htypeArgs_h0 => DAST.ResolvedType.create((_12_dt__update__tmp_h0).dtor_path, _13_dt__update_htypeArgs_h0, (_12_dt__update__tmp_h0).dtor_kind, (_12_dt__update__tmp_h0).dtor_attributes, (_12_dt__update__tmp_h0).dtor_properMethods, (_12_dt__update__tmp_h0).dtor_extendedTypes)))))); goto after_match0; } } @@ -2457,17 +2485,17 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D } } { - RAST._IExpr _12_onExpr; - Defs._IOwnership _13___v33; - Dafny.ISet> _14_recIdents; + RAST._IExpr _12_onExpr = RAST.Expr.Default(); + Dafny.ISet> _13_recIdents = Dafny.Set>.Empty; + Defs._IOwnership _14_dummy = Defs.Ownership.Default(); RAST._IExpr _out18; Defs._IOwnership _out19; Dafny.ISet> _out20; (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out18, out _out19, out _out20); _12_onExpr = _out18; - _13___v33 = _out19; - _14_recIdents = _out20; - readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); + _14_dummy = _out19; + _13_recIdents = _out20; + readIdents = Dafny.Set>.Union(readIdents, _13_recIdents); Dafny.ISequence _15_renderedName; _15_renderedName = (this).GetMethodName(@on, name); DAST._IExpression _source1 = @on; @@ -2545,15 +2573,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _5_isAssignedVar = Defs.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { RAST._IExpr _6_rhs; - Defs._IOwnership _7___v43; - Dafny.ISet> _8___v44; + Defs._IOwnership _7___v42; + Dafny.ISet> _8___v43; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr(DAST.Expression.create_InitializationValue(((_2_field).dtor_formal).dtor_typ), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); _6_rhs = _out1; - _7___v43 = _out2; - _8___v44 = _out3; + _7___v42 = _out2; + _8___v43 = _out3; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); Dafny.ISequence _9_update__if__uninit; if ((_2_field).dtor_isConstant) { @@ -2648,14 +2676,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _22_expression = _source0.dtor_value; { RAST._IExpr _23_exprGen; - Defs._IOwnership _24___v45; + Defs._IOwnership _24___v44; Dafny.ISet> _25_exprIdents; RAST._IExpr _out12; Defs._IOwnership _out13; Dafny.ISet> _out14; (this).GenExpr(_22_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out12, out _out13, out _out14); _23_exprGen = _out12; - _24___v45 = _out13; + _24___v44 = _out13; _25_exprIdents = _out14; if ((_21_lhs).is_Ident) { Dafny.ISequence _26_rustId; @@ -2705,14 +2733,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _36_elsDafny = _source0.dtor_els; { RAST._IExpr _37_cond; - Defs._IOwnership _38___v46; + Defs._IOwnership _38___v45; Dafny.ISet> _39_recIdents; RAST._IExpr _out19; Defs._IOwnership _out20; Dafny.ISet> _out21; (this).GenExpr(_34_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out19, out _out20, out _out21); _37_cond = _out19; - _38___v46 = _out20; + _38___v45 = _out20; _39_recIdents = _out21; Dafny.ISequence _40_condString; _40_condString = (_37_cond)._ToString(Defs.__default.IND); @@ -2773,14 +2801,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _53_body = _source0.dtor_body; { RAST._IExpr _54_cond; - Defs._IOwnership _55___v47; + Defs._IOwnership _55___v46; Dafny.ISet> _56_recIdents; RAST._IExpr _out31; Defs._IOwnership _out32; Dafny.ISet> _out33; (this).GenExpr(_52_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out31, out _out32, out _out33); _54_cond = _out31; - _55___v47 = _out32; + _55___v46 = _out32; _56_recIdents = _out33; readIdents = _56_recIdents; RAST._IExpr _57_bodyExpr; @@ -2808,14 +2836,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _63_body = _source0.dtor_body; { RAST._IExpr _64_over; - Defs._IOwnership _65___v48; + Defs._IOwnership _65___v47; Dafny.ISet> _66_recIdents; RAST._IExpr _out37; Defs._IOwnership _out38; Dafny.ISet> _out39; (this).GenExpr(_62_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out37, out _out38, out _out39); _64_over = _out37; - _65___v48 = _out38; + _65___v47 = _out38; _66_recIdents = _out39; if (((_62_overExpr).is_MapBoundedPool) || ((_62_overExpr).is_SetBoundedPool)) { _64_over = ((_64_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); @@ -2879,15 +2907,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _75_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { RAST._IExpr _76_selfClone; - Defs._IOwnership _77___v49; - Dafny.ISet> _78___v50; + Defs._IOwnership _77___v48; + Dafny.ISet> _78___v49; RAST._IExpr _out44; Defs._IOwnership _out45; Dafny.ISet> _out46; (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out44, out _out45, out _out46); _76_selfClone = _out44; - _77___v49 = _out45; - _78___v50 = _out46; + _77___v48 = _out45; + _78___v49 = _out46; generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_76_selfClone))); if (((_75_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { _75_oldEnv = (_75_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); @@ -2904,15 +2932,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv goto continue_4_0; } RAST._IExpr _82_paramInit; - Defs._IOwnership _83___v51; - Dafny.ISet> _84___v52; + Defs._IOwnership _83___v50; + Dafny.ISet> _84___v51; RAST._IExpr _out47; Defs._IOwnership _out48; Dafny.ISet> _out49; (this).GenIdent(_81_param, selfIdent, _75_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out47, out _out48, out _out49); _82_paramInit = _out47; - _83___v51 = _out48; - _84___v52 = _out49; + _83___v50 = _out48; + _84___v51 = _out49; Dafny.ISequence _85_recVar; _85_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_80_paramI)); generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _85_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_82_paramInit))); @@ -3004,14 +3032,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _102_exprDafny = _source0.dtor_expr; { RAST._IExpr _103_expr; - Defs._IOwnership _104___v53; + Defs._IOwnership _104___v52; Dafny.ISet> _105_recIdents; RAST._IExpr _out55; Defs._IOwnership _out56; Dafny.ISet> _out57; (this).GenExpr(_102_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out55, out _out56, out _out57); _103_expr = _out55; - _104___v53 = _out56; + _104___v52 = _out56; _105_recIdents = _out57; readIdents = _105_recIdents; if (isLast) { @@ -3041,15 +3069,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv BigInteger _hi3 = new BigInteger((_106_rustIdents).Count); for (BigInteger _108_i = BigInteger.Zero; _108_i < _hi3; _108_i++) { RAST._IExpr _109_rIdent; - Defs._IOwnership _110___v54; - Dafny.ISet> _111___v55; + Defs._IOwnership _110___v53; + Dafny.ISet> _111___v54; RAST._IExpr _out58; Defs._IOwnership _out59; Dafny.ISet> _out60; (this).GenIdent((_106_rustIdents).Select(_108_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out58, out _out59, out _out60); _109_rIdent = _out58; - _110___v54 = _out59; - _111___v55 = _out60; + _110___v53 = _out59; + _111___v54 = _out60; _107_tupleArgs = Dafny.Sequence.Concat(_107_tupleArgs, Dafny.Sequence.FromElements(_109_rIdent)); } if ((new BigInteger((_107_tupleArgs).Count)) == (BigInteger.One)) { @@ -3155,9 +3183,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. DAST._IExpression _source0 = e; { if (_source0.is_Literal) { - DAST._ILiteral _h560 = _source0.dtor_Literal_a0; - if (_h560.is_BoolLiteral) { - bool _0_b = _h560.dtor_BoolLiteral_a0; + DAST._ILiteral _h620 = _source0.dtor_Literal_a0; + if (_h620.is_BoolLiteral) { + bool _0_b = _h620.dtor_BoolLiteral_a0; { RAST._IExpr _out0; Defs._IOwnership _out1; @@ -3173,10 +3201,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h561 = _source0.dtor_Literal_a0; - if (_h561.is_IntLiteral) { - Dafny.ISequence _1_i = _h561.dtor_IntLiteral_a0; - DAST._IType _2_t = _h561.dtor_IntLiteral_a1; + DAST._ILiteral _h621 = _source0.dtor_Literal_a0; + if (_h621.is_IntLiteral) { + Dafny.ISequence _1_i = _h621.dtor_IntLiteral_a0; + DAST._IType _2_t = _h621.dtor_IntLiteral_a1; { DAST._IType _source1 = _2_t; { @@ -3219,11 +3247,11 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h562 = _source0.dtor_Literal_a0; - if (_h562.is_DecLiteral) { - Dafny.ISequence _5_n = _h562.dtor_DecLiteral_a0; - Dafny.ISequence _6_d = _h562.dtor_DecLiteral_a1; - DAST._IType _7_t = _h562.dtor_DecLiteral_a2; + DAST._ILiteral _h622 = _source0.dtor_Literal_a0; + if (_h622.is_DecLiteral) { + Dafny.ISequence _5_n = _h622.dtor_DecLiteral_a0; + Dafny.ISequence _6_d = _h622.dtor_DecLiteral_a1; + DAST._IType _7_t = _h622.dtor_DecLiteral_a2; { DAST._IType _source2 = _7_t; { @@ -3262,10 +3290,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h563 = _source0.dtor_Literal_a0; - if (_h563.is_StringLiteral) { - Dafny.ISequence _10_l = _h563.dtor_StringLiteral_a0; - bool _11_verbatim = _h563.dtor_verbatim; + DAST._ILiteral _h623 = _source0.dtor_Literal_a0; + if (_h623.is_StringLiteral) { + Dafny.ISequence _10_l = _h623.dtor_StringLiteral_a0; + bool _11_verbatim = _h623.dtor_verbatim; { r = (((RAST.__default.dafny__runtime).MSel((this).string__of)).AsExpr()).Apply1(RAST.Expr.create_LiteralString(_10_l, false, _11_verbatim)); RAST._IExpr _out8; @@ -3282,9 +3310,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h564 = _source0.dtor_Literal_a0; - if (_h564.is_CharLiteralUTF16) { - BigInteger _12_c = _h564.dtor_CharLiteralUTF16_a0; + DAST._ILiteral _h624 = _source0.dtor_Literal_a0; + if (_h624.is_CharLiteralUTF16) { + BigInteger _12_c = _h624.dtor_CharLiteralUTF16_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(_12_c)); r = RAST.Expr.create_TypeAscription(r, RAST.Type.create_U16()); @@ -3303,9 +3331,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h565 = _source0.dtor_Literal_a0; - if (_h565.is_CharLiteral) { - Dafny.Rune _13_c = _h565.dtor_CharLiteral_a0; + DAST._ILiteral _h625 = _source0.dtor_Literal_a0; + if (_h625.is_CharLiteral) { + Dafny.Rune _13_c = _h625.dtor_CharLiteral_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(new BigInteger((_13_c).Value))); if (!(((this).charType).is_UTF32)) { @@ -3327,8 +3355,8 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } } { - DAST._ILiteral _h566 = _source0.dtor_Literal_a0; - DAST._IType _14_tpe = _h566.dtor_Null_a0; + DAST._ILiteral _h626 = _source0.dtor_Literal_a0; + DAST._IType _14_tpe = _h626.dtor_Null_a0; { RAST._IType _15_tpeGen; RAST._IType _out14; @@ -3445,24 +3473,24 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ _10_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); } RAST._IExpr _11_left; - Defs._IOwnership _12___v56; + Defs._IOwnership _12___v55; Dafny.ISet> _13_recIdentsL; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(_4_lExpr, selfIdent, env, _9_expectedLeftOwnership, out _out0, out _out1, out _out2); _11_left = _out0; - _12___v56 = _out1; + _12___v55 = _out1; _13_recIdentsL = _out2; RAST._IExpr _14_right; - Defs._IOwnership _15___v57; + Defs._IOwnership _15___v56; Dafny.ISet> _16_recIdentsR; RAST._IExpr _out3; Defs._IOwnership _out4; Dafny.ISet> _out5; (this).GenExpr(_5_rExpr, selfIdent, env, _10_expectedRightOwnership, out _out3, out _out4, out _out5); _14_right = _out3; - _15___v57 = _out4; + _15___v56 = _out4; _16_recIdentsR = _out5; DAST._IBinOp _source0 = _0_op; { @@ -4184,7 +4212,7 @@ public bool SameTypesButDifferentTypeParameters(DAST._IType fromType, RAST._ITyp var arr16 = new Std.Wrappers._IResult,RAST._IExpr>>>[Dafny.Helpers.ToIntChecked(dim16, "array size exceeds memory limit")]; for (int i16 = 0; i16 < dim16; i16++) { var _13_j = (BigInteger) i16; - arr16[(int)(_13_j)] = Dafny.Helpers.Let,RAST._IExpr>>>>((_6_indices).Select(_13_j), _pat_let28_0 => Dafny.Helpers.Let,RAST._IExpr>>>>(_pat_let28_0, _14_i => (this).UpcastConversionLambda((((_pat_let_tv0).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv1).dtor_arguments).Select(_14_i), (((_pat_let_tv2).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv3).dtor_arguments).Select(_14_i), _pat_let_tv4))); + arr16[(int)(_13_j)] = Dafny.Helpers.Let,RAST._IExpr>>>>((_6_indices).Select(_13_j), _pat_let27_0 => Dafny.Helpers.Let,RAST._IExpr>>>>(_pat_let27_0, _14_i => (this).UpcastConversionLambda((((_pat_let_tv0).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv1).dtor_arguments).Select(_14_i), (((_pat_let_tv2).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv3).dtor_arguments).Select(_14_i), _pat_let_tv4))); } return Dafny.Sequence,RAST._IExpr>>>>.FromArray(arr16); }))()); @@ -4333,7 +4361,10 @@ public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership } after_match0: ; } - _8_newExpr = (this).FromGeneralBorrowToSelfBorrow(expr, Defs.Ownership.create_OwnershipBorrowed(), env); + _8_newExpr = (this).FromGeneralBorrowToSelfBorrow(_8_newExpr, Defs.Ownership.create_OwnershipBorrowed(), env); + if (_2_isDatatype) { + _8_newExpr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_8_newExpr); + } r = (((_7_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_as"))).Apply1(_8_newExpr); RAST._IExpr _out7; Defs._IOwnership _out8; @@ -4370,38 +4401,54 @@ public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership RAST._IExpr _12_conversionLambda; _12_conversionLambda = (_11_upcastConverter).dtor_value; if (object.Equals(exprOwnership, Defs.Ownership.create_OwnershipBorrowed())) { - r = (this).BorrowedToOwned(r, env); + if (((fromTyp).IsGeneralTrait()) && (object.Equals(r, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))))) { + RAST._IType _13_traitType; + RAST._IType _out15; + _out15 = (this).GenType(fromTyp, Defs.GenTypeContext.ForTraitParents()); + _13_traitType = _out15; + Std.Wrappers._IOption _14_traitExpr; + _14_traitExpr = (_13_traitType).ToExpr(); + if ((_14_traitExpr).is_None) { + RAST._IExpr _out16; + _out16 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_13_traitType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); + r = _out16; + } else { + r = (((_14_traitExpr).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(r); + } + } else { + r = (this).BorrowedToOwned(r, env); + } } r = (_12_conversionLambda).Apply1(r); - RAST._IExpr _out15; - Defs._IOwnership _out16; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out15, out _out16); - r = _out15; - resultingOwnership = _out16; - } else if ((this).IsDowncastConversion(_0_fromTpeGen, _1_toTpeGen)) { - _1_toTpeGen = (_1_toTpeGen).ObjectOrPointerUnderlying(); - r = (((RAST.__default.dafny__runtime).MSel((this).downcast)).AsExpr()).Apply(Dafny.Sequence.FromElements(r, RAST.Expr.create_ExprFromType(_1_toTpeGen))); RAST._IExpr _out17; Defs._IOwnership _out18; (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out17, out _out18); r = _out17; resultingOwnership = _out18; + } else if ((this).IsDowncastConversion(_0_fromTpeGen, _1_toTpeGen)) { + _1_toTpeGen = (_1_toTpeGen).ObjectOrPointerUnderlying(); + r = (((RAST.__default.dafny__runtime).MSel((this).downcast)).AsExpr()).Apply(Dafny.Sequence.FromElements(r, RAST.Expr.create_ExprFromType(_1_toTpeGen))); + RAST._IExpr _out19; + Defs._IOwnership _out20; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out19, out _out20); + r = _out19; + resultingOwnership = _out20; } else { Std.Wrappers._IResult,RAST._IExpr>>> _let_tmp_rhs0 = _11_upcastConverter; _System._ITuple5,RAST._IExpr>> _let_tmp_rhs1 = _let_tmp_rhs0.dtor_error; - DAST._IType _13_fromType = _let_tmp_rhs1.dtor__0; - RAST._IType _14_fromTpeGen = _let_tmp_rhs1.dtor__1; - DAST._IType _15_toType = _let_tmp_rhs1.dtor__2; - RAST._IType _16_toTpeGen = _let_tmp_rhs1.dtor__3; - Dafny.IMap<_System._ITuple2,RAST._IExpr> _17_m = _let_tmp_rhs1.dtor__4; - RAST._IExpr _out19; - _out19 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Coercion from "), (_14_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_16_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), r); - r = _out19; - RAST._IExpr _out20; - Defs._IOwnership _out21; - (this).FromOwned(r, expectedOwnership, out _out20, out _out21); - r = _out20; - resultingOwnership = _out21; + DAST._IType _15_fromType = _let_tmp_rhs1.dtor__0; + RAST._IType _16_fromTpeGen = _let_tmp_rhs1.dtor__1; + DAST._IType _17_toType = _let_tmp_rhs1.dtor__2; + RAST._IType _18_toTpeGen = _let_tmp_rhs1.dtor__3; + Dafny.IMap<_System._ITuple2,RAST._IExpr> _19_m = _let_tmp_rhs1.dtor__4; + RAST._IExpr _out21; + _out21 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Coercion from "), (_16_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_18_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), r); + r = _out21; + RAST._IExpr _out22; + Defs._IOwnership _out23; + (this).FromOwned(r, expectedOwnership, out _out22, out _out23); + r = _out22; + resultingOwnership = _out23; } } public void GenExprConvert(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership, out Dafny.ISet> readIdents) @@ -4482,40 +4529,45 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden resultingOwnership = Defs.Ownership.create_OwnershipBorrowedMut(); } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) { bool _5_needObjectFromRef; - _5_needObjectFromRef = (_4_isSelf) && (((System.Func)(() => { - DAST._IType _source0 = (selfIdent).dtor_dafnyType; - { - if (_source0.is_UserDefined) { - DAST._IResolvedType resolved0 = _source0.dtor_resolved; - DAST._IResolvedTypeBase _6_base = resolved0.dtor_kind; - Dafny.ISequence _7_attributes = resolved0.dtor_attributes; - return ((_6_base).is_Class) || (((_6_base).is_Trait) && (((_6_base).dtor_traitType).is_ObjectTrait)); - } - } - { - return false; - } - }))()); + _5_needObjectFromRef = (_4_isSelf) && ((selfIdent).IsClassOrObjectTrait()); if (_5_needObjectFromRef) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Object"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))).FSel(Dafny.Sequence.UnicodeFromString("from_ref"))).Apply(Dafny.Sequence.FromElements(r)); } else { if (!(_3_noNeedOfClone)) { - r = (r).Clone(); + bool _6_needUnderscoreClone; + _6_needUnderscoreClone = (_4_isSelf) && ((selfIdent).IsGeneralTrait()); + if (_6_needUnderscoreClone) { + RAST._IType _7_traitType; + RAST._IType _out0; + _out0 = (this).GenType((selfIdent).dtor_dafnyType, Defs.GenTypeContext.ForTraitParents()); + _7_traitType = _out0; + Std.Wrappers._IOption _8_traitExpr; + _8_traitExpr = (_7_traitType).ToExpr(); + if ((_8_traitExpr).is_None) { + RAST._IExpr _out1; + _out1 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_7_traitType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); + r = _out1; + } else { + r = (((_8_traitExpr).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(r); + } + } else { + r = (r).Clone(); + } } } resultingOwnership = Defs.Ownership.create_OwnershipOwned(); } else if (_2_currentlyBorrowed) { resultingOwnership = Defs.Ownership.create_OwnershipBorrowed(); } else { - bool _8_selfIsGeneralTrait; - _8_selfIsGeneralTrait = (_4_isSelf) && (((System.Func)(() => { - DAST._IType _source1 = (selfIdent).dtor_dafnyType; + bool _9_selfIsGeneralTrait; + _9_selfIsGeneralTrait = (_4_isSelf) && (((System.Func)(() => { + DAST._IType _source0 = (selfIdent).dtor_dafnyType; { - if (_source1.is_UserDefined) { - DAST._IResolvedType resolved1 = _source1.dtor_resolved; - DAST._IResolvedTypeBase _9_base = resolved1.dtor_kind; - Dafny.ISequence _10_attributes = resolved1.dtor_attributes; - return ((_9_base).is_Trait) && (((_9_base).dtor_traitType).is_GeneralTrait); + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase _10_base = resolved0.dtor_kind; + Dafny.ISequence _11_attributes = resolved0.dtor_attributes; + return ((_10_base).is_Trait) && (((_10_base).dtor_traitType).is_GeneralTrait); } } { @@ -4572,14 +4624,14 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v75; + Defs._IOwnership _5___v69; Dafny.ISet> _6_argIdents; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); _4_argExpr = _out1; - _5___v75 = _out2; + _5___v69 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -4777,14 +4829,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi1 = new BigInteger((_9_values).Count); for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13___v85; + Defs._IOwnership _13___v79; Dafny.ISet> _14_recIdents; RAST._IExpr _out16; Defs._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); _12_recursiveGen = _out16; - _13___v85 = _out17; + _13___v79 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -4833,14 +4885,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi3 = new BigInteger((_17_args).Count); for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { RAST._IExpr _23_recursiveGen; - Defs._IOwnership _24___v86; + Defs._IOwnership _24___v80; Dafny.ISet> _25_recIdents; RAST._IExpr _out23; Defs._IOwnership _out24; Dafny.ISet> _out25; (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); _23_recursiveGen = _out23; - _24___v86 = _out24; + _24___v80 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -4878,14 +4930,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi4 = new BigInteger((_26_dims).Count); for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { RAST._IExpr _31_recursiveGen; - Defs._IOwnership _32___v87; + Defs._IOwnership _32___v81; Dafny.ISet> _33_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr((_26_dims).Select(_30_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _31_recursiveGen = _out30; - _32___v87 = _out31; + _32___v81 = _out31; _33_recIdents = _out32; _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); @@ -4912,14 +4964,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _35_underlying = _source0.dtor_value; { RAST._IExpr _36_recursiveGen; - Defs._IOwnership _37___v88; + Defs._IOwnership _37___v82; Dafny.ISet> _38_recIdents; RAST._IExpr _out35; Defs._IOwnership _out36; Dafny.ISet> _out37; (this).GenExpr(_35_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out35, out _out36, out _out37); _36_recursiveGen = _out35; - _37___v88 = _out36; + _37___v82 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -4942,14 +4994,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out40 = (this).GenType(_40_typ, Defs.GenTypeContext.@default()); _41_tpe = _out40; RAST._IExpr _42_recursiveGen; - Defs._IOwnership _43___v89; + Defs._IOwnership _43___v83; Dafny.ISet> _44_recIdents; RAST._IExpr _out41; Defs._IOwnership _out42; Dafny.ISet> _out43; (this).GenExpr(_39_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); _42_recursiveGen = _out41; - _43___v89 = _out42; + _43___v83 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -5015,14 +5067,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; if (_50_isCo) { RAST._IExpr _59_recursiveGen; - Defs._IOwnership _60___v90; + Defs._IOwnership _60___v84; Dafny.ISet> _61_recIdents; RAST._IExpr _out50; Defs._IOwnership _out51; Dafny.ISet> _out52; (this).GenExpr(_58_value, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); _59_recursiveGen = _out50; - _60___v90 = _out51; + _60___v84 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -5045,14 +5097,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _64_wasAssigned))); } else { RAST._IExpr _65_recursiveGen; - Defs._IOwnership _66___v91; + Defs._IOwnership _66___v85; Dafny.ISet> _67_recIdents; RAST._IExpr _out53; Defs._IOwnership _out54; Dafny.ISet> _out55; (this).GenExpr(_58_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out53, out _out54, out _out55); _65_recursiveGen = _out53; - _66___v91 = _out54; + _66___v85 = _out54; _67_recIdents = _out55; _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _65_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); @@ -5092,24 +5144,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _69_expr = _source0.dtor_elem; { RAST._IExpr _70_recursiveGen; - Defs._IOwnership _71___v95; + Defs._IOwnership _71___v89; Dafny.ISet> _72_recIdents; RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; (this).GenExpr(_69_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); _70_recursiveGen = _out61; - _71___v95 = _out62; + _71___v89 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v96; + Defs._IOwnership _74___v90; Dafny.ISet> _75_lengthIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_68_length, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); _73_lengthGen = _out64; - _74___v96 = _out65; + _74___v90 = _out65; _75_lengthIdents = _out66; r = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("_initializer"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_70_recursiveGen)); RAST._IExpr _76_range; @@ -5148,14 +5200,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _82_args = Dafny.Sequence.FromElements(); while ((_81_i) < (new BigInteger((_78_exprs).Count))) { RAST._IExpr _83_recursiveGen; - Defs._IOwnership _84___v97; + Defs._IOwnership _84___v91; Dafny.ISet> _85_recIdents; RAST._IExpr _out70; Defs._IOwnership _out71; Dafny.ISet> _out72; (this).GenExpr((_78_exprs).Select(_81_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out70, out _out71, out _out72); _83_recursiveGen = _out70; - _84___v97 = _out71; + _84___v91 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -5186,14 +5238,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _88_i = BigInteger.Zero; while ((_88_i) < (new BigInteger((_86_exprs).Count))) { RAST._IExpr _89_recursiveGen; - Defs._IOwnership _90___v98; + Defs._IOwnership _90___v92; Dafny.ISet> _91_recIdents; RAST._IExpr _out75; Defs._IOwnership _out76; Dafny.ISet> _out77; (this).GenExpr((_86_exprs).Select(_88_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out75, out _out76, out _out77); _89_recursiveGen = _out75; - _90___v98 = _out76; + _90___v92 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -5221,14 +5273,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _94_i = BigInteger.Zero; while ((_94_i) < (new BigInteger((_92_exprs).Count))) { RAST._IExpr _95_recursiveGen; - Defs._IOwnership _96___v99; + Defs._IOwnership _96___v93; Dafny.ISet> _97_recIdents; RAST._IExpr _out80; Defs._IOwnership _out81; Dafny.ISet> _out82; (this).GenExpr((_92_exprs).Select(_94_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out80, out _out81, out _out82); _95_recursiveGen = _out80; - _96___v99 = _out81; + _96___v93 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -5250,14 +5302,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _98_expr = _source0.dtor_ToMultiset_a0; { RAST._IExpr _99_recursiveGen; - Defs._IOwnership _100___v100; + Defs._IOwnership _100___v94; Dafny.ISet> _101_recIdents; RAST._IExpr _out85; Defs._IOwnership _out86; Dafny.ISet> _out87; (this).GenExpr(_98_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out85, out _out86, out _out87); _99_recursiveGen = _out85; - _100___v100 = _out86; + _100___v94 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -5282,24 +5334,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _104_i = BigInteger.Zero; while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v101; + Defs._IOwnership _106___v95; Dafny.ISet> _107_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); _105_recursiveGenKey = _out90; - _106___v101 = _out91; + _106___v95 = _out91; _107_recIdentsKey = _out92; RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v102; + Defs._IOwnership _109___v96; Dafny.ISet> _110_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); _108_recursiveGenValue = _out93; - _109___v102 = _out94; + _109___v96 = _out94; _110_recIdentsValue = _out95; _103_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_103_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_105_recursiveGenKey, _108_recursiveGenValue))); readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _107_recIdentsKey), _110_recIdentsValue); @@ -5334,14 +5386,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _116_value = _source0.dtor_value; { RAST._IExpr _117_exprR; - Defs._IOwnership _118___v103; + Defs._IOwnership _118___v97; Dafny.ISet> _119_exprIdents; RAST._IExpr _out98; Defs._IOwnership _out99; Dafny.ISet> _out100; (this).GenExpr(_114_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out98, out _out99, out _out100); _117_exprR = _out98; - _118___v103 = _out99; + _118___v97 = _out99; _119_exprIdents = _out100; RAST._IExpr _120_indexR; Defs._IOwnership _121_indexOwnership; @@ -5382,14 +5434,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _128_value = _source0.dtor_value; { RAST._IExpr _129_exprR; - Defs._IOwnership _130___v104; + Defs._IOwnership _130___v98; Dafny.ISet> _131_exprIdents; RAST._IExpr _out109; Defs._IOwnership _out110; Dafny.ISet> _out111; (this).GenExpr(_126_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out109, out _out110, out _out111); _129_exprR = _out109; - _130___v104 = _out110; + _130___v98 = _out110; _131_exprIdents = _out111; RAST._IExpr _132_indexR; Defs._IOwnership _133_indexOwnership; @@ -5470,14 +5522,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _143_f = _source0.dtor_els; { RAST._IExpr _144_cond; - Defs._IOwnership _145___v105; + Defs._IOwnership _145___v99; Dafny.ISet> _146_recIdentsCond; RAST._IExpr _out126; Defs._IOwnership _out127; Dafny.ISet> _out128; (this).GenExpr(_141_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out126, out _out127, out _out128); _144_cond = _out126; - _145___v105 = _out127; + _145___v99 = _out127; _146_recIdentsCond = _out128; RAST._IExpr _147_fExpr; Defs._IOwnership _148_fOwned; @@ -5490,14 +5542,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _148_fOwned = _out130; _149_recIdentsF = _out131; RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v106; + Defs._IOwnership _151___v100; Dafny.ISet> _152_recIdentsT; RAST._IExpr _out132; Defs._IOwnership _out133; Dafny.ISet> _out134; (this).GenExpr(_142_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); _150_tExpr = _out132; - _151___v106 = _out133; + _151___v100 = _out133; _152_recIdentsT = _out134; r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); RAST._IExpr _out135; @@ -5519,14 +5571,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; { RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v107; + Defs._IOwnership _156___v101; Dafny.ISet> _157_recIdents; RAST._IExpr _out137; Defs._IOwnership _out138; Dafny.ISet> _out139; (this).GenExpr(_153_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out137, out _out138, out _out139); _155_recursiveGen = _out137; - _156___v107 = _out138; + _156___v101 = _out138; _157_recIdents = _out139; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); RAST._IExpr _out140; @@ -5549,14 +5601,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; { RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v108; + Defs._IOwnership _161___v102; Dafny.ISet> _162_recIdents; RAST._IExpr _out142; Defs._IOwnership _out143; Dafny.ISet> _out144; (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out142, out _out143, out _out144); _160_recursiveGen = _out142; - _161___v108 = _out143; + _161___v102 = _out143; _162_recIdents = _out144; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); RAST._IExpr _out145; @@ -5621,14 +5673,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _171_native = _source0.dtor_native; { RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v113; + Defs._IOwnership _173___v107; Dafny.ISet> _174_recIdents; RAST._IExpr _out155; Defs._IOwnership _out156; Dafny.ISet> _out157; (this).GenExpr(_168_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out155, out _out156, out _out157); _172_recursiveGen = _out155; - _173___v113 = _out156; + _173___v107 = _out156; _174_recIdents = _out157; RAST._IType _175_arrayType; RAST._IType _out158; @@ -5670,14 +5722,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _177_expr = _source0.dtor_expr; { RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v114; + Defs._IOwnership _179___v108; Dafny.ISet> _180_recIdents; RAST._IExpr _out162; Defs._IOwnership _out163; Dafny.ISet> _out164; (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); _178_recursiveGen = _out162; - _179___v114 = _out163; + _179___v108 = _out163; _180_recIdents = _out164; readIdents = _180_recIdents; r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); @@ -5696,14 +5748,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _181_expr = _source0.dtor_expr; { RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v115; + Defs._IOwnership _183___v109; Dafny.ISet> _184_recIdents; RAST._IExpr _out167; Defs._IOwnership _out168; Dafny.ISet> _out169; (this).GenExpr(_181_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); _182_recursiveGen = _out167; - _183___v115 = _out168; + _183___v109 = _out168; _184_recIdents = _out169; readIdents = _184_recIdents; r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); @@ -5722,14 +5774,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _185_expr = _source0.dtor_expr; { RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v116; + Defs._IOwnership _187___v110; Dafny.ISet> _188_recIdents; RAST._IExpr _out172; Defs._IOwnership _out173; Dafny.ISet> _out174; (this).GenExpr(_185_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out172, out _out173, out _out174); _186_recursiveGen = _out172; - _187___v116 = _out173; + _187___v110 = _out173; _188_recIdents = _out174; readIdents = _188_recIdents; r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); @@ -5801,15 +5853,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _209_name = _let_tmp_rhs1.dtor__0; RAST._IType _210_ty = _let_tmp_rhs1.dtor__1; RAST._IExpr _211_rIdent; - Defs._IOwnership _212___v117; - Dafny.ISet> _213___v118; + Defs._IOwnership _212___v111; + Dafny.ISet> _213___v112; RAST._IExpr _out181; Defs._IOwnership _out182; Dafny.ISet> _out183; (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((!(_193_isConstant)) && ((_210_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); _211_rIdent = _out181; - _212___v117 = _out182; - _213___v118 = _out183; + _212___v111 = _out182; + _213___v112 = _out183; _207_onExprArgs = Dafny.Sequence.Concat(_207_onExprArgs, Dafny.Sequence.FromElements(_211_rIdent)); } _206_body = (_206_body).Apply(_207_onExprArgs); @@ -5849,8 +5901,8 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _218_on = _source0.dtor_expr; Dafny.ISequence _219_field = _source0.dtor_field; DAST._IFieldMutability _220_fieldMutability = _source0.dtor_fieldMutability; - bool _221_isDatatype = _source0.dtor_isDatatype; - DAST._IType _222_fieldType = _source0.dtor_fieldType; + DAST._ISelectContext _221_selectContext = _source0.dtor_selectContext; + DAST._IType _222_fieldType = _source0.dtor_isfieldType; { if (((_218_on).is_Companion) || ((_218_on).is_ExternCompanion)) { RAST._IExpr _223_onExpr; @@ -5871,7 +5923,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir resultingOwnership = _out190; readIdents = _225_recIdents; return ; - } else if (_221_isDatatype) { + } else if ((_221_selectContext).is_SelectContextDatatype) { RAST._IExpr _226_onExpr; Defs._IOwnership _227_onOwned; Dafny.ISet> _228_recIdents; @@ -5913,20 +5965,42 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir r = _out196; resultingOwnership = _out197; readIdents = _228_recIdents; - } else { + } else if ((_221_selectContext).is_SelectContextGeneralTrait) { RAST._IExpr _231_onExpr; Defs._IOwnership _232_onOwned; Dafny.ISet> _233_recIdents; RAST._IExpr _out198; Defs._IOwnership _out199; Dafny.ISet> _out200; - (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out198, out _out199, out _out200); + (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out198, out _out199, out _out200); _231_onExpr = _out198; _232_onOwned = _out199; _233_recIdents = _out200; r = _231_onExpr; if (!object.Equals(_231_onExpr, RAST.__default.self)) { - RAST._IExpr _source3 = _231_onExpr; + r = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(r); + } + r = ((r).Sel(Defs.__default.escapeVar(_219_field))).Apply0(); + RAST._IExpr _out201; + Defs._IOwnership _out202; + (this).FromOwned(r, expectedOwnership, out _out201, out _out202); + r = _out201; + resultingOwnership = _out202; + readIdents = _233_recIdents; + } else { + RAST._IExpr _234_onExpr; + Defs._IOwnership _235_onOwned; + Dafny.ISet> _236_recIdents; + RAST._IExpr _out203; + Defs._IOwnership _out204; + Dafny.ISet> _out205; + (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out203, out _out204, out _out205); + _234_onExpr = _out203; + _235_onOwned = _out204; + _236_recIdents = _out205; + r = _234_onExpr; + if (!object.Equals(_234_onExpr, RAST.__default.self)) { + RAST._IExpr _source3 = _234_onExpr; { if (_source3.is_UnaryOp) { Dafny.ISequence op10 = _source3.dtor_op1; @@ -5969,12 +6043,12 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir r = ((this).read__mutable__field__macro).Apply1(r); } after_match4: ; - RAST._IExpr _out201; - Defs._IOwnership _out202; - (this).FromOwned(r, expectedOwnership, out _out201, out _out202); - r = _out201; - resultingOwnership = _out202; - readIdents = _233_recIdents; + RAST._IExpr _out206; + Defs._IOwnership _out207; + (this).FromOwned(r, expectedOwnership, out _out206, out _out207); + r = _out206; + resultingOwnership = _out207; + readIdents = _236_recIdents; } return ; } @@ -5983,70 +6057,70 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Index) { - DAST._IExpression _234_on = _source0.dtor_expr; - DAST._ICollKind _235_collKind = _source0.dtor_collKind; - Dafny.ISequence _236_indices = _source0.dtor_indices; + DAST._IExpression _237_on = _source0.dtor_expr; + DAST._ICollKind _238_collKind = _source0.dtor_collKind; + Dafny.ISequence _239_indices = _source0.dtor_indices; { - RAST._IExpr _237_onExpr; - Defs._IOwnership _238_onOwned; - Dafny.ISet> _239_recIdents; - RAST._IExpr _out203; - Defs._IOwnership _out204; - Dafny.ISet> _out205; - (this).GenExpr(_234_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out203, out _out204, out _out205); - _237_onExpr = _out203; - _238_onOwned = _out204; - _239_recIdents = _out205; - readIdents = _239_recIdents; - r = _237_onExpr; - bool _240_hadArray; - _240_hadArray = false; - if (object.Equals(_235_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _240_onExpr; + Defs._IOwnership _241_onOwned; + Dafny.ISet> _242_recIdents; + RAST._IExpr _out208; + Defs._IOwnership _out209; + Dafny.ISet> _out210; + (this).GenExpr(_237_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out208, out _out209, out _out210); + _240_onExpr = _out208; + _241_onOwned = _out209; + _242_recIdents = _out210; + readIdents = _242_recIdents; + r = _240_onExpr; + bool _243_hadArray; + _243_hadArray = false; + if (object.Equals(_238_collKind, DAST.CollKind.create_Array())) { r = ((this).read__macro).Apply1(r); - _240_hadArray = true; - if ((new BigInteger((_236_indices).Count)) > (BigInteger.One)) { + _243_hadArray = true; + if ((new BigInteger((_239_indices).Count)) > (BigInteger.One)) { r = (r).Sel(Dafny.Sequence.UnicodeFromString("data")); } } - BigInteger _hi10 = new BigInteger((_236_indices).Count); - for (BigInteger _241_i = BigInteger.Zero; _241_i < _hi10; _241_i++) { - if (object.Equals(_235_collKind, DAST.CollKind.create_Array())) { - RAST._IExpr _242_idx; - Defs._IOwnership _243_idxOwned; - Dafny.ISet> _244_recIdentsIdx; - RAST._IExpr _out206; - Defs._IOwnership _out207; - Dafny.ISet> _out208; - (this).GenExpr((_236_indices).Select(_241_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out206, out _out207, out _out208); - _242_idx = _out206; - _243_idxOwned = _out207; - _244_recIdentsIdx = _out208; - _242_idx = RAST.__default.IntoUsize(_242_idx); - r = RAST.Expr.create_SelectIndex(r, _242_idx); - readIdents = Dafny.Set>.Union(readIdents, _244_recIdentsIdx); - } else { + BigInteger _hi10 = new BigInteger((_239_indices).Count); + for (BigInteger _244_i = BigInteger.Zero; _244_i < _hi10; _244_i++) { + if (object.Equals(_238_collKind, DAST.CollKind.create_Array())) { RAST._IExpr _245_idx; Defs._IOwnership _246_idxOwned; Dafny.ISet> _247_recIdentsIdx; - RAST._IExpr _out209; - Defs._IOwnership _out210; - Dafny.ISet> _out211; - (this).GenExpr((_236_indices).Select(_241_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out209, out _out210, out _out211); - _245_idx = _out209; - _246_idxOwned = _out210; - _247_recIdentsIdx = _out211; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_245_idx); + RAST._IExpr _out211; + Defs._IOwnership _out212; + Dafny.ISet> _out213; + (this).GenExpr((_239_indices).Select(_244_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out211, out _out212, out _out213); + _245_idx = _out211; + _246_idxOwned = _out212; + _247_recIdentsIdx = _out213; + _245_idx = RAST.__default.IntoUsize(_245_idx); + r = RAST.Expr.create_SelectIndex(r, _245_idx); readIdents = Dafny.Set>.Union(readIdents, _247_recIdentsIdx); + } else { + RAST._IExpr _248_idx; + Defs._IOwnership _249_idxOwned; + Dafny.ISet> _250_recIdentsIdx; + RAST._IExpr _out214; + Defs._IOwnership _out215; + Dafny.ISet> _out216; + (this).GenExpr((_239_indices).Select(_244_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out214, out _out215, out _out216); + _248_idx = _out214; + _249_idxOwned = _out215; + _250_recIdentsIdx = _out216; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_248_idx); + readIdents = Dafny.Set>.Union(readIdents, _250_recIdentsIdx); } } - if (_240_hadArray) { + if (_243_hadArray) { r = (r).Clone(); } - RAST._IExpr _out212; - Defs._IOwnership _out213; - (this).FromOwned(r, expectedOwnership, out _out212, out _out213); - r = _out212; - resultingOwnership = _out213; + RAST._IExpr _out217; + Defs._IOwnership _out218; + (this).FromOwned(r, expectedOwnership, out _out217, out _out218); + r = _out217; + resultingOwnership = _out218; return ; } goto after_match0; @@ -6054,63 +6128,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IndexRange) { - DAST._IExpression _248_on = _source0.dtor_expr; - bool _249_isArray = _source0.dtor_isArray; - Std.Wrappers._IOption _250_low = _source0.dtor_low; - Std.Wrappers._IOption _251_high = _source0.dtor_high; + DAST._IExpression _251_on = _source0.dtor_expr; + bool _252_isArray = _source0.dtor_isArray; + Std.Wrappers._IOption _253_low = _source0.dtor_low; + Std.Wrappers._IOption _254_high = _source0.dtor_high; { - Defs._IOwnership _252_onExpectedOwnership; - if (_249_isArray) { + Defs._IOwnership _255_onExpectedOwnership; + if (_252_isArray) { if (((this).pointerType).is_Raw) { - _252_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); + _255_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); } else { - _252_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); + _255_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); } } else { - _252_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); - } - RAST._IExpr _253_onExpr; - Defs._IOwnership _254_onOwned; - Dafny.ISet> _255_recIdents; - RAST._IExpr _out214; - Defs._IOwnership _out215; - Dafny.ISet> _out216; - (this).GenExpr(_248_on, selfIdent, env, _252_onExpectedOwnership, out _out214, out _out215, out _out216); - _253_onExpr = _out214; - _254_onOwned = _out215; - _255_recIdents = _out216; - readIdents = _255_recIdents; - Dafny.ISequence _256_methodName; - if ((_250_low).is_Some) { - if ((_251_high).is_Some) { - _256_methodName = Dafny.Sequence.UnicodeFromString("slice"); + _255_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); + } + RAST._IExpr _256_onExpr; + Defs._IOwnership _257_onOwned; + Dafny.ISet> _258_recIdents; + RAST._IExpr _out219; + Defs._IOwnership _out220; + Dafny.ISet> _out221; + (this).GenExpr(_251_on, selfIdent, env, _255_onExpectedOwnership, out _out219, out _out220, out _out221); + _256_onExpr = _out219; + _257_onOwned = _out220; + _258_recIdents = _out221; + readIdents = _258_recIdents; + Dafny.ISequence _259_methodName; + if ((_253_low).is_Some) { + if ((_254_high).is_Some) { + _259_methodName = Dafny.Sequence.UnicodeFromString("slice"); } else { - _256_methodName = Dafny.Sequence.UnicodeFromString("drop"); + _259_methodName = Dafny.Sequence.UnicodeFromString("drop"); } - } else if ((_251_high).is_Some) { - _256_methodName = Dafny.Sequence.UnicodeFromString("take"); + } else if ((_254_high).is_Some) { + _259_methodName = Dafny.Sequence.UnicodeFromString("take"); } else { - _256_methodName = Dafny.Sequence.UnicodeFromString(""); + _259_methodName = Dafny.Sequence.UnicodeFromString(""); } - Dafny.ISequence _257_arguments; - _257_arguments = Dafny.Sequence.FromElements(); - Std.Wrappers._IOption _source5 = _250_low; + Dafny.ISequence _260_arguments; + _260_arguments = Dafny.Sequence.FromElements(); + Std.Wrappers._IOption _source5 = _253_low; { if (_source5.is_Some) { - DAST._IExpression _258_l = _source5.dtor_value; + DAST._IExpression _261_l = _source5.dtor_value; { - RAST._IExpr _259_lExpr; - Defs._IOwnership _260___v121; - Dafny.ISet> _261_recIdentsL; - RAST._IExpr _out217; - Defs._IOwnership _out218; - Dafny.ISet> _out219; - (this).GenExpr(_258_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out217, out _out218, out _out219); - _259_lExpr = _out217; - _260___v121 = _out218; - _261_recIdentsL = _out219; - _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_259_lExpr)); - readIdents = Dafny.Set>.Union(readIdents, _261_recIdentsL); + RAST._IExpr _262_lExpr; + Defs._IOwnership _263___v115; + Dafny.ISet> _264_recIdentsL; + RAST._IExpr _out222; + Defs._IOwnership _out223; + Dafny.ISet> _out224; + (this).GenExpr(_261_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out222, out _out223, out _out224); + _262_lExpr = _out222; + _263___v115 = _out223; + _264_recIdentsL = _out224; + _260_arguments = Dafny.Sequence.Concat(_260_arguments, Dafny.Sequence.FromElements(_262_lExpr)); + readIdents = Dafny.Set>.Union(readIdents, _264_recIdentsL); } goto after_match5; } @@ -6118,23 +6192,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match5: ; - Std.Wrappers._IOption _source6 = _251_high; + Std.Wrappers._IOption _source6 = _254_high; { if (_source6.is_Some) { - DAST._IExpression _262_h = _source6.dtor_value; + DAST._IExpression _265_h = _source6.dtor_value; { - RAST._IExpr _263_hExpr; - Defs._IOwnership _264___v122; - Dafny.ISet> _265_recIdentsH; - RAST._IExpr _out220; - Defs._IOwnership _out221; - Dafny.ISet> _out222; - (this).GenExpr(_262_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out220, out _out221, out _out222); - _263_hExpr = _out220; - _264___v122 = _out221; - _265_recIdentsH = _out222; - _257_arguments = Dafny.Sequence.Concat(_257_arguments, Dafny.Sequence.FromElements(_263_hExpr)); - readIdents = Dafny.Set>.Union(readIdents, _265_recIdentsH); + RAST._IExpr _266_hExpr; + Defs._IOwnership _267___v116; + Dafny.ISet> _268_recIdentsH; + RAST._IExpr _out225; + Defs._IOwnership _out226; + Dafny.ISet> _out227; + (this).GenExpr(_265_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out225, out _out226, out _out227); + _266_hExpr = _out225; + _267___v116 = _out226; + _268_recIdentsH = _out227; + _260_arguments = Dafny.Sequence.Concat(_260_arguments, Dafny.Sequence.FromElements(_266_hExpr)); + readIdents = Dafny.Set>.Union(readIdents, _268_recIdentsH); } goto after_match6; } @@ -6142,30 +6216,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match6: ; - r = _253_onExpr; - if (_249_isArray) { - if (!(_256_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - _256_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _256_methodName); + r = _256_onExpr; + if (_252_isArray) { + if (!(_259_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + _259_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _259_methodName); } - Dafny.ISequence _266_object__suffix; + Dafny.ISequence _269_object__suffix; if (((this).pointerType).is_Raw) { - _266_object__suffix = Dafny.Sequence.UnicodeFromString(""); + _269_object__suffix = Dafny.Sequence.UnicodeFromString(""); } else { - _266_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); + _269_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); } - r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _256_methodName), _266_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_253_onExpr), _257_arguments)); + r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _259_methodName), _269_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_256_onExpr), _260_arguments)); } else { - if (!(_256_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - r = ((r).Sel(_256_methodName)).Apply(_257_arguments); + if (!(_259_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + r = ((r).Sel(_259_methodName)).Apply(_260_arguments); } else { r = (r).Clone(); } } - RAST._IExpr _out223; - Defs._IOwnership _out224; - (this).FromOwned(r, expectedOwnership, out _out223, out _out224); - r = _out223; - resultingOwnership = _out224; + RAST._IExpr _out228; + Defs._IOwnership _out229; + (this).FromOwned(r, expectedOwnership, out _out228, out _out229); + r = _out228; + resultingOwnership = _out229; return ; } goto after_match0; @@ -6173,28 +6247,28 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TupleSelect) { - DAST._IExpression _267_on = _source0.dtor_expr; - BigInteger _268_idx = _source0.dtor_index; - DAST._IType _269_fieldType = _source0.dtor_fieldType; + DAST._IExpression _270_on = _source0.dtor_expr; + BigInteger _271_idx = _source0.dtor_index; + DAST._IType _272_fieldType = _source0.dtor_fieldType; { - RAST._IExpr _270_onExpr; - Defs._IOwnership _271_onOwnership; - Dafny.ISet> _272_recIdents; - RAST._IExpr _out225; - Defs._IOwnership _out226; - Dafny.ISet> _out227; - (this).GenExpr(_267_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out225, out _out226, out _out227); - _270_onExpr = _out225; - _271_onOwnership = _out226; - _272_recIdents = _out227; - Dafny.ISequence _273_selName; - _273_selName = Std.Strings.__default.OfNat(_268_idx); - DAST._IType _source7 = _269_fieldType; + RAST._IExpr _273_onExpr; + Defs._IOwnership _274_onOwnership; + Dafny.ISet> _275_recIdents; + RAST._IExpr _out230; + Defs._IOwnership _out231; + Dafny.ISet> _out232; + (this).GenExpr(_270_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out230, out _out231, out _out232); + _273_onExpr = _out230; + _274_onOwnership = _out231; + _275_recIdents = _out232; + Dafny.ISequence _276_selName; + _276_selName = Std.Strings.__default.OfNat(_271_idx); + DAST._IType _source7 = _272_fieldType; { if (_source7.is_Tuple) { - Dafny.ISequence _274_tps = _source7.dtor_Tuple_a0; - if (((_269_fieldType).is_Tuple) && ((new BigInteger((_274_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { - _273_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _273_selName); + Dafny.ISequence _277_tps = _source7.dtor_Tuple_a0; + if (((_272_fieldType).is_Tuple) && ((new BigInteger((_277_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { + _276_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _276_selName); } goto after_match7; } @@ -6202,13 +6276,13 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match7: ; - r = ((_270_onExpr).Sel(_273_selName)).Clone(); - RAST._IExpr _out228; - Defs._IOwnership _out229; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out228, out _out229); - r = _out228; - resultingOwnership = _out229; - readIdents = _272_recIdents; + r = ((_273_onExpr).Sel(_276_selName)).Clone(); + RAST._IExpr _out233; + Defs._IOwnership _out234; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out233, out _out234); + r = _out233; + resultingOwnership = _out234; + readIdents = _275_recIdents; return ; } goto after_match0; @@ -6216,21 +6290,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Call) { - DAST._IExpression _275_on = _source0.dtor_on; - DAST._ICallName _276_name = _source0.dtor_callName; - Dafny.ISequence _277_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _278_args = _source0.dtor_args; + DAST._IExpression _278_on = _source0.dtor_on; + DAST._ICallName _279_name = _source0.dtor_callName; + Dafny.ISequence _280_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _281_args = _source0.dtor_args; { - RAST._IExpr _out230; - Dafny.ISet> _out231; - (this).GenOwnedCallPart(_275_on, selfIdent, _276_name, _277_typeArgs, _278_args, env, out _out230, out _out231); - r = _out230; - readIdents = _out231; - RAST._IExpr _out232; - Defs._IOwnership _out233; - (this).FromOwned(r, expectedOwnership, out _out232, out _out233); - r = _out232; - resultingOwnership = _out233; + RAST._IExpr _out235; + Dafny.ISet> _out236; + (this).GenOwnedCallPart(_278_on, selfIdent, _279_name, _280_typeArgs, _281_args, env, out _out235, out _out236); + r = _out235; + readIdents = _out236; + RAST._IExpr _out237; + Defs._IOwnership _out238; + (this).FromOwned(r, expectedOwnership, out _out237, out _out238); + r = _out237; + resultingOwnership = _out238; return ; } goto after_match0; @@ -6238,90 +6312,90 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Lambda) { - Dafny.ISequence _279_paramsDafny = _source0.dtor_params; - DAST._IType _280_retType = _source0.dtor_retType; - Dafny.ISequence _281_body = _source0.dtor_body; + Dafny.ISequence _282_paramsDafny = _source0.dtor_params; + DAST._IType _283_retType = _source0.dtor_retType; + Dafny.ISequence _284_body = _source0.dtor_body; { - Dafny.ISequence _282_params; - Dafny.ISequence _out234; - _out234 = (this).GenParams(_279_paramsDafny, true); - _282_params = _out234; - Dafny.ISequence> _283_paramNames; - _283_paramNames = Dafny.Sequence>.FromElements(); - Dafny.IMap,RAST._IType> _284_paramTypesMap; - _284_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); - BigInteger _hi11 = new BigInteger((_282_params).Count); - for (BigInteger _285_i = BigInteger.Zero; _285_i < _hi11; _285_i++) { - Dafny.ISequence _286_name; - _286_name = ((_282_params).Select(_285_i)).dtor_name; - _283_paramNames = Dafny.Sequence>.Concat(_283_paramNames, Dafny.Sequence>.FromElements(_286_name)); - _284_paramTypesMap = Dafny.Map, RAST._IType>.Update(_284_paramTypesMap, _286_name, ((_282_params).Select(_285_i)).dtor_tpe); - } - Defs._IEnvironment _287_subEnv; - _287_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_283_paramNames, _284_paramTypesMap, Dafny.Set>.FromElements())); - RAST._IExpr _288_recursiveGen; - Dafny.ISet> _289_recIdents; - Defs._IEnvironment _290___v124; - RAST._IExpr _out235; - Dafny.ISet> _out236; - Defs._IEnvironment _out237; - (this).GenStmts(_281_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _287_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out235, out _out236, out _out237); - _288_recursiveGen = _out235; - _289_recIdents = _out236; - _290___v124 = _out237; + Dafny.ISequence _285_params; + Dafny.ISequence _out239; + _out239 = (this).GenParams(_282_paramsDafny, true); + _285_params = _out239; + Dafny.ISequence> _286_paramNames; + _286_paramNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _287_paramTypesMap; + _287_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); + BigInteger _hi11 = new BigInteger((_285_params).Count); + for (BigInteger _288_i = BigInteger.Zero; _288_i < _hi11; _288_i++) { + Dafny.ISequence _289_name; + _289_name = ((_285_params).Select(_288_i)).dtor_name; + _286_paramNames = Dafny.Sequence>.Concat(_286_paramNames, Dafny.Sequence>.FromElements(_289_name)); + _287_paramTypesMap = Dafny.Map, RAST._IType>.Update(_287_paramTypesMap, _289_name, ((_285_params).Select(_288_i)).dtor_tpe); + } + Defs._IEnvironment _290_subEnv; + _290_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_286_paramNames, _287_paramTypesMap, Dafny.Set>.FromElements())); + RAST._IExpr _291_recursiveGen; + Dafny.ISet> _292_recIdents; + Defs._IEnvironment _293___v118; + RAST._IExpr _out240; + Dafny.ISet> _out241; + Defs._IEnvironment _out242; + (this).GenStmts(_284_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _290_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out240, out _out241, out _out242); + _291_recursiveGen = _out240; + _292_recIdents = _out241; + _293___v118 = _out242; readIdents = Dafny.Set>.FromElements(); - _289_recIdents = Dafny.Set>.Difference(_289_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_291_paramNames) => ((System.Func>>)(() => { + _292_recIdents = Dafny.Set>.Difference(_292_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_294_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); - foreach (Dafny.ISequence _compr_0 in (_291_paramNames).CloneAsArray()) { - Dafny.ISequence _292_name = (Dafny.ISequence)_compr_0; - if ((_291_paramNames).Contains(_292_name)) { - _coll0.Add(_292_name); + foreach (Dafny.ISequence _compr_0 in (_294_paramNames).CloneAsArray()) { + Dafny.ISequence _295_name = (Dafny.ISequence)_compr_0; + if ((_294_paramNames).Contains(_295_name)) { + _coll0.Add(_295_name); } } return Dafny.Set>.FromCollection(_coll0); - }))())(_283_paramNames)); - RAST._IExpr _293_allReadCloned; - _293_allReadCloned = (this).InitEmptyExpr(); - while (!(_289_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _294_next; - foreach (Dafny.ISequence _assign_such_that_1 in (_289_recIdents).Elements) { - _294_next = (Dafny.ISequence)_assign_such_that_1; - if ((_289_recIdents).Contains(_294_next)) { + }))())(_286_paramNames)); + RAST._IExpr _296_allReadCloned; + _296_allReadCloned = (this).InitEmptyExpr(); + while (!(_292_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _297_next; + foreach (Dafny.ISequence _assign_such_that_1 in (_292_recIdents).Elements) { + _297_next = (Dafny.ISequence)_assign_such_that_1; + if ((_292_recIdents).Contains(_297_next)) { goto after__ASSIGN_SUCH_THAT_1; } } throw new System.Exception("assign-such-that search produced no value"); after__ASSIGN_SUCH_THAT_1: ; - if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_294_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { - RAST._IExpr _295_selfCloned; - Defs._IOwnership _296___v125; - Dafny.ISet> _297___v126; - RAST._IExpr _out238; - Defs._IOwnership _out239; - Dafny.ISet> _out240; - (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out238, out _out239, out _out240); - _295_selfCloned = _out238; - _296___v125 = _out239; - _297___v126 = _out240; - _293_allReadCloned = (_293_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_295_selfCloned))); - } else if (!((_283_paramNames).Contains(_294_next))) { - RAST._IExpr _298_copy; - _298_copy = (RAST.Expr.create_Identifier(_294_next)).Clone(); - _293_allReadCloned = (_293_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _294_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_298_copy))); - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_294_next)); + if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_297_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { + RAST._IExpr _298_selfCloned; + Defs._IOwnership _299___v119; + Dafny.ISet> _300___v120; + RAST._IExpr _out243; + Defs._IOwnership _out244; + Dafny.ISet> _out245; + (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out243, out _out244, out _out245); + _298_selfCloned = _out243; + _299___v119 = _out244; + _300___v120 = _out245; + _296_allReadCloned = (_296_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_298_selfCloned))); + } else if (!((_286_paramNames).Contains(_297_next))) { + RAST._IExpr _301_copy; + _301_copy = (RAST.Expr.create_Identifier(_297_next)).Clone(); + _296_allReadCloned = (_296_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _297_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_301_copy))); + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_297_next)); } - _289_recIdents = Dafny.Set>.Difference(_289_recIdents, Dafny.Set>.FromElements(_294_next)); - } - RAST._IType _299_retTypeGen; - RAST._IType _out241; - _out241 = (this).GenType(_280_retType, Defs.GenTypeContext.@default()); - _299_retTypeGen = _out241; - r = RAST.Expr.create_Block((_293_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_282_params, Std.Wrappers.Option.create_Some(_299_retTypeGen), RAST.Expr.create_Block(_288_recursiveGen))))); - RAST._IExpr _out242; - Defs._IOwnership _out243; - (this).FromOwned(r, expectedOwnership, out _out242, out _out243); - r = _out242; - resultingOwnership = _out243; + _292_recIdents = Dafny.Set>.Difference(_292_recIdents, Dafny.Set>.FromElements(_297_next)); + } + RAST._IType _302_retTypeGen; + RAST._IType _out246; + _out246 = (this).GenType(_283_retType, Defs.GenTypeContext.@default()); + _302_retTypeGen = _out246; + r = RAST.Expr.create_Block((_296_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_285_params, Std.Wrappers.Option.create_Some(_302_retTypeGen), RAST.Expr.create_Block(_291_recursiveGen))))); + RAST._IExpr _out247; + Defs._IOwnership _out248; + (this).FromOwned(r, expectedOwnership, out _out247, out _out248); + r = _out247; + resultingOwnership = _out248; return ; } goto after_match0; @@ -6329,72 +6403,72 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_BetaRedex) { - Dafny.ISequence<_System._ITuple2> _300_values = _source0.dtor_values; - DAST._IType _301_retType = _source0.dtor_retType; - DAST._IExpression _302_expr = _source0.dtor_expr; + Dafny.ISequence<_System._ITuple2> _303_values = _source0.dtor_values; + DAST._IType _304_retType = _source0.dtor_retType; + DAST._IExpression _305_expr = _source0.dtor_expr; { - Dafny.ISequence> _303_paramNames; - _303_paramNames = Dafny.Sequence>.FromElements(); - Dafny.ISequence _304_paramFormals; - Dafny.ISequence _out244; - _out244 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_305_value) => { - return (_305_value).dtor__0; - })), _300_values), false); - _304_paramFormals = _out244; - Dafny.IMap,RAST._IType> _306_paramTypes; - _306_paramTypes = Dafny.Map, RAST._IType>.FromElements(); - Dafny.ISet> _307_paramNamesSet; - _307_paramNamesSet = Dafny.Set>.FromElements(); - BigInteger _hi12 = new BigInteger((_300_values).Count); - for (BigInteger _308_i = BigInteger.Zero; _308_i < _hi12; _308_i++) { - Dafny.ISequence _309_name; - _309_name = (((_300_values).Select(_308_i)).dtor__0).dtor_name; - Dafny.ISequence _310_rName; - _310_rName = Defs.__default.escapeVar(_309_name); - _303_paramNames = Dafny.Sequence>.Concat(_303_paramNames, Dafny.Sequence>.FromElements(_310_rName)); - _306_paramTypes = Dafny.Map, RAST._IType>.Update(_306_paramTypes, _310_rName, ((_304_paramFormals).Select(_308_i)).dtor_tpe); - _307_paramNamesSet = Dafny.Set>.Union(_307_paramNamesSet, Dafny.Set>.FromElements(_310_rName)); + Dafny.ISequence> _306_paramNames; + _306_paramNames = Dafny.Sequence>.FromElements(); + Dafny.ISequence _307_paramFormals; + Dafny.ISequence _out249; + _out249 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_308_value) => { + return (_308_value).dtor__0; + })), _303_values), false); + _307_paramFormals = _out249; + Dafny.IMap,RAST._IType> _309_paramTypes; + _309_paramTypes = Dafny.Map, RAST._IType>.FromElements(); + Dafny.ISet> _310_paramNamesSet; + _310_paramNamesSet = Dafny.Set>.FromElements(); + BigInteger _hi12 = new BigInteger((_303_values).Count); + for (BigInteger _311_i = BigInteger.Zero; _311_i < _hi12; _311_i++) { + Dafny.ISequence _312_name; + _312_name = (((_303_values).Select(_311_i)).dtor__0).dtor_name; + Dafny.ISequence _313_rName; + _313_rName = Defs.__default.escapeVar(_312_name); + _306_paramNames = Dafny.Sequence>.Concat(_306_paramNames, Dafny.Sequence>.FromElements(_313_rName)); + _309_paramTypes = Dafny.Map, RAST._IType>.Update(_309_paramTypes, _313_rName, ((_307_paramFormals).Select(_311_i)).dtor_tpe); + _310_paramNamesSet = Dafny.Set>.Union(_310_paramNamesSet, Dafny.Set>.FromElements(_313_rName)); } readIdents = Dafny.Set>.FromElements(); r = (this).InitEmptyExpr(); - BigInteger _hi13 = new BigInteger((_300_values).Count); - for (BigInteger _311_i = BigInteger.Zero; _311_i < _hi13; _311_i++) { - RAST._IType _312_typeGen; - RAST._IType _out245; - _out245 = (this).GenType((((_300_values).Select(_311_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); - _312_typeGen = _out245; - RAST._IExpr _313_valueGen; - Defs._IOwnership _314___v127; - Dafny.ISet> _315_recIdents; - RAST._IExpr _out246; - Defs._IOwnership _out247; - Dafny.ISet> _out248; - (this).GenExpr(((_300_values).Select(_311_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out246, out _out247, out _out248); - _313_valueGen = _out246; - _314___v127 = _out247; - _315_recIdents = _out248; - r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_300_values).Select(_311_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_312_typeGen), Std.Wrappers.Option.create_Some(_313_valueGen))); - readIdents = Dafny.Set>.Union(readIdents, _315_recIdents); - } - Defs._IEnvironment _316_newEnv; - _316_newEnv = Defs.Environment.create(_303_paramNames, _306_paramTypes, Dafny.Set>.FromElements()); - RAST._IExpr _317_recGen; - Defs._IOwnership _318_recOwned; - Dafny.ISet> _319_recIdents; - RAST._IExpr _out249; - Defs._IOwnership _out250; - Dafny.ISet> _out251; - (this).GenExpr(_302_expr, selfIdent, _316_newEnv, expectedOwnership, out _out249, out _out250, out _out251); - _317_recGen = _out249; - _318_recOwned = _out250; - _319_recIdents = _out251; - readIdents = Dafny.Set>.Difference(_319_recIdents, _307_paramNamesSet); - r = RAST.Expr.create_Block((r).Then(_317_recGen)); - RAST._IExpr _out252; - Defs._IOwnership _out253; - (this).FromOwnership(r, _318_recOwned, expectedOwnership, out _out252, out _out253); - r = _out252; - resultingOwnership = _out253; + BigInteger _hi13 = new BigInteger((_303_values).Count); + for (BigInteger _314_i = BigInteger.Zero; _314_i < _hi13; _314_i++) { + RAST._IType _315_typeGen; + RAST._IType _out250; + _out250 = (this).GenType((((_303_values).Select(_314_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); + _315_typeGen = _out250; + RAST._IExpr _316_valueGen; + Defs._IOwnership _317___v121; + Dafny.ISet> _318_recIdents; + RAST._IExpr _out251; + Defs._IOwnership _out252; + Dafny.ISet> _out253; + (this).GenExpr(((_303_values).Select(_314_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out251, out _out252, out _out253); + _316_valueGen = _out251; + _317___v121 = _out252; + _318_recIdents = _out253; + r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_303_values).Select(_314_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_315_typeGen), Std.Wrappers.Option.create_Some(_316_valueGen))); + readIdents = Dafny.Set>.Union(readIdents, _318_recIdents); + } + Defs._IEnvironment _319_newEnv; + _319_newEnv = Defs.Environment.create(_306_paramNames, _309_paramTypes, Dafny.Set>.FromElements()); + RAST._IExpr _320_recGen; + Defs._IOwnership _321_recOwned; + Dafny.ISet> _322_recIdents; + RAST._IExpr _out254; + Defs._IOwnership _out255; + Dafny.ISet> _out256; + (this).GenExpr(_305_expr, selfIdent, _319_newEnv, expectedOwnership, out _out254, out _out255, out _out256); + _320_recGen = _out254; + _321_recOwned = _out255; + _322_recIdents = _out256; + readIdents = Dafny.Set>.Difference(_322_recIdents, _310_paramNamesSet); + r = RAST.Expr.create_Block((r).Then(_320_recGen)); + RAST._IExpr _out257; + Defs._IOwnership _out258; + (this).FromOwnership(r, _321_recOwned, expectedOwnership, out _out257, out _out258); + r = _out257; + resultingOwnership = _out258; return ; } goto after_match0; @@ -6402,45 +6476,45 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IIFE) { - Dafny.ISequence _320_name = _source0.dtor_ident; - DAST._IType _321_tpe = _source0.dtor_typ; - DAST._IExpression _322_value = _source0.dtor_value; - DAST._IExpression _323_iifeBody = _source0.dtor_iifeBody; + Dafny.ISequence _323_name = _source0.dtor_ident; + DAST._IType _324_tpe = _source0.dtor_typ; + DAST._IExpression _325_value = _source0.dtor_value; + DAST._IExpression _326_iifeBody = _source0.dtor_iifeBody; { - RAST._IExpr _324_valueGen; - Defs._IOwnership _325___v128; - Dafny.ISet> _326_recIdents; - RAST._IExpr _out254; - Defs._IOwnership _out255; - Dafny.ISet> _out256; - (this).GenExpr(_322_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out254, out _out255, out _out256); - _324_valueGen = _out254; - _325___v128 = _out255; - _326_recIdents = _out256; - readIdents = _326_recIdents; - RAST._IType _327_valueTypeGen; - RAST._IType _out257; - _out257 = (this).GenType(_321_tpe, Defs.GenTypeContext.@default()); - _327_valueTypeGen = _out257; - Dafny.ISequence _328_iifeVar; - _328_iifeVar = Defs.__default.escapeVar(_320_name); - RAST._IExpr _329_bodyGen; - Defs._IOwnership _330___v129; - Dafny.ISet> _331_bodyIdents; - RAST._IExpr _out258; - Defs._IOwnership _out259; - Dafny.ISet> _out260; - (this).GenExpr(_323_iifeBody, selfIdent, (env).AddAssigned(_328_iifeVar, _327_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out258, out _out259, out _out260); - _329_bodyGen = _out258; - _330___v129 = _out259; - _331_bodyIdents = _out260; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_331_bodyIdents, Dafny.Set>.FromElements(_328_iifeVar))); - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _328_iifeVar, Std.Wrappers.Option.create_Some(_327_valueTypeGen), Std.Wrappers.Option.create_Some(_324_valueGen))).Then(_329_bodyGen)); - RAST._IExpr _out261; - Defs._IOwnership _out262; - (this).FromOwned(r, expectedOwnership, out _out261, out _out262); - r = _out261; - resultingOwnership = _out262; + RAST._IExpr _327_valueGen; + Defs._IOwnership _328___v122; + Dafny.ISet> _329_recIdents; + RAST._IExpr _out259; + Defs._IOwnership _out260; + Dafny.ISet> _out261; + (this).GenExpr(_325_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out259, out _out260, out _out261); + _327_valueGen = _out259; + _328___v122 = _out260; + _329_recIdents = _out261; + readIdents = _329_recIdents; + RAST._IType _330_valueTypeGen; + RAST._IType _out262; + _out262 = (this).GenType(_324_tpe, Defs.GenTypeContext.@default()); + _330_valueTypeGen = _out262; + Dafny.ISequence _331_iifeVar; + _331_iifeVar = Defs.__default.escapeVar(_323_name); + RAST._IExpr _332_bodyGen; + Defs._IOwnership _333___v123; + Dafny.ISet> _334_bodyIdents; + RAST._IExpr _out263; + Defs._IOwnership _out264; + Dafny.ISet> _out265; + (this).GenExpr(_326_iifeBody, selfIdent, (env).AddAssigned(_331_iifeVar, _330_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out263, out _out264, out _out265); + _332_bodyGen = _out263; + _333___v123 = _out264; + _334_bodyIdents = _out265; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_334_bodyIdents, Dafny.Set>.FromElements(_331_iifeVar))); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _331_iifeVar, Std.Wrappers.Option.create_Some(_330_valueTypeGen), Std.Wrappers.Option.create_Some(_327_valueGen))).Then(_332_bodyGen)); + RAST._IExpr _out266; + Defs._IOwnership _out267; + (this).FromOwned(r, expectedOwnership, out _out266, out _out267); + r = _out266; + resultingOwnership = _out267; return ; } goto after_match0; @@ -6448,43 +6522,43 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Apply) { - DAST._IExpression _332_func = _source0.dtor_expr; - Dafny.ISequence _333_args = _source0.dtor_args; + DAST._IExpression _335_func = _source0.dtor_expr; + Dafny.ISequence _336_args = _source0.dtor_args; { - RAST._IExpr _334_funcExpr; - Defs._IOwnership _335___v130; - Dafny.ISet> _336_recIdents; - RAST._IExpr _out263; - Defs._IOwnership _out264; - Dafny.ISet> _out265; - (this).GenExpr(_332_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out263, out _out264, out _out265); - _334_funcExpr = _out263; - _335___v130 = _out264; - _336_recIdents = _out265; - readIdents = _336_recIdents; - Dafny.ISequence _337_rArgs; - _337_rArgs = Dafny.Sequence.FromElements(); - BigInteger _hi14 = new BigInteger((_333_args).Count); - for (BigInteger _338_i = BigInteger.Zero; _338_i < _hi14; _338_i++) { - RAST._IExpr _339_argExpr; - Defs._IOwnership _340_argOwned; - Dafny.ISet> _341_argIdents; - RAST._IExpr _out266; - Defs._IOwnership _out267; - Dafny.ISet> _out268; - (this).GenExpr((_333_args).Select(_338_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out266, out _out267, out _out268); - _339_argExpr = _out266; - _340_argOwned = _out267; - _341_argIdents = _out268; - _337_rArgs = Dafny.Sequence.Concat(_337_rArgs, Dafny.Sequence.FromElements(_339_argExpr)); - readIdents = Dafny.Set>.Union(readIdents, _341_argIdents); - } - r = (_334_funcExpr).Apply(_337_rArgs); - RAST._IExpr _out269; - Defs._IOwnership _out270; - (this).FromOwned(r, expectedOwnership, out _out269, out _out270); - r = _out269; - resultingOwnership = _out270; + RAST._IExpr _337_funcExpr; + Defs._IOwnership _338___v124; + Dafny.ISet> _339_recIdents; + RAST._IExpr _out268; + Defs._IOwnership _out269; + Dafny.ISet> _out270; + (this).GenExpr(_335_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out268, out _out269, out _out270); + _337_funcExpr = _out268; + _338___v124 = _out269; + _339_recIdents = _out270; + readIdents = _339_recIdents; + Dafny.ISequence _340_rArgs; + _340_rArgs = Dafny.Sequence.FromElements(); + BigInteger _hi14 = new BigInteger((_336_args).Count); + for (BigInteger _341_i = BigInteger.Zero; _341_i < _hi14; _341_i++) { + RAST._IExpr _342_argExpr; + Defs._IOwnership _343_argOwned; + Dafny.ISet> _344_argIdents; + RAST._IExpr _out271; + Defs._IOwnership _out272; + Dafny.ISet> _out273; + (this).GenExpr((_336_args).Select(_341_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out271, out _out272, out _out273); + _342_argExpr = _out271; + _343_argOwned = _out272; + _344_argIdents = _out273; + _340_rArgs = Dafny.Sequence.Concat(_340_rArgs, Dafny.Sequence.FromElements(_342_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _344_argIdents); + } + r = (_337_funcExpr).Apply(_340_rArgs); + RAST._IExpr _out274; + Defs._IOwnership _out275; + (this).FromOwned(r, expectedOwnership, out _out274, out _out275); + r = _out274; + resultingOwnership = _out275; return ; } goto after_match0; @@ -6492,31 +6566,31 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TypeTest) { - DAST._IExpression _342_on = _source0.dtor_on; - Dafny.ISequence> _343_dType = _source0.dtor_dType; - Dafny.ISequence _344_variant = _source0.dtor_variant; + DAST._IExpression _345_on = _source0.dtor_on; + Dafny.ISequence> _346_dType = _source0.dtor_dType; + Dafny.ISequence _347_variant = _source0.dtor_variant; { - RAST._IExpr _345_exprGen; - Defs._IOwnership _346___v131; - Dafny.ISet> _347_recIdents; - RAST._IExpr _out271; - Defs._IOwnership _out272; - Dafny.ISet> _out273; - (this).GenExpr(_342_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out271, out _out272, out _out273); - _345_exprGen = _out271; - _346___v131 = _out272; - _347_recIdents = _out273; - RAST._IExpr _348_variantExprPath; - RAST._IExpr _out274; - _out274 = (this).GenPathExpr(Dafny.Sequence>.Concat(_343_dType, Dafny.Sequence>.FromElements(_344_variant)), true); - _348_variantExprPath = _out274; - r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_345_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _348_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); - RAST._IExpr _out275; - Defs._IOwnership _out276; - (this).FromOwned(r, expectedOwnership, out _out275, out _out276); - r = _out275; - resultingOwnership = _out276; - readIdents = _347_recIdents; + RAST._IExpr _348_exprGen; + Defs._IOwnership _349___v125; + Dafny.ISet> _350_recIdents; + RAST._IExpr _out276; + Defs._IOwnership _out277; + Dafny.ISet> _out278; + (this).GenExpr(_345_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out276, out _out277, out _out278); + _348_exprGen = _out276; + _349___v125 = _out277; + _350_recIdents = _out278; + RAST._IExpr _351_variantExprPath; + RAST._IExpr _out279; + _out279 = (this).GenPathExpr(Dafny.Sequence>.Concat(_346_dType, Dafny.Sequence>.FromElements(_347_variant)), true); + _351_variantExprPath = _out279; + r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_348_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _351_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); + RAST._IExpr _out280; + Defs._IOwnership _out281; + (this).FromOwned(r, expectedOwnership, out _out280, out _out281); + r = _out280; + resultingOwnership = _out281; + readIdents = _350_recIdents; return ; } goto after_match0; @@ -6524,76 +6598,96 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Is) { - DAST._IExpression _349_expr = _source0.dtor_expr; - DAST._IType _350_fromTyp = _source0.dtor_fromType; - DAST._IType _351_toTyp = _source0.dtor_toType; + DAST._IExpression _352_expr = _source0.dtor_expr; + DAST._IType _353_fromTyp = _source0.dtor_fromType; + DAST._IType _354_toTyp = _source0.dtor_toType; { - RAST._IExpr _352_expr; - Defs._IOwnership _353_recOwned; - Dafny.ISet> _354_recIdents; - RAST._IExpr _out277; - Defs._IOwnership _out278; - Dafny.ISet> _out279; - (this).GenExpr(_349_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out277, out _out278, out _out279); - _352_expr = _out277; - _353_recOwned = _out278; - _354_recIdents = _out279; RAST._IType _355_fromTpe; - RAST._IType _out280; - _out280 = (this).GenType(_350_fromTyp, Defs.GenTypeContext.@default()); - _355_fromTpe = _out280; + RAST._IType _out282; + _out282 = (this).GenType(_353_fromTyp, Defs.GenTypeContext.@default()); + _355_fromTpe = _out282; RAST._IType _356_toTpe; - RAST._IType _out281; - _out281 = (this).GenType(_351_toTyp, Defs.GenTypeContext.@default()); - _356_toTpe = _out281; + RAST._IType _out283; + _out283 = (this).GenType(_354_toTyp, Defs.GenTypeContext.@default()); + _356_toTpe = _out283; if (((_355_fromTpe).IsObjectOrPointer()) && ((_356_toTpe).IsObjectOrPointer())) { - r = (((_352_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_356_toTpe).ObjectOrPointerUnderlying()))).Apply0(); + RAST._IExpr _357_expr; + Defs._IOwnership _358_recOwned; + Dafny.ISet> _359_recIdents; + RAST._IExpr _out284; + Defs._IOwnership _out285; + Dafny.ISet> _out286; + (this).GenExpr(_352_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out284, out _out285, out _out286); + _357_expr = _out284; + _358_recOwned = _out285; + _359_recIdents = _out286; + r = (((_357_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_356_toTpe).ObjectOrPointerUnderlying()))).Apply0(); + RAST._IExpr _out287; + Defs._IOwnership _out288; + (this).FromOwnership(r, _358_recOwned, expectedOwnership, out _out287, out _out288); + r = _out287; + resultingOwnership = _out288; + readIdents = _359_recIdents; } else { - bool _357_isDatatype; - _357_isDatatype = (_351_toTyp).IsDatatype(); - bool _358_isGeneralTrait; - _358_isGeneralTrait = (!(_357_isDatatype)) && ((_351_toTyp).IsGeneralTrait()); - if ((_357_isDatatype) || (_358_isGeneralTrait)) { - bool _359_isDowncast; - _359_isDowncast = (_351_toTyp).Extends(_350_fromTyp); - if (_359_isDowncast) { - DAST._IType _360_underlyingType; - if (_357_isDatatype) { - _360_underlyingType = (_351_toTyp).GetDatatypeType(); + RAST._IExpr _360_expr; + Defs._IOwnership _361_recOwned; + Dafny.ISet> _362_recIdents; + RAST._IExpr _out289; + Defs._IOwnership _out290; + Dafny.ISet> _out291; + (this).GenExpr(_352_expr, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out289, out _out290, out _out291); + _360_expr = _out289; + _361_recOwned = _out290; + _362_recIdents = _out291; + bool _363_isDatatype; + _363_isDatatype = (_354_toTyp).IsDatatype(); + bool _364_isGeneralTrait; + _364_isGeneralTrait = (!(_363_isDatatype)) && ((_354_toTyp).IsGeneralTrait()); + if ((_363_isDatatype) || (_364_isGeneralTrait)) { + bool _365_isDowncast; + _365_isDowncast = (_354_toTyp).Extends(_353_fromTyp); + if (_365_isDowncast) { + DAST._IType _366_underlyingType; + if (_363_isDatatype) { + _366_underlyingType = (_354_toTyp).GetDatatypeType(); } else { - _360_underlyingType = (_351_toTyp).GetGeneralTraitType(); + _366_underlyingType = (_354_toTyp).GetGeneralTraitType(); } - RAST._IType _361_toTpeRaw; - RAST._IType _out282; - _out282 = (this).GenType(_360_underlyingType, Defs.GenTypeContext.@default()); - _361_toTpeRaw = _out282; - Std.Wrappers._IOption _362_toTpeRawDowncastOpt; - _362_toTpeRawDowncastOpt = (_361_toTpeRaw).ToDowncastExpr(); - if ((_362_toTpeRawDowncastOpt).is_Some) { - r = (((_362_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_352_expr); - _353_recOwned = Defs.Ownership.create_OwnershipOwned(); + RAST._IType _367_toTpeRaw; + RAST._IType _out292; + _out292 = (this).GenType(_366_underlyingType, Defs.GenTypeContext.@default()); + _367_toTpeRaw = _out292; + Std.Wrappers._IOption _368_toTpeRawDowncastOpt; + _368_toTpeRawDowncastOpt = (_367_toTpeRaw).ToDowncastExpr(); + if ((_368_toTpeRawDowncastOpt).is_Some) { + _360_expr = (this).FromGeneralBorrowToSelfBorrow(_360_expr, Defs.Ownership.create_OwnershipBorrowed(), env); + if (_363_isDatatype) { + _360_expr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_360_expr); + } + r = (((_368_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_360_expr); + _361_recOwned = Defs.Ownership.create_OwnershipOwned(); } else { - RAST._IExpr _out283; - _out283 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_361_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); - r = _out283; + RAST._IExpr _out293; + _out293 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_367_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); + r = _out293; } } else { - RAST._IExpr _out284; - _out284 = (this).Error(Dafny.Sequence.UnicodeFromString("Needs support for upcasting general traits"), (this).InitEmptyExpr()); - r = _out284; + RAST._IExpr _out294; + _out294 = (this).Error(Dafny.Sequence.UnicodeFromString("Needs support for upcasting general traits"), (this).InitEmptyExpr()); + r = _out294; } } else { - RAST._IExpr _out285; - _out285 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"), (this).InitEmptyExpr()); - r = _out285; + RAST._IExpr _out295; + _out295 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"), (this).InitEmptyExpr()); + r = _out295; } + RAST._IExpr _out296; + Defs._IOwnership _out297; + (this).FromOwnership(r, _361_recOwned, expectedOwnership, out _out296, out _out297); + r = _out296; + resultingOwnership = _out297; + readIdents = _362_recIdents; } - RAST._IExpr _out286; - Defs._IOwnership _out287; - (this).FromOwnership(r, _353_recOwned, expectedOwnership, out _out286, out _out287); - r = _out286; - resultingOwnership = _out287; - readIdents = _354_recIdents; return ; } goto after_match0; @@ -6603,198 +6697,198 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_BoolBoundedPool) { { r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("[false, true]")); - RAST._IExpr _out288; - Defs._IOwnership _out289; - (this).FromOwned(r, expectedOwnership, out _out288, out _out289); - r = _out288; - resultingOwnership = _out289; - readIdents = Dafny.Set>.FromElements(); - return ; - } - goto after_match0; - } - } - { - if (_source0.is_SetBoundedPool) { - DAST._IExpression _363_of = _source0.dtor_of; - { - RAST._IExpr _364_exprGen; - Defs._IOwnership _365___v132; - Dafny.ISet> _366_recIdents; - RAST._IExpr _out290; - Defs._IOwnership _out291; - Dafny.ISet> _out292; - (this).GenExpr(_363_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out290, out _out291, out _out292); - _364_exprGen = _out290; - _365___v132 = _out291; - _366_recIdents = _out292; - r = ((_364_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - RAST._IExpr _out293; - Defs._IOwnership _out294; - (this).FromOwned(r, expectedOwnership, out _out293, out _out294); - r = _out293; - resultingOwnership = _out294; - readIdents = _366_recIdents; - return ; - } - goto after_match0; - } - } - { - if (_source0.is_SeqBoundedPool) { - DAST._IExpression _367_of = _source0.dtor_of; - bool _368_includeDuplicates = _source0.dtor_includeDuplicates; - { - RAST._IExpr _369_exprGen; - Defs._IOwnership _370___v133; - Dafny.ISet> _371_recIdents; - RAST._IExpr _out295; - Defs._IOwnership _out296; - Dafny.ISet> _out297; - (this).GenExpr(_367_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out295, out _out296, out _out297); - _369_exprGen = _out295; - _370___v133 = _out296; - _371_recIdents = _out297; - r = ((_369_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_368_includeDuplicates)) { - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); - } RAST._IExpr _out298; Defs._IOwnership _out299; (this).FromOwned(r, expectedOwnership, out _out298, out _out299); r = _out298; resultingOwnership = _out299; - readIdents = _371_recIdents; + readIdents = Dafny.Set>.FromElements(); return ; } goto after_match0; } } { - if (_source0.is_MultisetBoundedPool) { - DAST._IExpression _372_of = _source0.dtor_of; - bool _373_includeDuplicates = _source0.dtor_includeDuplicates; + if (_source0.is_SetBoundedPool) { + DAST._IExpression _369_of = _source0.dtor_of; { - RAST._IExpr _374_exprGen; - Defs._IOwnership _375___v134; - Dafny.ISet> _376_recIdents; + RAST._IExpr _370_exprGen; + Defs._IOwnership _371___v126; + Dafny.ISet> _372_recIdents; RAST._IExpr _out300; Defs._IOwnership _out301; Dafny.ISet> _out302; - (this).GenExpr(_372_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out300, out _out301, out _out302); - _374_exprGen = _out300; - _375___v134 = _out301; - _376_recIdents = _out302; - r = ((_374_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_373_includeDuplicates)) { - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); - } + (this).GenExpr(_369_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out300, out _out301, out _out302); + _370_exprGen = _out300; + _371___v126 = _out301; + _372_recIdents = _out302; + r = ((_370_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out303; Defs._IOwnership _out304; (this).FromOwned(r, expectedOwnership, out _out303, out _out304); r = _out303; resultingOwnership = _out304; - readIdents = _376_recIdents; + readIdents = _372_recIdents; return ; } goto after_match0; } } { - if (_source0.is_MapBoundedPool) { - DAST._IExpression _377_of = _source0.dtor_of; + if (_source0.is_SeqBoundedPool) { + DAST._IExpression _373_of = _source0.dtor_of; + bool _374_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _378_exprGen; - Defs._IOwnership _379___v135; - Dafny.ISet> _380_recIdents; + RAST._IExpr _375_exprGen; + Defs._IOwnership _376___v127; + Dafny.ISet> _377_recIdents; RAST._IExpr _out305; Defs._IOwnership _out306; Dafny.ISet> _out307; - (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out305, out _out306, out _out307); - _378_exprGen = _out305; - _379___v135 = _out306; - _380_recIdents = _out307; - r = ((((_378_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - readIdents = _380_recIdents; + (this).GenExpr(_373_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out305, out _out306, out _out307); + _375_exprGen = _out305; + _376___v127 = _out306; + _377_recIdents = _out307; + r = ((_375_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_374_includeDuplicates)) { + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); + } RAST._IExpr _out308; Defs._IOwnership _out309; (this).FromOwned(r, expectedOwnership, out _out308, out _out309); r = _out308; resultingOwnership = _out309; + readIdents = _377_recIdents; + return ; } goto after_match0; } } { - if (_source0.is_ExactBoundedPool) { - DAST._IExpression _381_of = _source0.dtor_of; + if (_source0.is_MultisetBoundedPool) { + DAST._IExpression _378_of = _source0.dtor_of; + bool _379_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _382_exprGen; - Defs._IOwnership _383___v136; - Dafny.ISet> _384_recIdents; + RAST._IExpr _380_exprGen; + Defs._IOwnership _381___v128; + Dafny.ISet> _382_recIdents; RAST._IExpr _out310; Defs._IOwnership _out311; Dafny.ISet> _out312; - (this).GenExpr(_381_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out310, out _out311, out _out312); - _382_exprGen = _out310; - _383___v136 = _out311; - _384_recIdents = _out312; - r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_382_exprGen); - readIdents = _384_recIdents; + (this).GenExpr(_378_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out310, out _out311, out _out312); + _380_exprGen = _out310; + _381___v128 = _out311; + _382_recIdents = _out312; + r = ((_380_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_379_includeDuplicates)) { + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); + } RAST._IExpr _out313; Defs._IOwnership _out314; (this).FromOwned(r, expectedOwnership, out _out313, out _out314); r = _out313; resultingOwnership = _out314; + readIdents = _382_recIdents; + return ; } goto after_match0; } } { - if (_source0.is_IntRange) { - DAST._IType _385_typ = _source0.dtor_elemType; - DAST._IExpression _386_lo = _source0.dtor_lo; - DAST._IExpression _387_hi = _source0.dtor_hi; - bool _388_up = _source0.dtor_up; + if (_source0.is_MapBoundedPool) { + DAST._IExpression _383_of = _source0.dtor_of; { - RAST._IExpr _389_lo; - Defs._IOwnership _390___v137; - Dafny.ISet> _391_recIdentsLo; + RAST._IExpr _384_exprGen; + Defs._IOwnership _385___v129; + Dafny.ISet> _386_recIdents; RAST._IExpr _out315; Defs._IOwnership _out316; Dafny.ISet> _out317; - (this).GenExpr(_386_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out315, out _out316, out _out317); - _389_lo = _out315; - _390___v137 = _out316; - _391_recIdentsLo = _out317; - RAST._IExpr _392_hi; - Defs._IOwnership _393___v138; - Dafny.ISet> _394_recIdentsHi; + (this).GenExpr(_383_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out315, out _out316, out _out317); + _384_exprGen = _out315; + _385___v129 = _out316; + _386_recIdents = _out317; + r = ((((_384_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + readIdents = _386_recIdents; RAST._IExpr _out318; Defs._IOwnership _out319; - Dafny.ISet> _out320; - (this).GenExpr(_387_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out318, out _out319, out _out320); - _392_hi = _out318; - _393___v138 = _out319; - _394_recIdentsHi = _out320; - if (_388_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_389_lo, _392_hi)); + (this).FromOwned(r, expectedOwnership, out _out318, out _out319); + r = _out318; + resultingOwnership = _out319; + } + goto after_match0; + } + } + { + if (_source0.is_ExactBoundedPool) { + DAST._IExpression _387_of = _source0.dtor_of; + { + RAST._IExpr _388_exprGen; + Defs._IOwnership _389___v130; + Dafny.ISet> _390_recIdents; + RAST._IExpr _out320; + Defs._IOwnership _out321; + Dafny.ISet> _out322; + (this).GenExpr(_387_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out320, out _out321, out _out322); + _388_exprGen = _out320; + _389___v130 = _out321; + _390_recIdents = _out322; + r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_388_exprGen); + readIdents = _390_recIdents; + RAST._IExpr _out323; + Defs._IOwnership _out324; + (this).FromOwned(r, expectedOwnership, out _out323, out _out324); + r = _out323; + resultingOwnership = _out324; + } + goto after_match0; + } + } + { + if (_source0.is_IntRange) { + DAST._IType _391_typ = _source0.dtor_elemType; + DAST._IExpression _392_lo = _source0.dtor_lo; + DAST._IExpression _393_hi = _source0.dtor_hi; + bool _394_up = _source0.dtor_up; + { + RAST._IExpr _395_lo; + Defs._IOwnership _396___v131; + Dafny.ISet> _397_recIdentsLo; + RAST._IExpr _out325; + Defs._IOwnership _out326; + Dafny.ISet> _out327; + (this).GenExpr(_392_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out325, out _out326, out _out327); + _395_lo = _out325; + _396___v131 = _out326; + _397_recIdentsLo = _out327; + RAST._IExpr _398_hi; + Defs._IOwnership _399___v132; + Dafny.ISet> _400_recIdentsHi; + RAST._IExpr _out328; + Defs._IOwnership _out329; + Dafny.ISet> _out330; + (this).GenExpr(_393_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out328, out _out329, out _out330); + _398_hi = _out328; + _399___v132 = _out329; + _400_recIdentsHi = _out330; + if (_394_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_395_lo, _398_hi)); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_392_hi, _389_lo)); - } - if (!((_385_typ).is_Primitive)) { - RAST._IType _395_tpe; - RAST._IType _out321; - _out321 = (this).GenType(_385_typ, Defs.GenTypeContext.@default()); - _395_tpe = _out321; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_395_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); - } - RAST._IExpr _out322; - Defs._IOwnership _out323; - (this).FromOwned(r, expectedOwnership, out _out322, out _out323); - r = _out322; - resultingOwnership = _out323; - readIdents = Dafny.Set>.Union(_391_recIdentsLo, _394_recIdentsHi); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_398_hi, _395_lo)); + } + if (!((_391_typ).is_Primitive)) { + RAST._IType _401_tpe; + RAST._IType _out331; + _out331 = (this).GenType(_391_typ, Defs.GenTypeContext.@default()); + _401_tpe = _out331; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_401_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); + } + RAST._IExpr _out332; + Defs._IOwnership _out333; + (this).FromOwned(r, expectedOwnership, out _out332, out _out333); + r = _out332; + resultingOwnership = _out333; + readIdents = Dafny.Set>.Union(_397_recIdentsLo, _400_recIdentsHi); return ; } goto after_match0; @@ -6802,30 +6896,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_UnboundedIntRange) { - DAST._IExpression _396_start = _source0.dtor_start; - bool _397_up = _source0.dtor_up; + DAST._IExpression _402_start = _source0.dtor_start; + bool _403_up = _source0.dtor_up; { - RAST._IExpr _398_start; - Defs._IOwnership _399___v139; - Dafny.ISet> _400_recIdentStart; - RAST._IExpr _out324; - Defs._IOwnership _out325; - Dafny.ISet> _out326; - (this).GenExpr(_396_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out324, out _out325, out _out326); - _398_start = _out324; - _399___v139 = _out325; - _400_recIdentStart = _out326; - if (_397_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_398_start); + RAST._IExpr _404_start; + Defs._IOwnership _405___v133; + Dafny.ISet> _406_recIdentStart; + RAST._IExpr _out334; + Defs._IOwnership _out335; + Dafny.ISet> _out336; + (this).GenExpr(_402_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); + _404_start = _out334; + _405___v133 = _out335; + _406_recIdentStart = _out336; + if (_403_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_404_start); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_398_start); - } - RAST._IExpr _out327; - Defs._IOwnership _out328; - (this).FromOwned(r, expectedOwnership, out _out327, out _out328); - r = _out327; - resultingOwnership = _out328; - readIdents = _400_recIdentStart; + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_404_start); + } + RAST._IExpr _out337; + Defs._IOwnership _out338; + (this).FromOwned(r, expectedOwnership, out _out337, out _out338); + r = _out337; + resultingOwnership = _out338; + readIdents = _406_recIdentStart; return ; } goto after_match0; @@ -6833,23 +6927,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBuilder) { - DAST._IType _401_keyType = _source0.dtor_keyType; - DAST._IType _402_valueType = _source0.dtor_valueType; + DAST._IType _407_keyType = _source0.dtor_keyType; + DAST._IType _408_valueType = _source0.dtor_valueType; { - RAST._IType _403_kType; - RAST._IType _out329; - _out329 = (this).GenType(_401_keyType, Defs.GenTypeContext.@default()); - _403_kType = _out329; - RAST._IType _404_vType; - RAST._IType _out330; - _out330 = (this).GenType(_402_valueType, Defs.GenTypeContext.@default()); - _404_vType = _out330; - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_403_kType, _404_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out331; - Defs._IOwnership _out332; - (this).FromOwned(r, expectedOwnership, out _out331, out _out332); - r = _out331; - resultingOwnership = _out332; + RAST._IType _409_kType; + RAST._IType _out339; + _out339 = (this).GenType(_407_keyType, Defs.GenTypeContext.@default()); + _409_kType = _out339; + RAST._IType _410_vType; + RAST._IType _out340; + _out340 = (this).GenType(_408_valueType, Defs.GenTypeContext.@default()); + _410_vType = _out340; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_409_kType, _410_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out341; + Defs._IOwnership _out342; + (this).FromOwned(r, expectedOwnership, out _out341, out _out342); + r = _out341; + resultingOwnership = _out342; readIdents = Dafny.Set>.FromElements(); return ; } @@ -6858,93 +6952,93 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBuilder) { - DAST._IType _405_elemType = _source0.dtor_elemType; + DAST._IType _411_elemType = _source0.dtor_elemType; { - RAST._IType _406_eType; - RAST._IType _out333; - _out333 = (this).GenType(_405_elemType, Defs.GenTypeContext.@default()); - _406_eType = _out333; + RAST._IType _412_eType; + RAST._IType _out343; + _out343 = (this).GenType(_411_elemType, Defs.GenTypeContext.@default()); + _412_eType = _out343; readIdents = Dafny.Set>.FromElements(); - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_406_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out334; - Defs._IOwnership _out335; - (this).FromOwned(r, expectedOwnership, out _out334, out _out335); - r = _out334; - resultingOwnership = _out335; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_412_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out344; + Defs._IOwnership _out345; + (this).FromOwned(r, expectedOwnership, out _out344, out _out345); + r = _out344; + resultingOwnership = _out345; return ; } goto after_match0; } } { - DAST._IType _407_elemType = _source0.dtor_elemType; - DAST._IExpression _408_collection = _source0.dtor_collection; - bool _409_is__forall = _source0.dtor_is__forall; - DAST._IExpression _410_lambda = _source0.dtor_lambda; + DAST._IType _413_elemType = _source0.dtor_elemType; + DAST._IExpression _414_collection = _source0.dtor_collection; + bool _415_is__forall = _source0.dtor_is__forall; + DAST._IExpression _416_lambda = _source0.dtor_lambda; { - RAST._IType _411_tpe; - RAST._IType _out336; - _out336 = (this).GenType(_407_elemType, Defs.GenTypeContext.@default()); - _411_tpe = _out336; - RAST._IExpr _412_collectionGen; - Defs._IOwnership _413___v140; - Dafny.ISet> _414_recIdents; - RAST._IExpr _out337; - Defs._IOwnership _out338; - Dafny.ISet> _out339; - (this).GenExpr(_408_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out337, out _out338, out _out339); - _412_collectionGen = _out337; - _413___v140 = _out338; - _414_recIdents = _out339; - Dafny.ISequence _415_extraAttributes; - _415_extraAttributes = Dafny.Sequence.FromElements(); - if ((((((_408_collection).is_IntRange) || ((_408_collection).is_UnboundedIntRange)) || ((_408_collection).is_SeqBoundedPool)) || ((_408_collection).is_ExactBoundedPool)) || ((_408_collection).is_MultisetBoundedPool)) { - _415_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); - } - if ((_410_lambda).is_Lambda) { - Dafny.ISequence _416_formals; - _416_formals = (_410_lambda).dtor_params; - Dafny.ISequence _417_newFormals; - _417_newFormals = Dafny.Sequence.FromElements(); - BigInteger _hi15 = new BigInteger((_416_formals).Count); - for (BigInteger _418_i = BigInteger.Zero; _418_i < _hi15; _418_i++) { - var _pat_let_tv0 = _415_extraAttributes; - var _pat_let_tv1 = _416_formals; - _417_newFormals = Dafny.Sequence.Concat(_417_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_416_formals).Select(_418_i), _pat_let29_0 => Dafny.Helpers.Let(_pat_let29_0, _419_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_418_i)).dtor_attributes), _pat_let30_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let30_0, _420_dt__update_hattributes_h0 => DAST.Formal.create((_419_dt__update__tmp_h0).dtor_name, (_419_dt__update__tmp_h0).dtor_typ, _420_dt__update_hattributes_h0))))))); - } - DAST._IExpression _421_newLambda; - DAST._IExpression _422_dt__update__tmp_h1 = _410_lambda; - Dafny.ISequence _423_dt__update_hparams_h0 = _417_newFormals; - _421_newLambda = DAST.Expression.create_Lambda(_423_dt__update_hparams_h0, (_422_dt__update__tmp_h1).dtor_retType, (_422_dt__update__tmp_h1).dtor_body); - RAST._IExpr _424_lambdaGen; - Defs._IOwnership _425___v141; - Dafny.ISet> _426_recLambdaIdents; - RAST._IExpr _out340; - Defs._IOwnership _out341; - Dafny.ISet> _out342; - (this).GenExpr(_421_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out340, out _out341, out _out342); - _424_lambdaGen = _out340; - _425___v141 = _out341; - _426_recLambdaIdents = _out342; - Dafny.ISequence _427_fn; - if (_409_is__forall) { - _427_fn = Dafny.Sequence.UnicodeFromString("all"); + RAST._IType _417_tpe; + RAST._IType _out346; + _out346 = (this).GenType(_413_elemType, Defs.GenTypeContext.@default()); + _417_tpe = _out346; + RAST._IExpr _418_collectionGen; + Defs._IOwnership _419___v134; + Dafny.ISet> _420_recIdents; + RAST._IExpr _out347; + Defs._IOwnership _out348; + Dafny.ISet> _out349; + (this).GenExpr(_414_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out347, out _out348, out _out349); + _418_collectionGen = _out347; + _419___v134 = _out348; + _420_recIdents = _out349; + Dafny.ISequence _421_extraAttributes; + _421_extraAttributes = Dafny.Sequence.FromElements(); + if ((((((_414_collection).is_IntRange) || ((_414_collection).is_UnboundedIntRange)) || ((_414_collection).is_SeqBoundedPool)) || ((_414_collection).is_ExactBoundedPool)) || ((_414_collection).is_MultisetBoundedPool)) { + _421_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); + } + if ((_416_lambda).is_Lambda) { + Dafny.ISequence _422_formals; + _422_formals = (_416_lambda).dtor_params; + Dafny.ISequence _423_newFormals; + _423_newFormals = Dafny.Sequence.FromElements(); + BigInteger _hi15 = new BigInteger((_422_formals).Count); + for (BigInteger _424_i = BigInteger.Zero; _424_i < _hi15; _424_i++) { + var _pat_let_tv0 = _421_extraAttributes; + var _pat_let_tv1 = _422_formals; + _423_newFormals = Dafny.Sequence.Concat(_423_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_422_formals).Select(_424_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _425_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_424_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _426_dt__update_hattributes_h0 => DAST.Formal.create((_425_dt__update__tmp_h0).dtor_name, (_425_dt__update__tmp_h0).dtor_typ, _426_dt__update_hattributes_h0))))))); + } + DAST._IExpression _427_newLambda; + DAST._IExpression _428_dt__update__tmp_h1 = _416_lambda; + Dafny.ISequence _429_dt__update_hparams_h0 = _423_newFormals; + _427_newLambda = DAST.Expression.create_Lambda(_429_dt__update_hparams_h0, (_428_dt__update__tmp_h1).dtor_retType, (_428_dt__update__tmp_h1).dtor_body); + RAST._IExpr _430_lambdaGen; + Defs._IOwnership _431___v135; + Dafny.ISet> _432_recLambdaIdents; + RAST._IExpr _out350; + Defs._IOwnership _out351; + Dafny.ISet> _out352; + (this).GenExpr(_427_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out350, out _out351, out _out352); + _430_lambdaGen = _out350; + _431___v135 = _out351; + _432_recLambdaIdents = _out352; + Dafny.ISequence _433_fn; + if (_415_is__forall) { + _433_fn = Dafny.Sequence.UnicodeFromString("all"); } else { - _427_fn = Dafny.Sequence.UnicodeFromString("any"); + _433_fn = Dafny.Sequence.UnicodeFromString("any"); } - r = ((_412_collectionGen).Sel(_427_fn)).Apply1(((_424_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); - readIdents = Dafny.Set>.Union(_414_recIdents, _426_recLambdaIdents); + r = ((_418_collectionGen).Sel(_433_fn)).Apply1(((_430_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); + readIdents = Dafny.Set>.Union(_420_recIdents, _432_recLambdaIdents); } else { - RAST._IExpr _out343; - _out343 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); - r = _out343; + RAST._IExpr _out353; + _out353 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); + r = _out353; readIdents = Dafny.Set>.FromElements(); } - RAST._IExpr _out344; - Defs._IOwnership _out345; - (this).FromOwned(r, expectedOwnership, out _out344, out _out345); - r = _out344; - resultingOwnership = _out345; + RAST._IExpr _out354; + Defs._IOwnership _out355; + (this).FromOwned(r, expectedOwnership, out _out354, out _out355); + r = _out354; + resultingOwnership = _out355; } } after_match0: ; @@ -7031,15 +7125,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v142; - Dafny.ISet> _2___v143; + Defs._IOwnership _1___v136; + Dafny.ISet> _2___v137; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v142 = _out1; - _2___v143 = _out2; + _1___v136 = _out1; + _2___v137 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index e67d0d6e831..2f4bf7adf64 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -557,18 +557,34 @@ public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence.create_Some(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(RAST.__default.NoDoc, RAST.__default.NoAttr, rTypeParamsDecls, _1_downcast__type, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(fullType), Std.Wrappers.Option.create_None())))))); } } - public static Std.Wrappers._IOption DowncastImplFor(Dafny.ISequence rTypeParamsDecls, RAST._IType typeToDowncastTo, RAST._IType forType) + public static Std.Wrappers._IOption DowncastImplFor(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType) { - var _pat_let_tv0 = forType; - Std.Wrappers._IOption _0_valueOrError0 = (typeToDowncastTo).ToDowncast(); + Std.Wrappers._IOption _0_valueOrError0 = (datatypeType).ToDowncast(); if ((_0_valueOrError0).IsFailure()) { return (_0_valueOrError0).PropagateFailure(); } else { RAST._IType _1_downcast__type = (_0_valueOrError0).Extract(); - RAST._IType _2_forTypeRaw = (((forType).IsRc()) ? ((forType).RcUnderlying()) : (forType)); - bool _3_sameType = object.Equals(typeToDowncastTo, forType); - RAST._IExpr _4_asBody = ((_3_sameType) ? (Dafny.Helpers.Let((RAST.__default.self).Clone(), _pat_let25_0 => Dafny.Helpers.Let(_pat_let25_0, _5_body => (((_pat_let_tv0).IsRc()) ? (RAST.__default.RcNew(_5_body)) : (_5_body))))) : ((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply1(RAST.Expr.create_LiteralString(Dafny.Sequence.Concat(Dafny.Sequence.Concat((_2_forTypeRaw)._ToString(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString(" is not a ")), (typeToDowncastTo)._ToString(Dafny.Sequence.UnicodeFromString(""))), false, true)))); - return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, forType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(RAST.Expr.create_LiteralBool(_3_sameType)))), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(forType), Std.Wrappers.Option.create_Some(_4_asBody))))))); + bool _2_isRc = (datatypeType).IsRc(); + RAST._IType _3_datatypeTypeRaw = ((_2_isRc) ? ((datatypeType).RcUnderlying()) : (datatypeType)); + RAST._IExpr _4_isBody = (((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(_3_datatypeTypeRaw))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("is_some"))).Apply0(); + RAST._IExpr _5_asBody = (((((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(_3_datatypeTypeRaw))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0(); + RAST._IExpr _6_asBody = ((_2_isRc) ? (RAST.__default.RcNew(_5_asBody)) : (_5_asBody)); + return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, RAST.Type.create_DynType(RAST.__default.AnyTrait), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_4_isBody))), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(datatypeType), Std.Wrappers.Option.create_Some(_6_asBody))))))); + } + } + public static Std.Wrappers._IOption DowncastImplTraitFor(Dafny.ISequence rTypeParamsDecls, RAST._IType traitType, bool implementsTrait, RAST._IType datatypeType) + { + Std.Wrappers._IOption _0_valueOrError0 = (traitType).ToDowncast(); + if ((_0_valueOrError0).IsFailure()) { + return (_0_valueOrError0).PropagateFailure(); + } else { + RAST._IType _1_downcast__type = (_0_valueOrError0).Extract(); + bool _2_isRc = (datatypeType).IsRc(); + RAST._IType _3_forType = ((_2_isRc) ? ((datatypeType).RcUnderlying()) : (datatypeType)); + RAST._IType _4_resultType = traitType; + RAST._IExpr _5_isBody = RAST.Expr.create_LiteralBool(implementsTrait); + RAST._IExpr _6_asBody = RAST.__default.BoxNew((RAST.__default.self).Clone()); + return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, _3_forType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_5_isBody))), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(_4_resultType), Std.Wrappers.Option.create_Some(_6_asBody))))))); } } public static Defs._IAssignmentStatus DetectAssignmentStatus(Dafny.ISequence stmts__remainder, Dafny.ISequence dafny__name) @@ -740,7 +756,7 @@ public static RAST._IImplMember hasher__trait { get { return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Std.Wrappers.Option.create_Some((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("hasher"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("DefaultHasher"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0()))).Then((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&mut"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher")), DAST.Format.UnaryOpFormat.create_NoFormat()))).Then(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher"))).Sel(Dafny.Sequence.UnicodeFromString("finish"))).Apply0()))))); } } public static RAST._IImplMember as__any__trait { get { - return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType()))), Std.Wrappers.Option.create_Some(RAST.__default.self))); + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType(RAST.__default.AnyTrait))), Std.Wrappers.Option.create_Some(RAST.__default.self))); } } } @@ -1321,6 +1337,8 @@ public interface _ISelfInfo { DAST._IType dtor_dafnyType { get; } _ISelfInfo DowncastClone(); bool IsSelf(); + bool IsGeneralTrait(); + bool IsClassOrObjectTrait(); } public abstract class SelfInfo : _ISelfInfo { public SelfInfo() { @@ -1357,6 +1375,12 @@ public DAST._IType dtor_dafnyType { public bool IsSelf() { return ((this).is_ThisTyped) && (((this).dtor_rSelfName).Equals(Dafny.Sequence.UnicodeFromString("self"))); } + public bool IsGeneralTrait() { + return ((this).is_ThisTyped) && (((this).dtor_dafnyType).IsGeneralTrait()); + } + public bool IsClassOrObjectTrait() { + return ((this).is_ThisTyped) && (((this).dtor_dafnyType).IsClassOrObjectTrait()); + } } public class SelfInfo_NoSelf : SelfInfo { public SelfInfo_NoSelf() : base() { diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index 4ba3e85ff6f..abf64c2df1a 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -3954,6 +3954,15 @@ impl UpcastBox for Box } } +pub trait AnyRef { + fn as_any_ref(&self) -> &dyn Any; +} + +impl AnyRef for T { + fn as_any_ref(&self) -> &dyn Any { + self + } +} #[macro_export] macro_rules! Extends { diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index a31e7cb2803..2a8b1e4964b 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -925,6 +925,16 @@ mod tests { assert_eq!(resulting_message, message); } + /** Hierarchy implemented + * GeneralTraitSuper + * | \____________________, + * | | + * GeneralTraitSuper GeneralTraitSuperChild + * | | (via i32) + * GeneralTrait CDatatype + * | | + * ADatatype BDatatype + */ trait _Downcast_GeneralTrait { fn _is(&self) -> bool; @@ -936,11 +946,24 @@ mod tests { fn _is(&self) -> bool; fn _as(&self) -> ADatatype; // For trait objects, Object or Ptr instead of Box } + trait _Downcast_CDatatype { + fn _is(&self) -> bool; + fn _as(&self) -> CDatatype; // For trait objects, Object or Ptr instead of Box + } // Every general trait must declare how to clone a Box of itself - trait GeneralTraitSuper: _Downcast_GeneralTrait + _Downcast_ADatatype { + trait GeneralTraitSuper: _Downcast_GeneralTrait + AnyRef + _Downcast_GeneralTraitSuperChild { fn _clone(&self) -> Box>; } + trait GeneralTraitSuperChild: GeneralTraitSuper { + fn _clone(&self) -> Box>; + } + + trait _Downcast_GeneralTraitSuperChild { + fn _is(&self) -> bool; + fn _as(&self) -> Box>; // For trait objects, Object or Ptr instead of Box + } + impl Clone for Box> { fn clone(&self) -> Self { GeneralTraitSuper::_clone(self.as_ref()) @@ -973,15 +996,15 @@ mod tests { Box::new(self.clone()) as Box } } - impl _Downcast_ADatatype for ADatatype { + impl _Downcast_ADatatype for dyn Any { fn _is(&self) -> bool { - true + self.downcast_ref::().is_some() } fn _as(&self) -> ADatatype { - self.clone() + self.downcast_ref::().unwrap().clone() // Optimization: Could be unwrap_unchecked } } - impl _Downcast_GeneralTrait for ADatatype { + impl _Downcast_GeneralTrait for T { fn _is(&self) -> bool { true } @@ -994,6 +1017,14 @@ mod tests { Box::new(self.clone()) } } + impl _Downcast_GeneralTraitSuperChild for ADatatype { + fn _is(&self) -> bool { + false + } + fn _as(&self) -> Box> { + panic!("cannot") + } + } impl UpcastBox for ADatatype { fn upcast(&self) -> ::std::boxed::Box { GeneralTrait::_clone(self) @@ -1004,26 +1035,82 @@ mod tests { GeneralTraitSuper::::_clone(self) } } + + #[derive(Clone, PartialEq, Debug)] + pub struct CDatatype { i: u32 } + impl _Downcast_CDatatype for dyn Any { + fn _is(&self) -> bool { + self.downcast_ref::().is_some() + } + fn _as(&self) -> CDatatype { + self.downcast_ref::().unwrap().clone() // Optimization: Could be unwrap_unchecked + } + } + impl UpcastBox> for CDatatype { + fn upcast(&self) -> ::std::boxed::Box> { + GeneralTraitSuper::::_clone(self) + } + } + impl UpcastBox> for CDatatype { + fn upcast(&self) -> ::std::boxed::Box> { + GeneralTraitSuperChild::::_clone(self) + } + } + + impl GeneralTraitSuper for CDatatype { + fn _clone(&self) -> Box> { + Box::new(self.clone()) + } + } + impl GeneralTraitSuperChild for CDatatype { + fn _clone(&self) -> Box> { + Box::new(self.clone()) + } + } + impl _Downcast_GeneralTraitSuperChild for CDatatype { + fn _is(&self) -> bool { + true + } + fn _as(&self) -> Box> { + GeneralTraitSuperChild::::_clone(self) + } + } + impl _Downcast_GeneralTrait for CDatatype { // CDatatype does not extend general trait + fn _is(&self) -> bool { + false + } + fn _as(&self) -> Box { + panic!("CDatatype does not extend GeneralTrait") + } + } #[test] fn test_general_traits() { let x = ADatatype{i: 3}; let gt = upcast_box::()(x.clone()); let gts = upcast_box::>()(x.clone()); let gtgts = upcast_box_box::>()(gt.clone()); - assert!(_Downcast_ADatatype::_is(AsRef::as_ref(>))); - assert!(_Downcast_ADatatype::_is(AsRef::as_ref(>s))); - assert!(_Downcast_ADatatype::_is(AsRef::as_ref(>gts))); + assert!(_Downcast_ADatatype::_is(AnyRef::as_any_ref(AsRef::as_ref(>)))); + assert!(_Downcast_ADatatype::_is(AnyRef::as_any_ref(AsRef::as_ref(>s)))); + assert!(_Downcast_ADatatype::_is(AnyRef::as_any_ref(AsRef::as_ref(>gts)))); assert!(_Downcast_GeneralTrait::_is(AsRef::as_ref(>s))); assert!(_Downcast_GeneralTrait::_is(AsRef::as_ref(>gts))); - assert_eq!(_Downcast_ADatatype::_as(AsRef::as_ref(>)), x); - assert_eq!(_Downcast_ADatatype::_as(AsRef::as_ref(>s)), x); - assert_eq!(_Downcast_ADatatype::_as(AsRef::as_ref(>gts)), x); + assert_eq!(_Downcast_ADatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>))), x); + assert_eq!(_Downcast_ADatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>s))), x); + assert_eq!(_Downcast_ADatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>gts))), x); let gtsgt = _Downcast_GeneralTrait::_as(AsRef::as_ref(>s)); let gtgtsgt = _Downcast_GeneralTrait::_as(AsRef::as_ref(>gts)); - assert!(_Downcast_ADatatype::_is(AsRef::as_ref(>sgt))); - assert!(_Downcast_ADatatype::_is(AsRef::as_ref(>gtsgt))); - assert_eq!(_Downcast_ADatatype::_as(AsRef::as_ref(>sgt)), x); - assert_eq!(_Downcast_ADatatype::_as(AsRef::as_ref(>sgt)), x); + assert!(_Downcast_ADatatype::_is(AnyRef::as_any_ref(AsRef::as_ref(>sgt)))); + assert!(_Downcast_ADatatype::_is(AnyRef::as_any_ref(AsRef::as_ref(>gtsgt)))); + assert_eq!(_Downcast_ADatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>sgt))), x); + assert_eq!(_Downcast_ADatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>sgt))), x); + let xc = CDatatype{i: 3}; + let gtc = upcast_box::>()(xc.clone()); + let gcsc = upcast_box::>()(xc.clone()); + let gtcsc = _Downcast_GeneralTraitSuperChild::::_as(AsRef::as_ref(>c)); + let xc1 = _Downcast_CDatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(&gcsc))); + let xc2 = _Downcast_CDatatype::_as(AnyRef::as_any_ref(AsRef::as_ref(>csc))); + assert_eq!(xc, xc1); + assert_eq!(xc, xc2); } /*impl GeneralTrait for Rc { fn _clone(&self) -> Box { From 178f339c4b4c7a49d6bef6c40df3c15f406de4bf Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Sat, 7 Dec 2024 00:33:06 +0100 Subject: [PATCH 22/69] Support for negative traits. --- .../AST/TypeDeclarations/TraitDecl.cs | 2 +- Source/DafnyCore/Backends/Dafny/AST.dfy | 7 +- Source/DafnyCore/Backends/Dafny/ASTBuilder.cs | 35 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 118 +- .../Rust/Dafny-compiler-rust-definitions.dfy | 35 + .../Rust/Dafny-compiler-rust-rast.dfy | 6 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 50 +- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 54 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 1429 +++++++++-------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 14 + Source/DafnyCore/Resolver/ModuleResolver.cs | 6 + .../LitTest/comp/rust/traits-datatypes.dfy | 18 + 12 files changed, 1032 insertions(+), 742 deletions(-) diff --git a/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs b/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs index 16af1a8a98f..8a052b1976c 100644 --- a/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs +++ b/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs @@ -9,7 +9,7 @@ public class TraitDecl : ClassLikeDecl { public bool IsParent { set; get; } public override bool AcceptThis => true; - [FilledInDuringResolution] public List ChildrenTraitDecl = new(); + [FilledInDuringResolution] public List TraitDeclsCanBeDowncastedTo = new(); internal void SetUpAsReferenceType(bool isReferenceType) { // Note, it's important to set .NonNullTypeDecl first, before calling NewSelfSynonym(), since the latter will look at the former. diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index ee8504ff5c6..fa369bf5051 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -301,6 +301,7 @@ module {:extern "DAST"} DAST { typeParams: seq, traitType: TraitType, parents: seq, + downcastableTraits: seq, body: seq, attributes: seq) @@ -313,7 +314,9 @@ module {:extern "DAST"} DAST { body: seq, isCo: bool, attributes: seq, - superTraitTypes: seq) + superTraitTypes: seq, + superTraitNegativeTypes: seq // Traits that one or more superTraits know they can downcast to, but the datatype does not. + ) datatype DatatypeDtor = DatatypeDtor( formal: Formal, @@ -422,7 +425,7 @@ module {:extern "DAST"} DAST { Submultiset() | ProperSubmultiset() | MultisetDisjoint() | Concat() | Passthrough(string) - + datatype SelectContext = SelectContextDatatype | SelectContextGeneralTrait | SelectContextClassOrObjectTrait diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index 3b7f6eeb867..d8bded0b388 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -166,9 +166,9 @@ public object Finish() { interface TraitContainer : Container { void AddTrait(Trait item); - public TraitBuilder Trait(string name, List typeParams, List parents, - ISequence<_IAttribute> attributes, string docString, _ITraitType traitType) { - return new TraitBuilder(this, name, docString, typeParams, parents, attributes, traitType); + public TraitBuilder Trait(string name, List typeParams, List parents, + ISequence<_IAttribute> attributes, string docString, _ITraitType traitType, List downcastableTraits) { + return new TraitBuilder(this, name, docString, typeParams, parents, attributes, traitType, downcastableTraits); } } @@ -179,16 +179,18 @@ class TraitBuilder : ClassLike { private readonly List parents; readonly List body = new(); private ISequence<_IAttribute> attributes; - private string docString; - private _ITraitType traitType; + private readonly string docString; + private readonly _ITraitType traitType; + private readonly List downcastableTraits; - public TraitBuilder(TraitContainer parent, string name, string docString, List typeParams, List parents, ISequence<_IAttribute> attributes, _ITraitType traitType) { + public TraitBuilder(TraitContainer parent, string name, string docString, List typeParams, List parents, ISequence<_IAttribute> attributes, _ITraitType traitType, List downcastableTraits) { this.parent = parent; this.name = name; this.typeParams = typeParams; this.attributes = attributes; this.docString = docString; this.traitType = traitType; + this.downcastableTraits = downcastableTraits; this.parents = parents; } @@ -215,6 +217,7 @@ public object Finish() { Sequence.FromArray(typeParams.ToArray()), traitType, Sequence.FromArray(parents.ToArray()), + Sequence.FromArray(downcastableTraits.ToArray()), Sequence.FromArray(body.ToArray()), attributes) ); @@ -341,9 +344,10 @@ public object Finish() { interface DatatypeContainer : Container { void AddDatatype(Datatype item); - public DatatypeBuilder Datatype(string name, string enclosingModule, List typeParams, - List ctors, bool isCo, ISequence<_IAttribute> attributes, string docString, List superTraitTypes) { - return new DatatypeBuilder(this, name, docString, enclosingModule, typeParams, ctors, isCo, attributes, superTraitTypes); + public DatatypeBuilder Datatype(string name, string enclosingModule, List typeParams, + List ctors, bool isCo, ISequence<_IAttribute> attributes, string docString, + List superTraitTypes, List superNegativeTraitTypes) { + return new DatatypeBuilder(this, name, docString, enclosingModule, typeParams, ctors, isCo, attributes, superTraitTypes, superNegativeTraitTypes); } } @@ -355,11 +359,12 @@ class DatatypeBuilder : ClassLike { readonly List ctors; readonly bool isCo; readonly List body = new(); - private ISequence<_IAttribute> attributes; - private string docString; - private List superTraitTypes; + readonly ISequence<_IAttribute> attributes; + readonly string docString; + readonly List superTraitTypes; + readonly List superNegativeTraitTypes; - public DatatypeBuilder(DatatypeContainer parent, string name, string docString, string enclosingModule, List typeParams, List ctors, bool isCo, ISequence<_IAttribute> attributes, List superTraitTypes) { + public DatatypeBuilder(DatatypeContainer parent, string name, string docString, string enclosingModule, List typeParams, List ctors, bool isCo, ISequence<_IAttribute> attributes, List superTraitTypes, List superNegativeTraitTypes) { this.parent = parent; this.name = name; this.docString = docString; @@ -369,6 +374,7 @@ public DatatypeBuilder(DatatypeContainer parent, string name, string docString, this.isCo = isCo; this.attributes = attributes; this.superTraitTypes = superTraitTypes; + this.superNegativeTraitTypes = superNegativeTraitTypes; } public void AddMethod(DAST.Method item) { @@ -388,7 +394,8 @@ public object Finish() { Sequence.FromArray(ctors.ToArray()), Sequence.FromArray(body.ToArray()), this.isCo, attributes, - Sequence.FromArray(superTraitTypes.ToArray()) + Sequence.FromArray(superTraitTypes.ToArray()), + Sequence.FromArray(superNegativeTraitTypes.ToArray()) )); return parent; } diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 07a1a327700..b20a09c5b6a 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -268,13 +268,88 @@ protected override IClassWriter CreateTrait(string name, bool isExtern, List DowncastableTraitsTypes(TraitDecl trait) { + var downcastableTraits = new List(); + foreach (var subTrait in trait.TraitDeclsCanBeDowncastedTo) { + // Recovers which of the parent traits of the subTraits is the current trait declaration + var parentTrait = subTrait.ParentTraits.FirstOrDefault(t => t.AsTraitType == trait); + if (parentTrait != null && CanDowncast(parentTrait, subTrait, out var downcastType)) { + downcastableTraits.Add(downcastType); + } + } + + return downcastableTraits; + } + + /// + private static bool CanDowncast(Type parentTrait, TraitDecl subTrait, out Type downcastType) { + Contract.Requires(parentTrait.AsTraitType != null); + var parentTraitDecl = parentTrait.AsTraitType; + var canDowncast = false; + downcastType = null; + if (parentTrait is UserDefinedType { TypeArgs: var PT }) { + // Algorithm: + // trait Sub extends Parent where trait Parent + // Foreach type parameter in the parent TPi + // if PTi is some TCj, store the mapping TCj => TPi. We need only to store the first of such mapping + // If PTi is anything else, ok + // End of the loop: if not all children type parameters were found, cancel + // build the type Sub by iterating on the type parameters TC. + Contract.Assert(parentTraitDecl.TypeArgs.Count == PT.Count); + var mapping = new Dictionary(); + for (var i = 0; i < parentTraitDecl.TypeArgs.Count; i++) { + var TP = parentTraitDecl.TypeArgs[i]; + var maybeTc = PT[i]; + if (maybeTc is UserDefinedType { ResolvedClass: TypeParameter maybeTc2 }) { + if (subTrait.TypeArgs.Contains(maybeTc2) && !mapping.ContainsKey(maybeTc2)) { + mapping.Add(maybeTc2, new UserDefinedType(TP)); + } + } + } + + var allTypeParametersCovered = subTrait.TypeArgs.TrueForAll( + tp => mapping.ContainsKey(tp)); + if (allTypeParametersCovered) { + + var typeArgs = subTrait.TypeArgs.Select(tp => mapping[tp]).ToList(); + + var subTraitTypeDowncastable = + new UserDefinedType(Token.NoToken, subTrait.Name, subTrait, typeArgs); + downcastType = subTraitTypeDowncastable; + canDowncast = true; + } + } + + return canDowncast; + } + protected override ConcreteSyntaxTree CreateIterator(IteratorDecl iter, ConcreteSyntaxTree wr) { AddUnsupportedFeature(iter.tok, Feature.Iterators); return wr; @@ -318,6 +393,8 @@ from arg in ctor.Formals var superClasses = dt.ParentTypeInformation.UniqueParentTraits(); var superTraitTypes = superClasses.Select(GenType).ToList(); + var superNegativeTraitTypes = GetNegativeTraitTypes(superClasses); + var datatypeBuilder = builder.Datatype( dt.GetCompileName(Options), dt.EnclosingModuleDefinition.GetCompileName(Options), @@ -326,7 +403,8 @@ from arg in ctor.Formals dt is CoDatatypeDecl, ParseAttributes(dt.Attributes), GetDocString(dt), - superTraitTypes + superTraitTypes, + superNegativeTraitTypes ); return new ClassWriter(this, typeParams.Count > 0, datatypeBuilder); @@ -335,6 +413,35 @@ from arg in ctor.Formals } } + // Given a list of super traits implemented by a datatype, + // find the list of all instantiated traits that the super traits can be downcasted to, + // but that are not in the super classes, + // and return them + private List GetNegativeTraitTypes(List superClasses) { + var superNegativeTraitTypes = new List(); + var traitDeclsNegative = new HashSet(); + var traitDeclsImplemented = superClasses.Select(t => t.AsTraitType) + .Where(t => t != null).ToHashSet(); + foreach (var superClass in superClasses) { + if (superClass.AsTraitType is { } traitDecl) { + var downcastableTraitTypes = DowncastableTraitsTypes(traitDecl); + foreach (var downcastableTraitType in downcastableTraitTypes) { + if (downcastableTraitType is { AsTraitType: { } downcastTraitDecl } && + !traitDeclsNegative.Contains(downcastTraitDecl) && !traitDeclsImplemented.Contains(downcastTraitDecl)) { + traitDeclsNegative.Add(downcastTraitDecl); + // downcastableTraitType is instantiated with the type parameters of traitDecl + var typeParametersInstantiation = + traitDecl.TypeArgs.Zip(superClass.TypeArgs).ToDictionary(kv => kv.Item1, kv => kv.Item2); + var typeForDatatype = downcastableTraitType.Subst(typeParametersInstantiation); + superNegativeTraitTypes.Add(GenType(typeForDatatype)); + } + } + } + } + + return superNegativeTraitTypes; + } + protected override IClassWriter DeclareNewtype(NewtypeDecl nt, ConcreteSyntaxTree wr) { if (currentBuilder is NewtypeContainer builder) { List witnessStmts = new(); @@ -1978,7 +2085,7 @@ protected override void GetSpecialFieldInfo(SpecialField.ID id, object idParam, _ISelectContext GetSelectContext(TopLevelDecl decl) { return decl is DatatypeDecl or NewtypeDecl ? SelectContext.create_SelectContextDatatype() : - decl is TraitDecl { IsReferenceTypeDecl: false} ? + decl is TraitDecl { IsReferenceTypeDecl: false } ? SelectContext.create_SelectContextGeneralTrait() : SelectContext.create_SelectContextClassOrObjectTrait(); } @@ -2978,8 +3085,7 @@ protected override void EmitTypeTestExpr(Expression expr, Type fromType, Type to } } - private void EmitTypeTestDAST(Type fromType, Type toType, BuilderSyntaxTree builder, DAST.Expression exprDAST) - { + private void EmitTypeTestDAST(Type fromType, Type toType, BuilderSyntaxTree builder, DAST.Expression exprDAST) { builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_Is( exprDAST, GenType(fromType), diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 0539bed9712..6805500f938 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -933,6 +933,41 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { ) } + /* + impl _Downcast_TraitNotImplemented + for CDatatype { + fn _is(&self) -> bool { false } + fn _as(&self) -> Box { panic!(); } + } + */ + function DowncastNotImplFor( + rTypeParamsDecls: seq, + traitType: R.Type, + datatypeType: R.Type + ): Option { + var downcast_type :- traitType.ToDowncast(); + var isRc := datatypeType.IsRc(); + var datatypeTypeRaw := if isRc then datatypeType.RcUnderlying() else datatypeType; + var isBody := R.LiteralBool(false); + var asBody := R.Identifier("panic!").Apply0(); + Some( + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + downcast_type, + datatypeTypeRaw, + [ R.FnDecl( + datatypeTypeRaw.ToString("") + " does not implement that trait", R.NoAttr, + R.PRIV, + R.Fn("_is", [], [R.Formal.selfBorrowed], Some(R.Bool), Some(isBody))), + R.FnDecl( + R.NoDoc, R.NoAttr, + R.PRIV, + R.Fn("_as", [], [R.Formal.selfBorrowed], Some(traitType), Some(asBody))) + ])) + ) + } + /* impl _Downcast_SuperSubTrait for ADatatype { fn _is(&self) -> bool { diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index efd6f59ca64..16affcf6e1a 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -749,7 +749,7 @@ module RAST if t.IsBoxDyn() then t.BoxDynUnderlying().ToDowncast() else // For general traits match t { case TypeFromPath(path) => Some(TypeFromPath(path.ToDowncast())) - case TypeApp(baseName, arguments) => + case TypeApp(baseName, arguments) => var baseNameExpr :- baseName.ToDowncast(); Some(baseNameExpr.Apply(arguments)) case TIdentifier(name) => @@ -1122,13 +1122,13 @@ module RAST { arguments[0] } - + /** Returns true if the type has the shape Box, so that one can extract T = .arguments[0].underlying * Useful to detect general traits */ predicate IsBoxDyn() { this.TypeApp? && this.baseName == BoxType && |arguments| == 1 && arguments[0].DynType? } - + function BoxDynUnderlying(): (t: Type) requires IsBoxDyn() ensures t < this diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index eb312643a15..7656e9caa43 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -624,6 +624,17 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // Any top-most general trait must extend AnyRef so that we can perform downcasts to actual datatypes parents := [R.dafny_runtime.MSel("AnyRef").AsType()] + parents; } + if |t.downcastableTraits| > 0 { + for i := 0 to |t.downcastableTraits| { + var downcastableTrait := GenType(t.downcastableTraits[i], GenTypeContext.ForTraitParents()); + var downcastTraitOpt := downcastableTrait.ToDowncast(); + if downcastTraitOpt.Some? { + parents := parents + [downcastTraitOpt.value]; + } else { + var r := Error("Cannot convert "+downcastableTrait.ToString("")+" to its downcast version"); + } + } + } s := [ R.TraitDecl( R.Trait( @@ -1214,6 +1225,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } else { s := s + [downcastImplementationsOpt.value]; } + for i := 0 to |c.superTraitNegativeTypes| { + var negativeTraitType := GenType(c.superTraitNegativeTypes[i], GenTypeContext.default()); + var downcastDefinitionOpt := DowncastNotImplFor(rTypeParamsDecls, negativeTraitType, fullType); + if downcastDefinitionOpt.None? { + var dummy := Error("Could not generate negative downcast definition for " + fullType.ToString("")); + } else { + s := s + [downcastDefinitionOpt.value]; + } + } for i := 0 to |c.superTraitTypes| { var c := c.superTraitTypes[i]; if c.UserDefined? && c.resolved.kind.Trait? && |c.resolved.extendedTypes| == 0 { @@ -2091,15 +2111,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // The underlying type is a Box, self: Datatype or Rc // 'on' is going to return an owned version of this box. - /*if on.IsThisUpcast() { + if on.IsThisUpcast() { // Special case, in Rust, we don't need to upcast "self" because upcasted methods are automatically available onExpr := R.self; // Already self borrow readIdents := readIdents + {"self"}; - } else {*/ + } else { onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); onExpr := FromGeneralBorrowToSelfBorrow(onExpr, recOwnership, env); readIdents := readIdents + recIdents; - //} + } } else if base.Newtype? && IsNewtypeCopy(base.range) { // The self type of a newtype that is copy is also copy onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipOwned); @@ -2112,13 +2132,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r := fullPath.ApplyType(onTypeExprs).FSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); case _ => // Infix call on.name(args) or Companion::name(args) var onExpr, recIdents, dummy; - /*if on.IsThisUpcast() { + if on.IsThisUpcast() { // Special case, in Rust, we don't need to upcast "self" because upcasted methods are automatically available onExpr := R.self; // Already self borrow recIdents := {"self"}; - } else {*/ + } else { onExpr, dummy, recIdents := GenExpr(on, selfIdent, env, OwnershipAutoBorrowed); - //} + } readIdents := readIdents + recIdents; var renderedName := GetMethodName(on, name); // Pointers in the role of "self" must be converted to borrowed versions. @@ -3087,7 +3107,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case _ => expr.Clone() } - + method GenExprConvertOther( expr: R.Expr, exprOwnership: Ownership, @@ -3895,11 +3915,19 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r, resultingOwnership := FromOwnership(r, originalMutability, expectedOwnership); readIdents := recIdents; } else if selectContext.SelectContextGeneralTrait? { - var onExpr, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); - r := onExpr; - if onExpr != R.self { - r := R.std.MSel("convert").MSel("AsRef").AsExpr().FSel("as_ref").Apply1(r); + var onOwned, recIdents; + readIdents := {}; + if on.IsThisUpcast() { + // Special case, in Rust, we don't need to upcast "self" because upcasted methods are automatically available + r := R.self; // Already self borrow + recIdents := {"self"}; + } else { + r, onOwned, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); + if r != R.self { + r := R.std.MSel("convert").MSel("AsRef").AsExpr().FSel("as_ref").Apply1(r); + } } + readIdents := readIdents + recIdents; r := r.Sel(escapeVar(field)).Apply0(); r, resultingOwnership := FromOwned(r, expectedOwnership); readIdents := recIdents; diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 7a1fe477045..3b506e78feb 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -3006,6 +3006,7 @@ public interface _ITrait { Dafny.ISequence dtor_typeParams { get; } DAST._ITraitType dtor_traitType { get; } Dafny.ISequence dtor_parents { get; } + Dafny.ISequence dtor_downcastableTraits { get; } Dafny.ISequence dtor_body { get; } Dafny.ISequence dtor_attributes { get; } _ITrait DowncastClone(); @@ -3016,24 +3017,26 @@ public class Trait : _ITrait { public readonly Dafny.ISequence _typeParams; public readonly DAST._ITraitType _traitType; public readonly Dafny.ISequence _parents; + public readonly Dafny.ISequence _downcastableTraits; public readonly Dafny.ISequence _body; public readonly Dafny.ISequence _attributes; - public Trait(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence body, Dafny.ISequence attributes) { + public Trait(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence downcastableTraits, Dafny.ISequence body, Dafny.ISequence attributes) { this._name = name; this._docString = docString; this._typeParams = typeParams; this._traitType = traitType; this._parents = parents; + this._downcastableTraits = downcastableTraits; this._body = body; this._attributes = attributes; } public _ITrait DowncastClone() { if (this is _ITrait dt) { return dt; } - return new Trait(_name, _docString, _typeParams, _traitType, _parents, _body, _attributes); + return new Trait(_name, _docString, _typeParams, _traitType, _parents, _downcastableTraits, _body, _attributes); } public override bool Equals(object other) { var oth = other as DAST.Trait; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._traitType, oth._traitType) && object.Equals(this._parents, oth._parents) && object.Equals(this._body, oth._body) && object.Equals(this._attributes, oth._attributes); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._traitType, oth._traitType) && object.Equals(this._parents, oth._parents) && object.Equals(this._downcastableTraits, oth._downcastableTraits) && object.Equals(this._body, oth._body) && object.Equals(this._attributes, oth._attributes); } public override int GetHashCode() { ulong hash = 5381; @@ -3043,6 +3046,7 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typeParams)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._traitType)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._parents)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._downcastableTraits)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); return (int) hash; @@ -3060,13 +3064,15 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._parents); s += ", "; + s += Dafny.Helpers.ToString(this._downcastableTraits); + s += ", "; s += Dafny.Helpers.ToString(this._body); s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ")"; return s; } - private static readonly DAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.TraitType.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly DAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.TraitType.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static DAST._ITrait Default() { return theDefault; } @@ -3074,11 +3080,11 @@ public static DAST._ITrait Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITrait create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence body, Dafny.ISequence attributes) { - return new Trait(name, docString, typeParams, traitType, parents, body, attributes); + public static _ITrait create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence downcastableTraits, Dafny.ISequence body, Dafny.ISequence attributes) { + return new Trait(name, docString, typeParams, traitType, parents, downcastableTraits, body, attributes); } - public static _ITrait create_Trait(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence body, Dafny.ISequence attributes) { - return create(name, docString, typeParams, traitType, parents, body, attributes); + public static _ITrait create_Trait(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._ITraitType traitType, Dafny.ISequence parents, Dafny.ISequence downcastableTraits, Dafny.ISequence body, Dafny.ISequence attributes) { + return create(name, docString, typeParams, traitType, parents, downcastableTraits, body, attributes); } public bool is_Trait { get { return true; } } public Dafny.ISequence dtor_name { @@ -3106,6 +3112,11 @@ public Dafny.ISequence dtor_parents { return this._parents; } } + public Dafny.ISequence dtor_downcastableTraits { + get { + return this._downcastableTraits; + } + } public Dafny.ISequence dtor_body { get { return this._body; @@ -3129,6 +3140,7 @@ public interface _IDatatype { bool dtor_isCo { get; } Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_superTraitTypes { get; } + Dafny.ISequence dtor_superTraitNegativeTypes { get; } _IDatatype DowncastClone(); } public class Datatype : _IDatatype { @@ -3141,7 +3153,8 @@ public class Datatype : _IDatatype { public readonly bool _isCo; public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _superTraitTypes; - public Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes) { + public readonly Dafny.ISequence _superTraitNegativeTypes; + public Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { this._name = name; this._docString = docString; this._enclosingModule = enclosingModule; @@ -3151,14 +3164,15 @@ public Datatype(Dafny.ISequence name, Dafny.ISequence do this._isCo = isCo; this._attributes = attributes; this._superTraitTypes = superTraitTypes; + this._superTraitNegativeTypes = superTraitNegativeTypes; } public _IDatatype DowncastClone() { if (this is _IDatatype dt) { return dt; } - return new Datatype(_name, _docString, _enclosingModule, _typeParams, _ctors, _body, _isCo, _attributes, _superTraitTypes); + return new Datatype(_name, _docString, _enclosingModule, _typeParams, _ctors, _body, _isCo, _attributes, _superTraitTypes, _superTraitNegativeTypes); } public override bool Equals(object other) { var oth = other as DAST.Datatype; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._ctors, oth._ctors) && object.Equals(this._body, oth._body) && this._isCo == oth._isCo && object.Equals(this._attributes, oth._attributes) && object.Equals(this._superTraitTypes, oth._superTraitTypes); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._ctors, oth._ctors) && object.Equals(this._body, oth._body) && this._isCo == oth._isCo && object.Equals(this._attributes, oth._attributes) && object.Equals(this._superTraitTypes, oth._superTraitTypes) && object.Equals(this._superTraitNegativeTypes, oth._superTraitNegativeTypes); } public override int GetHashCode() { ulong hash = 5381; @@ -3172,6 +3186,7 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isCo)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._superTraitTypes)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._superTraitNegativeTypes)); return (int) hash; } public override string ToString() { @@ -3194,10 +3209,12 @@ public override string ToString() { s += Dafny.Helpers.ToString(this._attributes); s += ", "; s += Dafny.Helpers.ToString(this._superTraitTypes); + s += ", "; + s += Dafny.Helpers.ToString(this._superTraitNegativeTypes); s += ")"; return s; } - private static readonly DAST._IDatatype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, false, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly DAST._IDatatype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, false, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static DAST._IDatatype Default() { return theDefault; } @@ -3205,11 +3222,11 @@ public static DAST._IDatatype Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IDatatype create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes) { - return new Datatype(name, docString, enclosingModule, typeParams, ctors, body, isCo, attributes, superTraitTypes); + public static _IDatatype create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { + return new Datatype(name, docString, enclosingModule, typeParams, ctors, body, isCo, attributes, superTraitTypes, superTraitNegativeTypes); } - public static _IDatatype create_Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes) { - return create(name, docString, enclosingModule, typeParams, ctors, body, isCo, attributes, superTraitTypes); + public static _IDatatype create_Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { + return create(name, docString, enclosingModule, typeParams, ctors, body, isCo, attributes, superTraitTypes, superTraitNegativeTypes); } public bool is_Datatype { get { return true; } } public Dafny.ISequence dtor_name { @@ -3257,6 +3274,11 @@ public Dafny.ISequence dtor_superTraitTypes { return this._superTraitTypes; } } + public Dafny.ISequence dtor_superTraitNegativeTypes { + get { + return this._superTraitNegativeTypes; + } + } } public interface _IDatatypeDtor { diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index dcf9a60021b..4eee4d82e18 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -618,6 +618,25 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } else if (((t).dtor_traitType).is_GeneralTrait) { _17_parents = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsType()), _17_parents); } + if ((new BigInteger(((t).dtor_downcastableTraits).Count)).Sign == 1) { + BigInteger _hi3 = new BigInteger(((t).dtor_downcastableTraits).Count); + for (BigInteger _29_i = BigInteger.Zero; _29_i < _hi3; _29_i++) { + RAST._IType _30_downcastableTrait; + RAST._IType _out8; + _out8 = (this).GenType(((t).dtor_downcastableTraits).Select(_29_i), Defs.GenTypeContext.ForTraitParents()); + _30_downcastableTrait = _out8; + Std.Wrappers._IOption _31_downcastTraitOpt; + _31_downcastTraitOpt = (_30_downcastableTrait).ToDowncast(); + if ((_31_downcastTraitOpt).is_Some) { + _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((_31_downcastTraitOpt).dtor_value)); + } else { + RAST._IExpr _32_r; + RAST._IExpr _out9; + _out9 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Cannot convert "), (_30_downcastableTrait)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to its downcast version")), (this).InitEmptyExpr()); + _32_r = _out9; + } + } + } s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create((t).dtor_docString, Dafny.Sequence>.FromElements(), _1_rTypeParamsDecls, _10_traitFullType, _17_parents, _12_implBody))); s = Dafny.Sequence.Concat(s, _25_downcastDefinition); if (((t).dtor_traitType).is_GeneralTrait) { @@ -1193,185 +1212,202 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } else { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_73_downcastImplementationsOpt).dtor_value)); } - BigInteger _hi7 = new BigInteger(((c).dtor_superTraitTypes).Count); + BigInteger _hi7 = new BigInteger(((c).dtor_superTraitNegativeTypes).Count); for (BigInteger _75_i = BigInteger.Zero; _75_i < _hi7; _75_i++) { - DAST._IType _76_c; - _76_c = ((c).dtor_superTraitTypes).Select(_75_i); - if ((((_76_c).is_UserDefined) && ((((_76_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_76_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { - goto continue_3_0; - } - RAST._IType _77_cType; + RAST._IType _76_negativeTraitType; RAST._IType _out17; - _out17 = (this).GenType(_76_c, Defs.GenTypeContext.@default()); - _77_cType = _out17; - bool _78_isImplementing; - _78_isImplementing = true; - Std.Wrappers._IOption _79_downcastImplementationsOpt; - _79_downcastImplementationsOpt = Defs.__default.DowncastImplTraitFor(_3_rTypeParamsDecls, _77_cType, _78_isImplementing, _70_fullType); - if ((_79_downcastImplementationsOpt).is_None) { - RAST._IExpr _80_dummy; + _out17 = (this).GenType(((c).dtor_superTraitNegativeTypes).Select(_75_i), Defs.GenTypeContext.@default()); + _76_negativeTraitType = _out17; + Std.Wrappers._IOption _77_downcastDefinitionOpt; + _77_downcastDefinitionOpt = Defs.__default.DowncastNotImplFor(_3_rTypeParamsDecls, _76_negativeTraitType, _70_fullType); + if ((_77_downcastDefinitionOpt).is_None) { + RAST._IExpr _78_dummy; RAST._IExpr _out18; - _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation of "), (_77_cType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" for ")), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _80_dummy = _out18; + _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate negative downcast definition for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _78_dummy = _out18; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_79_downcastImplementationsOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_77_downcastDefinitionOpt).dtor_value)); + } + } + BigInteger _hi8 = new BigInteger(((c).dtor_superTraitTypes).Count); + for (BigInteger _79_i = BigInteger.Zero; _79_i < _hi8; _79_i++) { + DAST._IType _80_c; + _80_c = ((c).dtor_superTraitTypes).Select(_79_i); + if ((((_80_c).is_UserDefined) && ((((_80_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_80_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { + goto continue_3_0; + } + RAST._IType _81_cType; + RAST._IType _out19; + _out19 = (this).GenType(_80_c, Defs.GenTypeContext.@default()); + _81_cType = _out19; + bool _82_isImplementing; + _82_isImplementing = true; + Std.Wrappers._IOption _83_downcastImplementationsOpt; + _83_downcastImplementationsOpt = Defs.__default.DowncastImplTraitFor(_3_rTypeParamsDecls, _81_cType, _82_isImplementing, _70_fullType); + if ((_83_downcastImplementationsOpt).is_None) { + RAST._IExpr _84_dummy; + RAST._IExpr _out20; + _out20 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation of "), (_81_cType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" for ")), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _84_dummy = _out20; + } else { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_83_downcastImplementationsOpt).dtor_value)); } continue_3_0: ; } after_3_0: ; } - Dafny.ISequence _81_printImplBodyCases; - _81_printImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _82_hashImplBodyCases; - _82_hashImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _83_coerceImplBodyCases; - _83_coerceImplBodyCases = Dafny.Sequence.FromElements(); - BigInteger _hi8 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _84_i = BigInteger.Zero; _84_i < _hi8; _84_i++) { - DAST._IDatatypeCtor _85_ctor; - _85_ctor = ((c).dtor_ctors).Select(_84_i); - Dafny.ISequence _86_ctorMatch; - _86_ctorMatch = Defs.__default.escapeName((_85_ctor).dtor_name); - Dafny.ISequence _87_modulePrefix; + Dafny.ISequence _85_printImplBodyCases; + _85_printImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _86_hashImplBodyCases; + _86_hashImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _87_coerceImplBodyCases; + _87_coerceImplBodyCases = Dafny.Sequence.FromElements(); + BigInteger _hi9 = new BigInteger(((c).dtor_ctors).Count); + for (BigInteger _88_i = BigInteger.Zero; _88_i < _hi9; _88_i++) { + DAST._IDatatypeCtor _89_ctor; + _89_ctor = ((c).dtor_ctors).Select(_88_i); + Dafny.ISequence _90_ctorMatch; + _90_ctorMatch = Defs.__default.escapeName((_89_ctor).dtor_name); + Dafny.ISequence _91_modulePrefix; if (((((c).dtor_enclosingModule))).Equals(Dafny.Sequence.UnicodeFromString("_module"))) { - _87_modulePrefix = Dafny.Sequence.UnicodeFromString(""); + _91_modulePrefix = Dafny.Sequence.UnicodeFromString(""); } else { - _87_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); - } - Dafny.ISequence _88_ctorName; - _88_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_87_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_85_ctor).dtor_name)); - if (((new BigInteger((_88_ctorName).Count)) >= (new BigInteger(13))) && (((_88_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { - _88_ctorName = Dafny.Sequence.UnicodeFromString(""); - } - RAST._IExpr _89_printRhs; - _89_printRhs = (this).writeStr(Dafny.Sequence.Concat(_88_ctorName, (((_85_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); - RAST._IExpr _90_hashRhs; - _90_hashRhs = (this).InitEmptyExpr(); - Dafny.ISequence _91_coerceRhsArgs; - _91_coerceRhsArgs = Dafny.Sequence.FromElements(); - bool _92_isNumeric; - _92_isNumeric = false; - Dafny.ISequence _93_ctorMatchInner; - _93_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); - BigInteger _hi9 = new BigInteger(((_85_ctor).dtor_args).Count); - for (BigInteger _94_j = BigInteger.Zero; _94_j < _hi9; _94_j++) { - DAST._IDatatypeDtor _95_dtor; - _95_dtor = ((_85_ctor).dtor_args).Select(_94_j); - Dafny.ISequence _96_patternName; - _96_patternName = Defs.__default.escapeVar(((_95_dtor).dtor_formal).dtor_name); - DAST._IType _97_formalType; - _97_formalType = ((_95_dtor).dtor_formal).dtor_typ; - if (((_94_j).Sign == 0) && ((_96_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _92_isNumeric = true; - } - if (_92_isNumeric) { - _96_patternName = Std.Wrappers.Option>.GetOr((_95_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_94_j))); - } - if ((_97_formalType).is_Arrow) { - _90_hashRhs = (_90_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + _91_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); + } + Dafny.ISequence _92_ctorName; + _92_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_91_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_89_ctor).dtor_name)); + if (((new BigInteger((_92_ctorName).Count)) >= (new BigInteger(13))) && (((_92_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { + _92_ctorName = Dafny.Sequence.UnicodeFromString(""); + } + RAST._IExpr _93_printRhs; + _93_printRhs = (this).writeStr(Dafny.Sequence.Concat(_92_ctorName, (((_89_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); + RAST._IExpr _94_hashRhs; + _94_hashRhs = (this).InitEmptyExpr(); + Dafny.ISequence _95_coerceRhsArgs; + _95_coerceRhsArgs = Dafny.Sequence.FromElements(); + bool _96_isNumeric; + _96_isNumeric = false; + Dafny.ISequence _97_ctorMatchInner; + _97_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); + BigInteger _hi10 = new BigInteger(((_89_ctor).dtor_args).Count); + for (BigInteger _98_j = BigInteger.Zero; _98_j < _hi10; _98_j++) { + DAST._IDatatypeDtor _99_dtor; + _99_dtor = ((_89_ctor).dtor_args).Select(_98_j); + Dafny.ISequence _100_patternName; + _100_patternName = Defs.__default.escapeVar(((_99_dtor).dtor_formal).dtor_name); + DAST._IType _101_formalType; + _101_formalType = ((_99_dtor).dtor_formal).dtor_typ; + if (((_98_j).Sign == 0) && ((_100_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _96_isNumeric = true; + } + if (_96_isNumeric) { + _100_patternName = Std.Wrappers.Option>.GetOr((_99_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_98_j))); + } + if ((_101_formalType).is_Arrow) { + _94_hashRhs = (_94_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); } else { - _90_hashRhs = (_90_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_96_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); - } - _93_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatchInner, _96_patternName), Dafny.Sequence.UnicodeFromString(", ")); - if ((_94_j).Sign == 1) { - _89_printRhs = (_89_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); - } - _89_printRhs = (_89_printRhs).Then((((_97_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_96_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); - RAST._IExpr _98_coerceRhsArg = RAST.Expr.Default(); - RAST._IType _99_formalTpe; - RAST._IType _out19; - _out19 = (this).GenType(_97_formalType, Defs.GenTypeContext.@default()); - _99_formalTpe = _out19; - DAST._IType _100_newFormalType; - _100_newFormalType = (_97_formalType).Replace(_51_coerceMap); - RAST._IType _101_newFormalTpe; - _101_newFormalTpe = (_99_formalTpe).ReplaceMap(_52_rCoerceMap); - Std.Wrappers._IResult,RAST._IExpr>>> _102_upcastConverter; - _102_upcastConverter = (this).UpcastConversionLambda(_97_formalType, _99_formalTpe, _100_newFormalType, _101_newFormalTpe, _53_coerceMapToArg); - if ((_102_upcastConverter).is_Success) { - RAST._IExpr _103_coercionFunction; - _103_coercionFunction = (_102_upcastConverter).dtor_value; - _98_coerceRhsArg = (_103_coercionFunction).Apply1(RAST.Expr.create_Identifier(_96_patternName)); + _94_hashRhs = (_94_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_100_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); + } + _97_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_97_ctorMatchInner, _100_patternName), Dafny.Sequence.UnicodeFromString(", ")); + if ((_98_j).Sign == 1) { + _93_printRhs = (_93_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); + } + _93_printRhs = (_93_printRhs).Then((((_101_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_100_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); + RAST._IExpr _102_coerceRhsArg = RAST.Expr.Default(); + RAST._IType _103_formalTpe; + RAST._IType _out21; + _out21 = (this).GenType(_101_formalType, Defs.GenTypeContext.@default()); + _103_formalTpe = _out21; + DAST._IType _104_newFormalType; + _104_newFormalType = (_101_formalType).Replace(_51_coerceMap); + RAST._IType _105_newFormalTpe; + _105_newFormalTpe = (_103_formalTpe).ReplaceMap(_52_rCoerceMap); + Std.Wrappers._IResult,RAST._IExpr>>> _106_upcastConverter; + _106_upcastConverter = (this).UpcastConversionLambda(_101_formalType, _103_formalTpe, _104_newFormalType, _105_newFormalTpe, _53_coerceMapToArg); + if ((_106_upcastConverter).is_Success) { + RAST._IExpr _107_coercionFunction; + _107_coercionFunction = (_106_upcastConverter).dtor_value; + _102_coerceRhsArg = (_107_coercionFunction).Apply1(RAST.Expr.create_Identifier(_100_patternName)); } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_94_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); - _98_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_98_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); + _102_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); } - _91_coerceRhsArgs = Dafny.Sequence.Concat(_91_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_96_patternName, _98_coerceRhsArg))); + _95_coerceRhsArgs = Dafny.Sequence.Concat(_95_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_100_patternName, _102_coerceRhsArg))); } - RAST._IExpr _104_coerceRhs; - _104_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_85_ctor).dtor_name)), _91_coerceRhsArgs); - if (_92_isNumeric) { - _86_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_86_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _93_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + RAST._IExpr _108_coerceRhs; + _108_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_89_ctor).dtor_name)), _95_coerceRhsArgs); + if (_96_isNumeric) { + _90_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_90_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _97_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); } else { - _86_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_86_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _93_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + _90_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_90_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _97_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); } - if ((_85_ctor).dtor_hasAnyArgs) { - _89_printRhs = (_89_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); + if ((_89_ctor).dtor_hasAnyArgs) { + _93_printRhs = (_93_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); } - _89_printRhs = (_89_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); - _81_printImplBodyCases = Dafny.Sequence.Concat(_81_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _86_ctorMatch), RAST.Expr.create_Block(_89_printRhs)))); - _82_hashImplBodyCases = Dafny.Sequence.Concat(_82_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _86_ctorMatch), RAST.Expr.create_Block(_90_hashRhs)))); - _83_coerceImplBodyCases = Dafny.Sequence.Concat(_83_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _86_ctorMatch), RAST.Expr.create_Block(_104_coerceRhs)))); + _93_printRhs = (_93_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); + _85_printImplBodyCases = Dafny.Sequence.Concat(_85_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _90_ctorMatch), RAST.Expr.create_Block(_93_printRhs)))); + _86_hashImplBodyCases = Dafny.Sequence.Concat(_86_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _90_ctorMatch), RAST.Expr.create_Block(_94_hashRhs)))); + _87_coerceImplBodyCases = Dafny.Sequence.Concat(_87_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _90_ctorMatch), RAST.Expr.create_Block(_108_coerceRhs)))); } if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { - Dafny.ISequence _105_extraCases; - _105_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); - _81_printImplBodyCases = Dafny.Sequence.Concat(_81_printImplBodyCases, _105_extraCases); - _82_hashImplBodyCases = Dafny.Sequence.Concat(_82_hashImplBodyCases, _105_extraCases); - _83_coerceImplBodyCases = Dafny.Sequence.Concat(_83_coerceImplBodyCases, _105_extraCases); - } - Dafny.ISequence _106_defaultConstrainedTypeParams; - _106_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - Dafny.ISequence _107_rTypeParamsDeclsWithEq; - _107_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); - Dafny.ISequence _108_rTypeParamsDeclsWithHash; - _108_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - RAST._IExpr _109_printImplBody; - _109_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _81_printImplBodyCases); - RAST._IExpr _110_hashImplBody; - _110_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _82_hashImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams, _109_printImplBody))); + Dafny.ISequence _109_extraCases; + _109_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + _85_printImplBodyCases = Dafny.Sequence.Concat(_85_printImplBodyCases, _109_extraCases); + _86_hashImplBodyCases = Dafny.Sequence.Concat(_86_hashImplBodyCases, _109_extraCases); + _87_coerceImplBodyCases = Dafny.Sequence.Concat(_87_coerceImplBodyCases, _109_extraCases); + } + Dafny.ISequence _110_defaultConstrainedTypeParams; + _110_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + Dafny.ISequence _111_rTypeParamsDeclsWithEq; + _111_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); + Dafny.ISequence _112_rTypeParamsDeclsWithHash; + _112_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); + RAST._IExpr _113_printImplBody; + _113_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _85_printImplBodyCases); + RAST._IExpr _114_hashImplBody; + _114_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _86_hashImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams, _113_printImplBody))); if ((new BigInteger((_49_rCoerceTypeParams).Count)).Sign == 1) { - RAST._IExpr _111_coerceImplBody; - _111_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _83_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _69_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _111_coerceImplBody))); + RAST._IExpr _115_coerceImplBody; + _115_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _87_coerceImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _69_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _115_coerceImplBody))); } if ((new BigInteger((_9_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { - RAST._IType _112_instantiationType; + RAST._IType _116_instantiationType; if (_0_isRcWrapped) { - _112_instantiationType = RAST.__default.Rc(_69_datatypeType); + _116_instantiationType = RAST.__default.Rc(_69_datatypeType); } else { - _112_instantiationType = _69_datatypeType; + _116_instantiationType = _69_datatypeType; } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _69_datatypeType, _112_instantiationType, _9_singletonConstructors))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _69_datatypeType, _116_instantiationType, _9_singletonConstructors))); } if (_68_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_107_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), Dafny.Sequence.FromElements())))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_111_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), Dafny.Sequence.FromElements())))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_108_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), _110_hashImplBody))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_112_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), _114_hashImplBody))); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - RAST._IExpr _113_structName; - _113_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _114_structAssignments; - _114_structAssignments = Dafny.Sequence.FromElements(); - BigInteger _hi10 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); - for (BigInteger _115_i = BigInteger.Zero; _115_i < _hi10; _115_i++) { - DAST._IDatatypeDtor _116_dtor; - _116_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_115_i); - _114_structAssignments = Dafny.Sequence.Concat(_114_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_116_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); - } - RAST._IType _117_fullType; - _117_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); + RAST._IExpr _117_structName; + _117_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _118_structAssignments; + _118_structAssignments = Dafny.Sequence.FromElements(); + BigInteger _hi11 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); + for (BigInteger _119_i = BigInteger.Zero; _119_i < _hi11; _119_i++) { + DAST._IDatatypeDtor _120_dtor; + _120_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_119_i); + _118_structAssignments = Dafny.Sequence.Concat(_118_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_120_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); + } + RAST._IType _121_fullType; + _121_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); if ((false) && (_68_cIsEq)) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _117_fullType, _113_structName, _114_structAssignments))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _121_fullType, _117_structName, _118_structAssignments))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _117_fullType))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _121_fullType))); } - Dafny.ISequence _118_superTraitImplementations; - Dafny.ISequence _out20; - _out20 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, Dafny.Sequence.UnicodeFromString("datatype")); - _118_superTraitImplementations = _out20; - s = Dafny.Sequence.Concat(s, _118_superTraitImplementations); + Dafny.ISequence _122_superTraitImplementations; + Dafny.ISequence _out22; + _out22 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, Dafny.Sequence.UnicodeFromString("datatype")); + _122_superTraitImplementations = _out22; + s = Dafny.Sequence.Concat(s, _122_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -2452,15 +2488,20 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D _9_onExpr = ((this).read__macro).Apply1(_9_onExpr); readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); } else if (((_6_base).is_Trait) && (((_6_base).dtor_traitType).is_GeneralTrait)) { - RAST._IExpr _out9; - Defs._IOwnership _out10; - Dafny.ISet> _out11; - (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out9, out _out10, out _out11); - _9_onExpr = _out9; - _10_recOwnership = _out10; - _11_recIdents = _out11; - _9_onExpr = (this).FromGeneralBorrowToSelfBorrow(_9_onExpr, _10_recOwnership, env); - readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); + if ((@on).IsThisUpcast()) { + _9_onExpr = RAST.__default.self; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self"))); + } else { + RAST._IExpr _out9; + Defs._IOwnership _out10; + Dafny.ISet> _out11; + (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out9, out _out10, out _out11); + _9_onExpr = _out9; + _10_recOwnership = _out10; + _11_recIdents = _out11; + _9_onExpr = (this).FromGeneralBorrowToSelfBorrow(_9_onExpr, _10_recOwnership, env); + readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); + } } else if (((_6_base).is_Newtype) && (Defs.__default.IsNewtypeCopy((_6_base).dtor_range))) { RAST._IExpr _out12; Defs._IOwnership _out13; @@ -2488,13 +2529,18 @@ public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, D RAST._IExpr _12_onExpr = RAST.Expr.Default(); Dafny.ISet> _13_recIdents = Dafny.Set>.Empty; Defs._IOwnership _14_dummy = Defs.Ownership.Default(); - RAST._IExpr _out18; - Defs._IOwnership _out19; - Dafny.ISet> _out20; - (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out18, out _out19, out _out20); - _12_onExpr = _out18; - _14_dummy = _out19; - _13_recIdents = _out20; + if ((@on).IsThisUpcast()) { + _12_onExpr = RAST.__default.self; + _13_recIdents = Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self")); + } else { + RAST._IExpr _out18; + Defs._IOwnership _out19; + Dafny.ISet> _out20; + (this).GenExpr(@on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out18, out _out19, out _out20); + _12_onExpr = _out18; + _14_dummy = _out19; + _13_recIdents = _out20; + } readIdents = Dafny.Set>.Union(readIdents, _13_recIdents); Dafny.ISequence _15_renderedName; _15_renderedName = (this).GetMethodName(@on, name); @@ -5966,41 +6012,46 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir resultingOwnership = _out197; readIdents = _228_recIdents; } else if ((_221_selectContext).is_SelectContextGeneralTrait) { - RAST._IExpr _231_onExpr; - Defs._IOwnership _232_onOwned; - Dafny.ISet> _233_recIdents; - RAST._IExpr _out198; - Defs._IOwnership _out199; - Dafny.ISet> _out200; - (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out198, out _out199, out _out200); - _231_onExpr = _out198; - _232_onOwned = _out199; - _233_recIdents = _out200; - r = _231_onExpr; - if (!object.Equals(_231_onExpr, RAST.__default.self)) { - r = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(r); + Defs._IOwnership _231_onOwned = Defs.Ownership.Default(); + Dafny.ISet> _232_recIdents = Dafny.Set>.Empty; + readIdents = Dafny.Set>.FromElements(); + if ((_218_on).IsThisUpcast()) { + r = RAST.__default.self; + _232_recIdents = Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self")); + } else { + RAST._IExpr _out198; + Defs._IOwnership _out199; + Dafny.ISet> _out200; + (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out198, out _out199, out _out200); + r = _out198; + _231_onOwned = _out199; + _232_recIdents = _out200; + if (!object.Equals(r, RAST.__default.self)) { + r = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(r); + } } + readIdents = Dafny.Set>.Union(readIdents, _232_recIdents); r = ((r).Sel(Defs.__default.escapeVar(_219_field))).Apply0(); RAST._IExpr _out201; Defs._IOwnership _out202; (this).FromOwned(r, expectedOwnership, out _out201, out _out202); r = _out201; resultingOwnership = _out202; - readIdents = _233_recIdents; + readIdents = _232_recIdents; } else { - RAST._IExpr _234_onExpr; - Defs._IOwnership _235_onOwned; - Dafny.ISet> _236_recIdents; + RAST._IExpr _233_onExpr; + Defs._IOwnership _234_onOwned; + Dafny.ISet> _235_recIdents; RAST._IExpr _out203; Defs._IOwnership _out204; Dafny.ISet> _out205; (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out203, out _out204, out _out205); - _234_onExpr = _out203; - _235_onOwned = _out204; - _236_recIdents = _out205; - r = _234_onExpr; - if (!object.Equals(_234_onExpr, RAST.__default.self)) { - RAST._IExpr _source3 = _234_onExpr; + _233_onExpr = _out203; + _234_onOwned = _out204; + _235_recIdents = _out205; + r = _233_onExpr; + if (!object.Equals(_233_onExpr, RAST.__default.self)) { + RAST._IExpr _source3 = _233_onExpr; { if (_source3.is_UnaryOp) { Dafny.ISequence op10 = _source3.dtor_op1; @@ -6048,7 +6099,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir (this).FromOwned(r, expectedOwnership, out _out206, out _out207); r = _out206; resultingOwnership = _out207; - readIdents = _236_recIdents; + readIdents = _235_recIdents; } return ; } @@ -6057,63 +6108,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Index) { - DAST._IExpression _237_on = _source0.dtor_expr; - DAST._ICollKind _238_collKind = _source0.dtor_collKind; - Dafny.ISequence _239_indices = _source0.dtor_indices; + DAST._IExpression _236_on = _source0.dtor_expr; + DAST._ICollKind _237_collKind = _source0.dtor_collKind; + Dafny.ISequence _238_indices = _source0.dtor_indices; { - RAST._IExpr _240_onExpr; - Defs._IOwnership _241_onOwned; - Dafny.ISet> _242_recIdents; + RAST._IExpr _239_onExpr; + Defs._IOwnership _240_onOwned; + Dafny.ISet> _241_recIdents; RAST._IExpr _out208; Defs._IOwnership _out209; Dafny.ISet> _out210; - (this).GenExpr(_237_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out208, out _out209, out _out210); - _240_onExpr = _out208; - _241_onOwned = _out209; - _242_recIdents = _out210; - readIdents = _242_recIdents; - r = _240_onExpr; - bool _243_hadArray; - _243_hadArray = false; - if (object.Equals(_238_collKind, DAST.CollKind.create_Array())) { + (this).GenExpr(_236_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out208, out _out209, out _out210); + _239_onExpr = _out208; + _240_onOwned = _out209; + _241_recIdents = _out210; + readIdents = _241_recIdents; + r = _239_onExpr; + bool _242_hadArray; + _242_hadArray = false; + if (object.Equals(_237_collKind, DAST.CollKind.create_Array())) { r = ((this).read__macro).Apply1(r); - _243_hadArray = true; - if ((new BigInteger((_239_indices).Count)) > (BigInteger.One)) { + _242_hadArray = true; + if ((new BigInteger((_238_indices).Count)) > (BigInteger.One)) { r = (r).Sel(Dafny.Sequence.UnicodeFromString("data")); } } - BigInteger _hi10 = new BigInteger((_239_indices).Count); - for (BigInteger _244_i = BigInteger.Zero; _244_i < _hi10; _244_i++) { - if (object.Equals(_238_collKind, DAST.CollKind.create_Array())) { - RAST._IExpr _245_idx; - Defs._IOwnership _246_idxOwned; - Dafny.ISet> _247_recIdentsIdx; + BigInteger _hi10 = new BigInteger((_238_indices).Count); + for (BigInteger _243_i = BigInteger.Zero; _243_i < _hi10; _243_i++) { + if (object.Equals(_237_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _244_idx; + Defs._IOwnership _245_idxOwned; + Dafny.ISet> _246_recIdentsIdx; RAST._IExpr _out211; Defs._IOwnership _out212; Dafny.ISet> _out213; - (this).GenExpr((_239_indices).Select(_244_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out211, out _out212, out _out213); - _245_idx = _out211; - _246_idxOwned = _out212; - _247_recIdentsIdx = _out213; - _245_idx = RAST.__default.IntoUsize(_245_idx); - r = RAST.Expr.create_SelectIndex(r, _245_idx); - readIdents = Dafny.Set>.Union(readIdents, _247_recIdentsIdx); + (this).GenExpr((_238_indices).Select(_243_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out211, out _out212, out _out213); + _244_idx = _out211; + _245_idxOwned = _out212; + _246_recIdentsIdx = _out213; + _244_idx = RAST.__default.IntoUsize(_244_idx); + r = RAST.Expr.create_SelectIndex(r, _244_idx); + readIdents = Dafny.Set>.Union(readIdents, _246_recIdentsIdx); } else { - RAST._IExpr _248_idx; - Defs._IOwnership _249_idxOwned; - Dafny.ISet> _250_recIdentsIdx; + RAST._IExpr _247_idx; + Defs._IOwnership _248_idxOwned; + Dafny.ISet> _249_recIdentsIdx; RAST._IExpr _out214; Defs._IOwnership _out215; Dafny.ISet> _out216; - (this).GenExpr((_239_indices).Select(_244_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out214, out _out215, out _out216); - _248_idx = _out214; - _249_idxOwned = _out215; - _250_recIdentsIdx = _out216; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_248_idx); - readIdents = Dafny.Set>.Union(readIdents, _250_recIdentsIdx); + (this).GenExpr((_238_indices).Select(_243_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out214, out _out215, out _out216); + _247_idx = _out214; + _248_idxOwned = _out215; + _249_recIdentsIdx = _out216; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_247_idx); + readIdents = Dafny.Set>.Union(readIdents, _249_recIdentsIdx); } } - if (_243_hadArray) { + if (_242_hadArray) { r = (r).Clone(); } RAST._IExpr _out217; @@ -6128,63 +6179,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IndexRange) { - DAST._IExpression _251_on = _source0.dtor_expr; - bool _252_isArray = _source0.dtor_isArray; - Std.Wrappers._IOption _253_low = _source0.dtor_low; - Std.Wrappers._IOption _254_high = _source0.dtor_high; + DAST._IExpression _250_on = _source0.dtor_expr; + bool _251_isArray = _source0.dtor_isArray; + Std.Wrappers._IOption _252_low = _source0.dtor_low; + Std.Wrappers._IOption _253_high = _source0.dtor_high; { - Defs._IOwnership _255_onExpectedOwnership; - if (_252_isArray) { + Defs._IOwnership _254_onExpectedOwnership; + if (_251_isArray) { if (((this).pointerType).is_Raw) { - _255_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); + _254_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); } else { - _255_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); + _254_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); } } else { - _255_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); + _254_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); } - RAST._IExpr _256_onExpr; - Defs._IOwnership _257_onOwned; - Dafny.ISet> _258_recIdents; + RAST._IExpr _255_onExpr; + Defs._IOwnership _256_onOwned; + Dafny.ISet> _257_recIdents; RAST._IExpr _out219; Defs._IOwnership _out220; Dafny.ISet> _out221; - (this).GenExpr(_251_on, selfIdent, env, _255_onExpectedOwnership, out _out219, out _out220, out _out221); - _256_onExpr = _out219; - _257_onOwned = _out220; - _258_recIdents = _out221; - readIdents = _258_recIdents; - Dafny.ISequence _259_methodName; - if ((_253_low).is_Some) { - if ((_254_high).is_Some) { - _259_methodName = Dafny.Sequence.UnicodeFromString("slice"); + (this).GenExpr(_250_on, selfIdent, env, _254_onExpectedOwnership, out _out219, out _out220, out _out221); + _255_onExpr = _out219; + _256_onOwned = _out220; + _257_recIdents = _out221; + readIdents = _257_recIdents; + Dafny.ISequence _258_methodName; + if ((_252_low).is_Some) { + if ((_253_high).is_Some) { + _258_methodName = Dafny.Sequence.UnicodeFromString("slice"); } else { - _259_methodName = Dafny.Sequence.UnicodeFromString("drop"); + _258_methodName = Dafny.Sequence.UnicodeFromString("drop"); } - } else if ((_254_high).is_Some) { - _259_methodName = Dafny.Sequence.UnicodeFromString("take"); + } else if ((_253_high).is_Some) { + _258_methodName = Dafny.Sequence.UnicodeFromString("take"); } else { - _259_methodName = Dafny.Sequence.UnicodeFromString(""); + _258_methodName = Dafny.Sequence.UnicodeFromString(""); } - Dafny.ISequence _260_arguments; - _260_arguments = Dafny.Sequence.FromElements(); - Std.Wrappers._IOption _source5 = _253_low; + Dafny.ISequence _259_arguments; + _259_arguments = Dafny.Sequence.FromElements(); + Std.Wrappers._IOption _source5 = _252_low; { if (_source5.is_Some) { - DAST._IExpression _261_l = _source5.dtor_value; + DAST._IExpression _260_l = _source5.dtor_value; { - RAST._IExpr _262_lExpr; - Defs._IOwnership _263___v115; - Dafny.ISet> _264_recIdentsL; + RAST._IExpr _261_lExpr; + Defs._IOwnership _262___v115; + Dafny.ISet> _263_recIdentsL; RAST._IExpr _out222; Defs._IOwnership _out223; Dafny.ISet> _out224; - (this).GenExpr(_261_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out222, out _out223, out _out224); - _262_lExpr = _out222; - _263___v115 = _out223; - _264_recIdentsL = _out224; - _260_arguments = Dafny.Sequence.Concat(_260_arguments, Dafny.Sequence.FromElements(_262_lExpr)); - readIdents = Dafny.Set>.Union(readIdents, _264_recIdentsL); + (this).GenExpr(_260_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out222, out _out223, out _out224); + _261_lExpr = _out222; + _262___v115 = _out223; + _263_recIdentsL = _out224; + _259_arguments = Dafny.Sequence.Concat(_259_arguments, Dafny.Sequence.FromElements(_261_lExpr)); + readIdents = Dafny.Set>.Union(readIdents, _263_recIdentsL); } goto after_match5; } @@ -6192,23 +6243,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match5: ; - Std.Wrappers._IOption _source6 = _254_high; + Std.Wrappers._IOption _source6 = _253_high; { if (_source6.is_Some) { - DAST._IExpression _265_h = _source6.dtor_value; + DAST._IExpression _264_h = _source6.dtor_value; { - RAST._IExpr _266_hExpr; - Defs._IOwnership _267___v116; - Dafny.ISet> _268_recIdentsH; + RAST._IExpr _265_hExpr; + Defs._IOwnership _266___v116; + Dafny.ISet> _267_recIdentsH; RAST._IExpr _out225; Defs._IOwnership _out226; Dafny.ISet> _out227; - (this).GenExpr(_265_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out225, out _out226, out _out227); - _266_hExpr = _out225; - _267___v116 = _out226; - _268_recIdentsH = _out227; - _260_arguments = Dafny.Sequence.Concat(_260_arguments, Dafny.Sequence.FromElements(_266_hExpr)); - readIdents = Dafny.Set>.Union(readIdents, _268_recIdentsH); + (this).GenExpr(_264_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out225, out _out226, out _out227); + _265_hExpr = _out225; + _266___v116 = _out226; + _267_recIdentsH = _out227; + _259_arguments = Dafny.Sequence.Concat(_259_arguments, Dafny.Sequence.FromElements(_265_hExpr)); + readIdents = Dafny.Set>.Union(readIdents, _267_recIdentsH); } goto after_match6; } @@ -6216,21 +6267,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match6: ; - r = _256_onExpr; - if (_252_isArray) { - if (!(_259_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - _259_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _259_methodName); + r = _255_onExpr; + if (_251_isArray) { + if (!(_258_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + _258_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _258_methodName); } - Dafny.ISequence _269_object__suffix; + Dafny.ISequence _268_object__suffix; if (((this).pointerType).is_Raw) { - _269_object__suffix = Dafny.Sequence.UnicodeFromString(""); + _268_object__suffix = Dafny.Sequence.UnicodeFromString(""); } else { - _269_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); + _268_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); } - r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _259_methodName), _269_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_256_onExpr), _260_arguments)); + r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _258_methodName), _268_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_255_onExpr), _259_arguments)); } else { - if (!(_259_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - r = ((r).Sel(_259_methodName)).Apply(_260_arguments); + if (!(_258_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + r = ((r).Sel(_258_methodName)).Apply(_259_arguments); } else { r = (r).Clone(); } @@ -6247,28 +6298,28 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TupleSelect) { - DAST._IExpression _270_on = _source0.dtor_expr; - BigInteger _271_idx = _source0.dtor_index; - DAST._IType _272_fieldType = _source0.dtor_fieldType; + DAST._IExpression _269_on = _source0.dtor_expr; + BigInteger _270_idx = _source0.dtor_index; + DAST._IType _271_fieldType = _source0.dtor_fieldType; { - RAST._IExpr _273_onExpr; - Defs._IOwnership _274_onOwnership; - Dafny.ISet> _275_recIdents; + RAST._IExpr _272_onExpr; + Defs._IOwnership _273_onOwnership; + Dafny.ISet> _274_recIdents; RAST._IExpr _out230; Defs._IOwnership _out231; Dafny.ISet> _out232; - (this).GenExpr(_270_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out230, out _out231, out _out232); - _273_onExpr = _out230; - _274_onOwnership = _out231; - _275_recIdents = _out232; - Dafny.ISequence _276_selName; - _276_selName = Std.Strings.__default.OfNat(_271_idx); - DAST._IType _source7 = _272_fieldType; + (this).GenExpr(_269_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out230, out _out231, out _out232); + _272_onExpr = _out230; + _273_onOwnership = _out231; + _274_recIdents = _out232; + Dafny.ISequence _275_selName; + _275_selName = Std.Strings.__default.OfNat(_270_idx); + DAST._IType _source7 = _271_fieldType; { if (_source7.is_Tuple) { - Dafny.ISequence _277_tps = _source7.dtor_Tuple_a0; - if (((_272_fieldType).is_Tuple) && ((new BigInteger((_277_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { - _276_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _276_selName); + Dafny.ISequence _276_tps = _source7.dtor_Tuple_a0; + if (((_271_fieldType).is_Tuple) && ((new BigInteger((_276_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { + _275_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _275_selName); } goto after_match7; } @@ -6276,13 +6327,13 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match7: ; - r = ((_273_onExpr).Sel(_276_selName)).Clone(); + r = ((_272_onExpr).Sel(_275_selName)).Clone(); RAST._IExpr _out233; Defs._IOwnership _out234; (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out233, out _out234); r = _out233; resultingOwnership = _out234; - readIdents = _275_recIdents; + readIdents = _274_recIdents; return ; } goto after_match0; @@ -6290,14 +6341,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Call) { - DAST._IExpression _278_on = _source0.dtor_on; - DAST._ICallName _279_name = _source0.dtor_callName; - Dafny.ISequence _280_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _281_args = _source0.dtor_args; + DAST._IExpression _277_on = _source0.dtor_on; + DAST._ICallName _278_name = _source0.dtor_callName; + Dafny.ISequence _279_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _280_args = _source0.dtor_args; { RAST._IExpr _out235; Dafny.ISet> _out236; - (this).GenOwnedCallPart(_278_on, selfIdent, _279_name, _280_typeArgs, _281_args, env, out _out235, out _out236); + (this).GenOwnedCallPart(_277_on, selfIdent, _278_name, _279_typeArgs, _280_args, env, out _out235, out _out236); r = _out235; readIdents = _out236; RAST._IExpr _out237; @@ -6312,85 +6363,85 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Lambda) { - Dafny.ISequence _282_paramsDafny = _source0.dtor_params; - DAST._IType _283_retType = _source0.dtor_retType; - Dafny.ISequence _284_body = _source0.dtor_body; + Dafny.ISequence _281_paramsDafny = _source0.dtor_params; + DAST._IType _282_retType = _source0.dtor_retType; + Dafny.ISequence _283_body = _source0.dtor_body; { - Dafny.ISequence _285_params; + Dafny.ISequence _284_params; Dafny.ISequence _out239; - _out239 = (this).GenParams(_282_paramsDafny, true); - _285_params = _out239; - Dafny.ISequence> _286_paramNames; - _286_paramNames = Dafny.Sequence>.FromElements(); - Dafny.IMap,RAST._IType> _287_paramTypesMap; - _287_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); - BigInteger _hi11 = new BigInteger((_285_params).Count); - for (BigInteger _288_i = BigInteger.Zero; _288_i < _hi11; _288_i++) { - Dafny.ISequence _289_name; - _289_name = ((_285_params).Select(_288_i)).dtor_name; - _286_paramNames = Dafny.Sequence>.Concat(_286_paramNames, Dafny.Sequence>.FromElements(_289_name)); - _287_paramTypesMap = Dafny.Map, RAST._IType>.Update(_287_paramTypesMap, _289_name, ((_285_params).Select(_288_i)).dtor_tpe); - } - Defs._IEnvironment _290_subEnv; - _290_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_286_paramNames, _287_paramTypesMap, Dafny.Set>.FromElements())); - RAST._IExpr _291_recursiveGen; - Dafny.ISet> _292_recIdents; - Defs._IEnvironment _293___v118; + _out239 = (this).GenParams(_281_paramsDafny, true); + _284_params = _out239; + Dafny.ISequence> _285_paramNames; + _285_paramNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _286_paramTypesMap; + _286_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); + BigInteger _hi11 = new BigInteger((_284_params).Count); + for (BigInteger _287_i = BigInteger.Zero; _287_i < _hi11; _287_i++) { + Dafny.ISequence _288_name; + _288_name = ((_284_params).Select(_287_i)).dtor_name; + _285_paramNames = Dafny.Sequence>.Concat(_285_paramNames, Dafny.Sequence>.FromElements(_288_name)); + _286_paramTypesMap = Dafny.Map, RAST._IType>.Update(_286_paramTypesMap, _288_name, ((_284_params).Select(_287_i)).dtor_tpe); + } + Defs._IEnvironment _289_subEnv; + _289_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_285_paramNames, _286_paramTypesMap, Dafny.Set>.FromElements())); + RAST._IExpr _290_recursiveGen; + Dafny.ISet> _291_recIdents; + Defs._IEnvironment _292___v118; RAST._IExpr _out240; Dafny.ISet> _out241; Defs._IEnvironment _out242; - (this).GenStmts(_284_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _290_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out240, out _out241, out _out242); - _291_recursiveGen = _out240; - _292_recIdents = _out241; - _293___v118 = _out242; + (this).GenStmts(_283_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _289_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out240, out _out241, out _out242); + _290_recursiveGen = _out240; + _291_recIdents = _out241; + _292___v118 = _out242; readIdents = Dafny.Set>.FromElements(); - _292_recIdents = Dafny.Set>.Difference(_292_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_294_paramNames) => ((System.Func>>)(() => { + _291_recIdents = Dafny.Set>.Difference(_291_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_293_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); - foreach (Dafny.ISequence _compr_0 in (_294_paramNames).CloneAsArray()) { - Dafny.ISequence _295_name = (Dafny.ISequence)_compr_0; - if ((_294_paramNames).Contains(_295_name)) { - _coll0.Add(_295_name); + foreach (Dafny.ISequence _compr_0 in (_293_paramNames).CloneAsArray()) { + Dafny.ISequence _294_name = (Dafny.ISequence)_compr_0; + if ((_293_paramNames).Contains(_294_name)) { + _coll0.Add(_294_name); } } return Dafny.Set>.FromCollection(_coll0); - }))())(_286_paramNames)); - RAST._IExpr _296_allReadCloned; - _296_allReadCloned = (this).InitEmptyExpr(); - while (!(_292_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _297_next; - foreach (Dafny.ISequence _assign_such_that_1 in (_292_recIdents).Elements) { - _297_next = (Dafny.ISequence)_assign_such_that_1; - if ((_292_recIdents).Contains(_297_next)) { + }))())(_285_paramNames)); + RAST._IExpr _295_allReadCloned; + _295_allReadCloned = (this).InitEmptyExpr(); + while (!(_291_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _296_next; + foreach (Dafny.ISequence _assign_such_that_1 in (_291_recIdents).Elements) { + _296_next = (Dafny.ISequence)_assign_such_that_1; + if ((_291_recIdents).Contains(_296_next)) { goto after__ASSIGN_SUCH_THAT_1; } } throw new System.Exception("assign-such-that search produced no value"); after__ASSIGN_SUCH_THAT_1: ; - if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_297_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { - RAST._IExpr _298_selfCloned; - Defs._IOwnership _299___v119; - Dafny.ISet> _300___v120; + if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_296_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { + RAST._IExpr _297_selfCloned; + Defs._IOwnership _298___v119; + Dafny.ISet> _299___v120; RAST._IExpr _out243; Defs._IOwnership _out244; Dafny.ISet> _out245; (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out243, out _out244, out _out245); - _298_selfCloned = _out243; - _299___v119 = _out244; - _300___v120 = _out245; - _296_allReadCloned = (_296_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_298_selfCloned))); - } else if (!((_286_paramNames).Contains(_297_next))) { - RAST._IExpr _301_copy; - _301_copy = (RAST.Expr.create_Identifier(_297_next)).Clone(); - _296_allReadCloned = (_296_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _297_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_301_copy))); - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_297_next)); + _297_selfCloned = _out243; + _298___v119 = _out244; + _299___v120 = _out245; + _295_allReadCloned = (_295_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_297_selfCloned))); + } else if (!((_285_paramNames).Contains(_296_next))) { + RAST._IExpr _300_copy; + _300_copy = (RAST.Expr.create_Identifier(_296_next)).Clone(); + _295_allReadCloned = (_295_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _296_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_300_copy))); + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_296_next)); } - _292_recIdents = Dafny.Set>.Difference(_292_recIdents, Dafny.Set>.FromElements(_297_next)); + _291_recIdents = Dafny.Set>.Difference(_291_recIdents, Dafny.Set>.FromElements(_296_next)); } - RAST._IType _302_retTypeGen; + RAST._IType _301_retTypeGen; RAST._IType _out246; - _out246 = (this).GenType(_283_retType, Defs.GenTypeContext.@default()); - _302_retTypeGen = _out246; - r = RAST.Expr.create_Block((_296_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_285_params, Std.Wrappers.Option.create_Some(_302_retTypeGen), RAST.Expr.create_Block(_291_recursiveGen))))); + _out246 = (this).GenType(_282_retType, Defs.GenTypeContext.@default()); + _301_retTypeGen = _out246; + r = RAST.Expr.create_Block((_295_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_284_params, Std.Wrappers.Option.create_Some(_301_retTypeGen), RAST.Expr.create_Block(_290_recursiveGen))))); RAST._IExpr _out247; Defs._IOwnership _out248; (this).FromOwned(r, expectedOwnership, out _out247, out _out248); @@ -6403,70 +6454,70 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_BetaRedex) { - Dafny.ISequence<_System._ITuple2> _303_values = _source0.dtor_values; - DAST._IType _304_retType = _source0.dtor_retType; - DAST._IExpression _305_expr = _source0.dtor_expr; + Dafny.ISequence<_System._ITuple2> _302_values = _source0.dtor_values; + DAST._IType _303_retType = _source0.dtor_retType; + DAST._IExpression _304_expr = _source0.dtor_expr; { - Dafny.ISequence> _306_paramNames; - _306_paramNames = Dafny.Sequence>.FromElements(); - Dafny.ISequence _307_paramFormals; + Dafny.ISequence> _305_paramNames; + _305_paramNames = Dafny.Sequence>.FromElements(); + Dafny.ISequence _306_paramFormals; Dafny.ISequence _out249; - _out249 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_308_value) => { - return (_308_value).dtor__0; - })), _303_values), false); - _307_paramFormals = _out249; - Dafny.IMap,RAST._IType> _309_paramTypes; - _309_paramTypes = Dafny.Map, RAST._IType>.FromElements(); - Dafny.ISet> _310_paramNamesSet; - _310_paramNamesSet = Dafny.Set>.FromElements(); - BigInteger _hi12 = new BigInteger((_303_values).Count); - for (BigInteger _311_i = BigInteger.Zero; _311_i < _hi12; _311_i++) { - Dafny.ISequence _312_name; - _312_name = (((_303_values).Select(_311_i)).dtor__0).dtor_name; - Dafny.ISequence _313_rName; - _313_rName = Defs.__default.escapeVar(_312_name); - _306_paramNames = Dafny.Sequence>.Concat(_306_paramNames, Dafny.Sequence>.FromElements(_313_rName)); - _309_paramTypes = Dafny.Map, RAST._IType>.Update(_309_paramTypes, _313_rName, ((_307_paramFormals).Select(_311_i)).dtor_tpe); - _310_paramNamesSet = Dafny.Set>.Union(_310_paramNamesSet, Dafny.Set>.FromElements(_313_rName)); + _out249 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_307_value) => { + return (_307_value).dtor__0; + })), _302_values), false); + _306_paramFormals = _out249; + Dafny.IMap,RAST._IType> _308_paramTypes; + _308_paramTypes = Dafny.Map, RAST._IType>.FromElements(); + Dafny.ISet> _309_paramNamesSet; + _309_paramNamesSet = Dafny.Set>.FromElements(); + BigInteger _hi12 = new BigInteger((_302_values).Count); + for (BigInteger _310_i = BigInteger.Zero; _310_i < _hi12; _310_i++) { + Dafny.ISequence _311_name; + _311_name = (((_302_values).Select(_310_i)).dtor__0).dtor_name; + Dafny.ISequence _312_rName; + _312_rName = Defs.__default.escapeVar(_311_name); + _305_paramNames = Dafny.Sequence>.Concat(_305_paramNames, Dafny.Sequence>.FromElements(_312_rName)); + _308_paramTypes = Dafny.Map, RAST._IType>.Update(_308_paramTypes, _312_rName, ((_306_paramFormals).Select(_310_i)).dtor_tpe); + _309_paramNamesSet = Dafny.Set>.Union(_309_paramNamesSet, Dafny.Set>.FromElements(_312_rName)); } readIdents = Dafny.Set>.FromElements(); r = (this).InitEmptyExpr(); - BigInteger _hi13 = new BigInteger((_303_values).Count); - for (BigInteger _314_i = BigInteger.Zero; _314_i < _hi13; _314_i++) { - RAST._IType _315_typeGen; + BigInteger _hi13 = new BigInteger((_302_values).Count); + for (BigInteger _313_i = BigInteger.Zero; _313_i < _hi13; _313_i++) { + RAST._IType _314_typeGen; RAST._IType _out250; - _out250 = (this).GenType((((_303_values).Select(_314_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); - _315_typeGen = _out250; - RAST._IExpr _316_valueGen; - Defs._IOwnership _317___v121; - Dafny.ISet> _318_recIdents; + _out250 = (this).GenType((((_302_values).Select(_313_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); + _314_typeGen = _out250; + RAST._IExpr _315_valueGen; + Defs._IOwnership _316___v121; + Dafny.ISet> _317_recIdents; RAST._IExpr _out251; Defs._IOwnership _out252; Dafny.ISet> _out253; - (this).GenExpr(((_303_values).Select(_314_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out251, out _out252, out _out253); - _316_valueGen = _out251; - _317___v121 = _out252; - _318_recIdents = _out253; - r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_303_values).Select(_314_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_315_typeGen), Std.Wrappers.Option.create_Some(_316_valueGen))); - readIdents = Dafny.Set>.Union(readIdents, _318_recIdents); - } - Defs._IEnvironment _319_newEnv; - _319_newEnv = Defs.Environment.create(_306_paramNames, _309_paramTypes, Dafny.Set>.FromElements()); - RAST._IExpr _320_recGen; - Defs._IOwnership _321_recOwned; - Dafny.ISet> _322_recIdents; + (this).GenExpr(((_302_values).Select(_313_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out251, out _out252, out _out253); + _315_valueGen = _out251; + _316___v121 = _out252; + _317_recIdents = _out253; + r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_302_values).Select(_313_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_314_typeGen), Std.Wrappers.Option.create_Some(_315_valueGen))); + readIdents = Dafny.Set>.Union(readIdents, _317_recIdents); + } + Defs._IEnvironment _318_newEnv; + _318_newEnv = Defs.Environment.create(_305_paramNames, _308_paramTypes, Dafny.Set>.FromElements()); + RAST._IExpr _319_recGen; + Defs._IOwnership _320_recOwned; + Dafny.ISet> _321_recIdents; RAST._IExpr _out254; Defs._IOwnership _out255; Dafny.ISet> _out256; - (this).GenExpr(_305_expr, selfIdent, _319_newEnv, expectedOwnership, out _out254, out _out255, out _out256); - _320_recGen = _out254; - _321_recOwned = _out255; - _322_recIdents = _out256; - readIdents = Dafny.Set>.Difference(_322_recIdents, _310_paramNamesSet); - r = RAST.Expr.create_Block((r).Then(_320_recGen)); + (this).GenExpr(_304_expr, selfIdent, _318_newEnv, expectedOwnership, out _out254, out _out255, out _out256); + _319_recGen = _out254; + _320_recOwned = _out255; + _321_recIdents = _out256; + readIdents = Dafny.Set>.Difference(_321_recIdents, _309_paramNamesSet); + r = RAST.Expr.create_Block((r).Then(_319_recGen)); RAST._IExpr _out257; Defs._IOwnership _out258; - (this).FromOwnership(r, _321_recOwned, expectedOwnership, out _out257, out _out258); + (this).FromOwnership(r, _320_recOwned, expectedOwnership, out _out257, out _out258); r = _out257; resultingOwnership = _out258; return ; @@ -6476,40 +6527,40 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IIFE) { - Dafny.ISequence _323_name = _source0.dtor_ident; - DAST._IType _324_tpe = _source0.dtor_typ; - DAST._IExpression _325_value = _source0.dtor_value; - DAST._IExpression _326_iifeBody = _source0.dtor_iifeBody; + Dafny.ISequence _322_name = _source0.dtor_ident; + DAST._IType _323_tpe = _source0.dtor_typ; + DAST._IExpression _324_value = _source0.dtor_value; + DAST._IExpression _325_iifeBody = _source0.dtor_iifeBody; { - RAST._IExpr _327_valueGen; - Defs._IOwnership _328___v122; - Dafny.ISet> _329_recIdents; + RAST._IExpr _326_valueGen; + Defs._IOwnership _327___v122; + Dafny.ISet> _328_recIdents; RAST._IExpr _out259; Defs._IOwnership _out260; Dafny.ISet> _out261; - (this).GenExpr(_325_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out259, out _out260, out _out261); - _327_valueGen = _out259; - _328___v122 = _out260; - _329_recIdents = _out261; - readIdents = _329_recIdents; - RAST._IType _330_valueTypeGen; + (this).GenExpr(_324_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out259, out _out260, out _out261); + _326_valueGen = _out259; + _327___v122 = _out260; + _328_recIdents = _out261; + readIdents = _328_recIdents; + RAST._IType _329_valueTypeGen; RAST._IType _out262; - _out262 = (this).GenType(_324_tpe, Defs.GenTypeContext.@default()); - _330_valueTypeGen = _out262; - Dafny.ISequence _331_iifeVar; - _331_iifeVar = Defs.__default.escapeVar(_323_name); - RAST._IExpr _332_bodyGen; - Defs._IOwnership _333___v123; - Dafny.ISet> _334_bodyIdents; + _out262 = (this).GenType(_323_tpe, Defs.GenTypeContext.@default()); + _329_valueTypeGen = _out262; + Dafny.ISequence _330_iifeVar; + _330_iifeVar = Defs.__default.escapeVar(_322_name); + RAST._IExpr _331_bodyGen; + Defs._IOwnership _332___v123; + Dafny.ISet> _333_bodyIdents; RAST._IExpr _out263; Defs._IOwnership _out264; Dafny.ISet> _out265; - (this).GenExpr(_326_iifeBody, selfIdent, (env).AddAssigned(_331_iifeVar, _330_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out263, out _out264, out _out265); - _332_bodyGen = _out263; - _333___v123 = _out264; - _334_bodyIdents = _out265; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_334_bodyIdents, Dafny.Set>.FromElements(_331_iifeVar))); - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _331_iifeVar, Std.Wrappers.Option.create_Some(_330_valueTypeGen), Std.Wrappers.Option.create_Some(_327_valueGen))).Then(_332_bodyGen)); + (this).GenExpr(_325_iifeBody, selfIdent, (env).AddAssigned(_330_iifeVar, _329_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out263, out _out264, out _out265); + _331_bodyGen = _out263; + _332___v123 = _out264; + _333_bodyIdents = _out265; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_333_bodyIdents, Dafny.Set>.FromElements(_330_iifeVar))); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _330_iifeVar, Std.Wrappers.Option.create_Some(_329_valueTypeGen), Std.Wrappers.Option.create_Some(_326_valueGen))).Then(_331_bodyGen)); RAST._IExpr _out266; Defs._IOwnership _out267; (this).FromOwned(r, expectedOwnership, out _out266, out _out267); @@ -6522,38 +6573,38 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Apply) { - DAST._IExpression _335_func = _source0.dtor_expr; - Dafny.ISequence _336_args = _source0.dtor_args; + DAST._IExpression _334_func = _source0.dtor_expr; + Dafny.ISequence _335_args = _source0.dtor_args; { - RAST._IExpr _337_funcExpr; - Defs._IOwnership _338___v124; - Dafny.ISet> _339_recIdents; + RAST._IExpr _336_funcExpr; + Defs._IOwnership _337___v124; + Dafny.ISet> _338_recIdents; RAST._IExpr _out268; Defs._IOwnership _out269; Dafny.ISet> _out270; - (this).GenExpr(_335_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out268, out _out269, out _out270); - _337_funcExpr = _out268; - _338___v124 = _out269; - _339_recIdents = _out270; - readIdents = _339_recIdents; - Dafny.ISequence _340_rArgs; - _340_rArgs = Dafny.Sequence.FromElements(); - BigInteger _hi14 = new BigInteger((_336_args).Count); - for (BigInteger _341_i = BigInteger.Zero; _341_i < _hi14; _341_i++) { - RAST._IExpr _342_argExpr; - Defs._IOwnership _343_argOwned; - Dafny.ISet> _344_argIdents; + (this).GenExpr(_334_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out268, out _out269, out _out270); + _336_funcExpr = _out268; + _337___v124 = _out269; + _338_recIdents = _out270; + readIdents = _338_recIdents; + Dafny.ISequence _339_rArgs; + _339_rArgs = Dafny.Sequence.FromElements(); + BigInteger _hi14 = new BigInteger((_335_args).Count); + for (BigInteger _340_i = BigInteger.Zero; _340_i < _hi14; _340_i++) { + RAST._IExpr _341_argExpr; + Defs._IOwnership _342_argOwned; + Dafny.ISet> _343_argIdents; RAST._IExpr _out271; Defs._IOwnership _out272; Dafny.ISet> _out273; - (this).GenExpr((_336_args).Select(_341_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out271, out _out272, out _out273); - _342_argExpr = _out271; - _343_argOwned = _out272; - _344_argIdents = _out273; - _340_rArgs = Dafny.Sequence.Concat(_340_rArgs, Dafny.Sequence.FromElements(_342_argExpr)); - readIdents = Dafny.Set>.Union(readIdents, _344_argIdents); - } - r = (_337_funcExpr).Apply(_340_rArgs); + (this).GenExpr((_335_args).Select(_340_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out271, out _out272, out _out273); + _341_argExpr = _out271; + _342_argOwned = _out272; + _343_argIdents = _out273; + _339_rArgs = Dafny.Sequence.Concat(_339_rArgs, Dafny.Sequence.FromElements(_341_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _343_argIdents); + } + r = (_336_funcExpr).Apply(_339_rArgs); RAST._IExpr _out274; Defs._IOwnership _out275; (this).FromOwned(r, expectedOwnership, out _out274, out _out275); @@ -6566,31 +6617,31 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TypeTest) { - DAST._IExpression _345_on = _source0.dtor_on; - Dafny.ISequence> _346_dType = _source0.dtor_dType; - Dafny.ISequence _347_variant = _source0.dtor_variant; + DAST._IExpression _344_on = _source0.dtor_on; + Dafny.ISequence> _345_dType = _source0.dtor_dType; + Dafny.ISequence _346_variant = _source0.dtor_variant; { - RAST._IExpr _348_exprGen; - Defs._IOwnership _349___v125; - Dafny.ISet> _350_recIdents; + RAST._IExpr _347_exprGen; + Defs._IOwnership _348___v125; + Dafny.ISet> _349_recIdents; RAST._IExpr _out276; Defs._IOwnership _out277; Dafny.ISet> _out278; - (this).GenExpr(_345_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out276, out _out277, out _out278); - _348_exprGen = _out276; - _349___v125 = _out277; - _350_recIdents = _out278; - RAST._IExpr _351_variantExprPath; + (this).GenExpr(_344_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out276, out _out277, out _out278); + _347_exprGen = _out276; + _348___v125 = _out277; + _349_recIdents = _out278; + RAST._IExpr _350_variantExprPath; RAST._IExpr _out279; - _out279 = (this).GenPathExpr(Dafny.Sequence>.Concat(_346_dType, Dafny.Sequence>.FromElements(_347_variant)), true); - _351_variantExprPath = _out279; - r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_348_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _351_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); + _out279 = (this).GenPathExpr(Dafny.Sequence>.Concat(_345_dType, Dafny.Sequence>.FromElements(_346_variant)), true); + _350_variantExprPath = _out279; + r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_347_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _350_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); RAST._IExpr _out280; Defs._IOwnership _out281; (this).FromOwned(r, expectedOwnership, out _out280, out _out281); r = _out280; resultingOwnership = _out281; - readIdents = _350_recIdents; + readIdents = _349_recIdents; return ; } goto after_match0; @@ -6598,77 +6649,77 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Is) { - DAST._IExpression _352_expr = _source0.dtor_expr; - DAST._IType _353_fromTyp = _source0.dtor_fromType; - DAST._IType _354_toTyp = _source0.dtor_toType; + DAST._IExpression _351_expr = _source0.dtor_expr; + DAST._IType _352_fromTyp = _source0.dtor_fromType; + DAST._IType _353_toTyp = _source0.dtor_toType; { - RAST._IType _355_fromTpe; + RAST._IType _354_fromTpe; RAST._IType _out282; - _out282 = (this).GenType(_353_fromTyp, Defs.GenTypeContext.@default()); - _355_fromTpe = _out282; - RAST._IType _356_toTpe; + _out282 = (this).GenType(_352_fromTyp, Defs.GenTypeContext.@default()); + _354_fromTpe = _out282; + RAST._IType _355_toTpe; RAST._IType _out283; - _out283 = (this).GenType(_354_toTyp, Defs.GenTypeContext.@default()); - _356_toTpe = _out283; - if (((_355_fromTpe).IsObjectOrPointer()) && ((_356_toTpe).IsObjectOrPointer())) { - RAST._IExpr _357_expr; - Defs._IOwnership _358_recOwned; - Dafny.ISet> _359_recIdents; + _out283 = (this).GenType(_353_toTyp, Defs.GenTypeContext.@default()); + _355_toTpe = _out283; + if (((_354_fromTpe).IsObjectOrPointer()) && ((_355_toTpe).IsObjectOrPointer())) { + RAST._IExpr _356_expr; + Defs._IOwnership _357_recOwned; + Dafny.ISet> _358_recIdents; RAST._IExpr _out284; Defs._IOwnership _out285; Dafny.ISet> _out286; - (this).GenExpr(_352_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out284, out _out285, out _out286); - _357_expr = _out284; - _358_recOwned = _out285; - _359_recIdents = _out286; - r = (((_357_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_356_toTpe).ObjectOrPointerUnderlying()))).Apply0(); + (this).GenExpr(_351_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out284, out _out285, out _out286); + _356_expr = _out284; + _357_recOwned = _out285; + _358_recIdents = _out286; + r = (((_356_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_355_toTpe).ObjectOrPointerUnderlying()))).Apply0(); RAST._IExpr _out287; Defs._IOwnership _out288; - (this).FromOwnership(r, _358_recOwned, expectedOwnership, out _out287, out _out288); + (this).FromOwnership(r, _357_recOwned, expectedOwnership, out _out287, out _out288); r = _out287; resultingOwnership = _out288; - readIdents = _359_recIdents; + readIdents = _358_recIdents; } else { - RAST._IExpr _360_expr; - Defs._IOwnership _361_recOwned; - Dafny.ISet> _362_recIdents; + RAST._IExpr _359_expr; + Defs._IOwnership _360_recOwned; + Dafny.ISet> _361_recIdents; RAST._IExpr _out289; Defs._IOwnership _out290; Dafny.ISet> _out291; - (this).GenExpr(_352_expr, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out289, out _out290, out _out291); - _360_expr = _out289; - _361_recOwned = _out290; - _362_recIdents = _out291; - bool _363_isDatatype; - _363_isDatatype = (_354_toTyp).IsDatatype(); - bool _364_isGeneralTrait; - _364_isGeneralTrait = (!(_363_isDatatype)) && ((_354_toTyp).IsGeneralTrait()); - if ((_363_isDatatype) || (_364_isGeneralTrait)) { - bool _365_isDowncast; - _365_isDowncast = (_354_toTyp).Extends(_353_fromTyp); - if (_365_isDowncast) { - DAST._IType _366_underlyingType; - if (_363_isDatatype) { - _366_underlyingType = (_354_toTyp).GetDatatypeType(); + (this).GenExpr(_351_expr, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out289, out _out290, out _out291); + _359_expr = _out289; + _360_recOwned = _out290; + _361_recIdents = _out291; + bool _362_isDatatype; + _362_isDatatype = (_353_toTyp).IsDatatype(); + bool _363_isGeneralTrait; + _363_isGeneralTrait = (!(_362_isDatatype)) && ((_353_toTyp).IsGeneralTrait()); + if ((_362_isDatatype) || (_363_isGeneralTrait)) { + bool _364_isDowncast; + _364_isDowncast = (_353_toTyp).Extends(_352_fromTyp); + if (_364_isDowncast) { + DAST._IType _365_underlyingType; + if (_362_isDatatype) { + _365_underlyingType = (_353_toTyp).GetDatatypeType(); } else { - _366_underlyingType = (_354_toTyp).GetGeneralTraitType(); + _365_underlyingType = (_353_toTyp).GetGeneralTraitType(); } - RAST._IType _367_toTpeRaw; + RAST._IType _366_toTpeRaw; RAST._IType _out292; - _out292 = (this).GenType(_366_underlyingType, Defs.GenTypeContext.@default()); - _367_toTpeRaw = _out292; - Std.Wrappers._IOption _368_toTpeRawDowncastOpt; - _368_toTpeRawDowncastOpt = (_367_toTpeRaw).ToDowncastExpr(); - if ((_368_toTpeRawDowncastOpt).is_Some) { - _360_expr = (this).FromGeneralBorrowToSelfBorrow(_360_expr, Defs.Ownership.create_OwnershipBorrowed(), env); - if (_363_isDatatype) { - _360_expr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_360_expr); + _out292 = (this).GenType(_365_underlyingType, Defs.GenTypeContext.@default()); + _366_toTpeRaw = _out292; + Std.Wrappers._IOption _367_toTpeRawDowncastOpt; + _367_toTpeRawDowncastOpt = (_366_toTpeRaw).ToDowncastExpr(); + if ((_367_toTpeRawDowncastOpt).is_Some) { + _359_expr = (this).FromGeneralBorrowToSelfBorrow(_359_expr, Defs.Ownership.create_OwnershipBorrowed(), env); + if (_362_isDatatype) { + _359_expr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_359_expr); } - r = (((_368_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_360_expr); - _361_recOwned = Defs.Ownership.create_OwnershipOwned(); + r = (((_367_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_359_expr); + _360_recOwned = Defs.Ownership.create_OwnershipOwned(); } else { RAST._IExpr _out293; - _out293 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_367_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); + _out293 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_366_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); r = _out293; } } else { @@ -6683,10 +6734,10 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } RAST._IExpr _out296; Defs._IOwnership _out297; - (this).FromOwnership(r, _361_recOwned, expectedOwnership, out _out296, out _out297); + (this).FromOwnership(r, _360_recOwned, expectedOwnership, out _out296, out _out297); r = _out296; resultingOwnership = _out297; - readIdents = _362_recIdents; + readIdents = _361_recIdents; } return ; } @@ -6710,25 +6761,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBoundedPool) { - DAST._IExpression _369_of = _source0.dtor_of; + DAST._IExpression _368_of = _source0.dtor_of; { - RAST._IExpr _370_exprGen; - Defs._IOwnership _371___v126; - Dafny.ISet> _372_recIdents; + RAST._IExpr _369_exprGen; + Defs._IOwnership _370___v126; + Dafny.ISet> _371_recIdents; RAST._IExpr _out300; Defs._IOwnership _out301; Dafny.ISet> _out302; - (this).GenExpr(_369_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out300, out _out301, out _out302); - _370_exprGen = _out300; - _371___v126 = _out301; - _372_recIdents = _out302; - r = ((_370_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + (this).GenExpr(_368_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out300, out _out301, out _out302); + _369_exprGen = _out300; + _370___v126 = _out301; + _371_recIdents = _out302; + r = ((_369_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out303; Defs._IOwnership _out304; (this).FromOwned(r, expectedOwnership, out _out303, out _out304); r = _out303; resultingOwnership = _out304; - readIdents = _372_recIdents; + readIdents = _371_recIdents; return ; } goto after_match0; @@ -6736,21 +6787,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SeqBoundedPool) { - DAST._IExpression _373_of = _source0.dtor_of; - bool _374_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _372_of = _source0.dtor_of; + bool _373_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _375_exprGen; - Defs._IOwnership _376___v127; - Dafny.ISet> _377_recIdents; + RAST._IExpr _374_exprGen; + Defs._IOwnership _375___v127; + Dafny.ISet> _376_recIdents; RAST._IExpr _out305; Defs._IOwnership _out306; Dafny.ISet> _out307; - (this).GenExpr(_373_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out305, out _out306, out _out307); - _375_exprGen = _out305; - _376___v127 = _out306; - _377_recIdents = _out307; - r = ((_375_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_374_includeDuplicates)) { + (this).GenExpr(_372_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out305, out _out306, out _out307); + _374_exprGen = _out305; + _375___v127 = _out306; + _376_recIdents = _out307; + r = ((_374_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_373_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } RAST._IExpr _out308; @@ -6758,7 +6809,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir (this).FromOwned(r, expectedOwnership, out _out308, out _out309); r = _out308; resultingOwnership = _out309; - readIdents = _377_recIdents; + readIdents = _376_recIdents; return ; } goto after_match0; @@ -6766,21 +6817,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MultisetBoundedPool) { - DAST._IExpression _378_of = _source0.dtor_of; - bool _379_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _377_of = _source0.dtor_of; + bool _378_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _380_exprGen; - Defs._IOwnership _381___v128; - Dafny.ISet> _382_recIdents; + RAST._IExpr _379_exprGen; + Defs._IOwnership _380___v128; + Dafny.ISet> _381_recIdents; RAST._IExpr _out310; Defs._IOwnership _out311; Dafny.ISet> _out312; - (this).GenExpr(_378_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out310, out _out311, out _out312); - _380_exprGen = _out310; - _381___v128 = _out311; - _382_recIdents = _out312; - r = ((_380_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_379_includeDuplicates)) { + (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out310, out _out311, out _out312); + _379_exprGen = _out310; + _380___v128 = _out311; + _381_recIdents = _out312; + r = ((_379_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_378_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } RAST._IExpr _out313; @@ -6788,7 +6839,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir (this).FromOwned(r, expectedOwnership, out _out313, out _out314); r = _out313; resultingOwnership = _out314; - readIdents = _382_recIdents; + readIdents = _381_recIdents; return ; } goto after_match0; @@ -6796,20 +6847,20 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBoundedPool) { - DAST._IExpression _383_of = _source0.dtor_of; + DAST._IExpression _382_of = _source0.dtor_of; { - RAST._IExpr _384_exprGen; - Defs._IOwnership _385___v129; - Dafny.ISet> _386_recIdents; + RAST._IExpr _383_exprGen; + Defs._IOwnership _384___v129; + Dafny.ISet> _385_recIdents; RAST._IExpr _out315; Defs._IOwnership _out316; Dafny.ISet> _out317; - (this).GenExpr(_383_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out315, out _out316, out _out317); - _384_exprGen = _out315; - _385___v129 = _out316; - _386_recIdents = _out317; - r = ((((_384_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - readIdents = _386_recIdents; + (this).GenExpr(_382_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out315, out _out316, out _out317); + _383_exprGen = _out315; + _384___v129 = _out316; + _385_recIdents = _out317; + r = ((((_383_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + readIdents = _385_recIdents; RAST._IExpr _out318; Defs._IOwnership _out319; (this).FromOwned(r, expectedOwnership, out _out318, out _out319); @@ -6821,20 +6872,20 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_ExactBoundedPool) { - DAST._IExpression _387_of = _source0.dtor_of; + DAST._IExpression _386_of = _source0.dtor_of; { - RAST._IExpr _388_exprGen; - Defs._IOwnership _389___v130; - Dafny.ISet> _390_recIdents; + RAST._IExpr _387_exprGen; + Defs._IOwnership _388___v130; + Dafny.ISet> _389_recIdents; RAST._IExpr _out320; Defs._IOwnership _out321; Dafny.ISet> _out322; - (this).GenExpr(_387_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out320, out _out321, out _out322); - _388_exprGen = _out320; - _389___v130 = _out321; - _390_recIdents = _out322; - r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_388_exprGen); - readIdents = _390_recIdents; + (this).GenExpr(_386_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out320, out _out321, out _out322); + _387_exprGen = _out320; + _388___v130 = _out321; + _389_recIdents = _out322; + r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_387_exprGen); + readIdents = _389_recIdents; RAST._IExpr _out323; Defs._IOwnership _out324; (this).FromOwned(r, expectedOwnership, out _out323, out _out324); @@ -6846,49 +6897,49 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IntRange) { - DAST._IType _391_typ = _source0.dtor_elemType; - DAST._IExpression _392_lo = _source0.dtor_lo; - DAST._IExpression _393_hi = _source0.dtor_hi; - bool _394_up = _source0.dtor_up; + DAST._IType _390_typ = _source0.dtor_elemType; + DAST._IExpression _391_lo = _source0.dtor_lo; + DAST._IExpression _392_hi = _source0.dtor_hi; + bool _393_up = _source0.dtor_up; { - RAST._IExpr _395_lo; - Defs._IOwnership _396___v131; - Dafny.ISet> _397_recIdentsLo; + RAST._IExpr _394_lo; + Defs._IOwnership _395___v131; + Dafny.ISet> _396_recIdentsLo; RAST._IExpr _out325; Defs._IOwnership _out326; Dafny.ISet> _out327; - (this).GenExpr(_392_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out325, out _out326, out _out327); - _395_lo = _out325; - _396___v131 = _out326; - _397_recIdentsLo = _out327; - RAST._IExpr _398_hi; - Defs._IOwnership _399___v132; - Dafny.ISet> _400_recIdentsHi; + (this).GenExpr(_391_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out325, out _out326, out _out327); + _394_lo = _out325; + _395___v131 = _out326; + _396_recIdentsLo = _out327; + RAST._IExpr _397_hi; + Defs._IOwnership _398___v132; + Dafny.ISet> _399_recIdentsHi; RAST._IExpr _out328; Defs._IOwnership _out329; Dafny.ISet> _out330; - (this).GenExpr(_393_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out328, out _out329, out _out330); - _398_hi = _out328; - _399___v132 = _out329; - _400_recIdentsHi = _out330; - if (_394_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_395_lo, _398_hi)); + (this).GenExpr(_392_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out328, out _out329, out _out330); + _397_hi = _out328; + _398___v132 = _out329; + _399_recIdentsHi = _out330; + if (_393_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_394_lo, _397_hi)); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_398_hi, _395_lo)); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_397_hi, _394_lo)); } - if (!((_391_typ).is_Primitive)) { - RAST._IType _401_tpe; + if (!((_390_typ).is_Primitive)) { + RAST._IType _400_tpe; RAST._IType _out331; - _out331 = (this).GenType(_391_typ, Defs.GenTypeContext.@default()); - _401_tpe = _out331; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_401_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); + _out331 = (this).GenType(_390_typ, Defs.GenTypeContext.@default()); + _400_tpe = _out331; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_400_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); } RAST._IExpr _out332; Defs._IOwnership _out333; (this).FromOwned(r, expectedOwnership, out _out332, out _out333); r = _out332; resultingOwnership = _out333; - readIdents = Dafny.Set>.Union(_397_recIdentsLo, _400_recIdentsHi); + readIdents = Dafny.Set>.Union(_396_recIdentsLo, _399_recIdentsHi); return ; } goto after_match0; @@ -6896,30 +6947,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_UnboundedIntRange) { - DAST._IExpression _402_start = _source0.dtor_start; - bool _403_up = _source0.dtor_up; + DAST._IExpression _401_start = _source0.dtor_start; + bool _402_up = _source0.dtor_up; { - RAST._IExpr _404_start; - Defs._IOwnership _405___v133; - Dafny.ISet> _406_recIdentStart; + RAST._IExpr _403_start; + Defs._IOwnership _404___v133; + Dafny.ISet> _405_recIdentStart; RAST._IExpr _out334; Defs._IOwnership _out335; Dafny.ISet> _out336; - (this).GenExpr(_402_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); - _404_start = _out334; - _405___v133 = _out335; - _406_recIdentStart = _out336; - if (_403_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_404_start); + (this).GenExpr(_401_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); + _403_start = _out334; + _404___v133 = _out335; + _405_recIdentStart = _out336; + if (_402_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_403_start); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_404_start); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_403_start); } RAST._IExpr _out337; Defs._IOwnership _out338; (this).FromOwned(r, expectedOwnership, out _out337, out _out338); r = _out337; resultingOwnership = _out338; - readIdents = _406_recIdentStart; + readIdents = _405_recIdentStart; return ; } goto after_match0; @@ -6927,18 +6978,18 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBuilder) { - DAST._IType _407_keyType = _source0.dtor_keyType; - DAST._IType _408_valueType = _source0.dtor_valueType; + DAST._IType _406_keyType = _source0.dtor_keyType; + DAST._IType _407_valueType = _source0.dtor_valueType; { - RAST._IType _409_kType; + RAST._IType _408_kType; RAST._IType _out339; - _out339 = (this).GenType(_407_keyType, Defs.GenTypeContext.@default()); - _409_kType = _out339; - RAST._IType _410_vType; + _out339 = (this).GenType(_406_keyType, Defs.GenTypeContext.@default()); + _408_kType = _out339; + RAST._IType _409_vType; RAST._IType _out340; - _out340 = (this).GenType(_408_valueType, Defs.GenTypeContext.@default()); - _410_vType = _out340; - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_409_kType, _410_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + _out340 = (this).GenType(_407_valueType, Defs.GenTypeContext.@default()); + _409_vType = _out340; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_408_kType, _409_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); RAST._IExpr _out341; Defs._IOwnership _out342; (this).FromOwned(r, expectedOwnership, out _out341, out _out342); @@ -6952,14 +7003,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBuilder) { - DAST._IType _411_elemType = _source0.dtor_elemType; + DAST._IType _410_elemType = _source0.dtor_elemType; { - RAST._IType _412_eType; + RAST._IType _411_eType; RAST._IType _out343; - _out343 = (this).GenType(_411_elemType, Defs.GenTypeContext.@default()); - _412_eType = _out343; + _out343 = (this).GenType(_410_elemType, Defs.GenTypeContext.@default()); + _411_eType = _out343; readIdents = Dafny.Set>.FromElements(); - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_412_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_411_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); RAST._IExpr _out344; Defs._IOwnership _out345; (this).FromOwned(r, expectedOwnership, out _out344, out _out345); @@ -6971,63 +7022,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } } { - DAST._IType _413_elemType = _source0.dtor_elemType; - DAST._IExpression _414_collection = _source0.dtor_collection; - bool _415_is__forall = _source0.dtor_is__forall; - DAST._IExpression _416_lambda = _source0.dtor_lambda; + DAST._IType _412_elemType = _source0.dtor_elemType; + DAST._IExpression _413_collection = _source0.dtor_collection; + bool _414_is__forall = _source0.dtor_is__forall; + DAST._IExpression _415_lambda = _source0.dtor_lambda; { - RAST._IType _417_tpe; + RAST._IType _416_tpe; RAST._IType _out346; - _out346 = (this).GenType(_413_elemType, Defs.GenTypeContext.@default()); - _417_tpe = _out346; - RAST._IExpr _418_collectionGen; - Defs._IOwnership _419___v134; - Dafny.ISet> _420_recIdents; + _out346 = (this).GenType(_412_elemType, Defs.GenTypeContext.@default()); + _416_tpe = _out346; + RAST._IExpr _417_collectionGen; + Defs._IOwnership _418___v134; + Dafny.ISet> _419_recIdents; RAST._IExpr _out347; Defs._IOwnership _out348; Dafny.ISet> _out349; - (this).GenExpr(_414_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out347, out _out348, out _out349); - _418_collectionGen = _out347; - _419___v134 = _out348; - _420_recIdents = _out349; - Dafny.ISequence _421_extraAttributes; - _421_extraAttributes = Dafny.Sequence.FromElements(); - if ((((((_414_collection).is_IntRange) || ((_414_collection).is_UnboundedIntRange)) || ((_414_collection).is_SeqBoundedPool)) || ((_414_collection).is_ExactBoundedPool)) || ((_414_collection).is_MultisetBoundedPool)) { - _421_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); - } - if ((_416_lambda).is_Lambda) { - Dafny.ISequence _422_formals; - _422_formals = (_416_lambda).dtor_params; - Dafny.ISequence _423_newFormals; - _423_newFormals = Dafny.Sequence.FromElements(); - BigInteger _hi15 = new BigInteger((_422_formals).Count); - for (BigInteger _424_i = BigInteger.Zero; _424_i < _hi15; _424_i++) { - var _pat_let_tv0 = _421_extraAttributes; - var _pat_let_tv1 = _422_formals; - _423_newFormals = Dafny.Sequence.Concat(_423_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_422_formals).Select(_424_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _425_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_424_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _426_dt__update_hattributes_h0 => DAST.Formal.create((_425_dt__update__tmp_h0).dtor_name, (_425_dt__update__tmp_h0).dtor_typ, _426_dt__update_hattributes_h0))))))); - } - DAST._IExpression _427_newLambda; - DAST._IExpression _428_dt__update__tmp_h1 = _416_lambda; - Dafny.ISequence _429_dt__update_hparams_h0 = _423_newFormals; - _427_newLambda = DAST.Expression.create_Lambda(_429_dt__update_hparams_h0, (_428_dt__update__tmp_h1).dtor_retType, (_428_dt__update__tmp_h1).dtor_body); - RAST._IExpr _430_lambdaGen; - Defs._IOwnership _431___v135; - Dafny.ISet> _432_recLambdaIdents; + (this).GenExpr(_413_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out347, out _out348, out _out349); + _417_collectionGen = _out347; + _418___v134 = _out348; + _419_recIdents = _out349; + Dafny.ISequence _420_extraAttributes; + _420_extraAttributes = Dafny.Sequence.FromElements(); + if ((((((_413_collection).is_IntRange) || ((_413_collection).is_UnboundedIntRange)) || ((_413_collection).is_SeqBoundedPool)) || ((_413_collection).is_ExactBoundedPool)) || ((_413_collection).is_MultisetBoundedPool)) { + _420_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); + } + if ((_415_lambda).is_Lambda) { + Dafny.ISequence _421_formals; + _421_formals = (_415_lambda).dtor_params; + Dafny.ISequence _422_newFormals; + _422_newFormals = Dafny.Sequence.FromElements(); + BigInteger _hi15 = new BigInteger((_421_formals).Count); + for (BigInteger _423_i = BigInteger.Zero; _423_i < _hi15; _423_i++) { + var _pat_let_tv0 = _420_extraAttributes; + var _pat_let_tv1 = _421_formals; + _422_newFormals = Dafny.Sequence.Concat(_422_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_421_formals).Select(_423_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _424_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_423_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _425_dt__update_hattributes_h0 => DAST.Formal.create((_424_dt__update__tmp_h0).dtor_name, (_424_dt__update__tmp_h0).dtor_typ, _425_dt__update_hattributes_h0))))))); + } + DAST._IExpression _426_newLambda; + DAST._IExpression _427_dt__update__tmp_h1 = _415_lambda; + Dafny.ISequence _428_dt__update_hparams_h0 = _422_newFormals; + _426_newLambda = DAST.Expression.create_Lambda(_428_dt__update_hparams_h0, (_427_dt__update__tmp_h1).dtor_retType, (_427_dt__update__tmp_h1).dtor_body); + RAST._IExpr _429_lambdaGen; + Defs._IOwnership _430___v135; + Dafny.ISet> _431_recLambdaIdents; RAST._IExpr _out350; Defs._IOwnership _out351; Dafny.ISet> _out352; - (this).GenExpr(_427_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out350, out _out351, out _out352); - _430_lambdaGen = _out350; - _431___v135 = _out351; - _432_recLambdaIdents = _out352; - Dafny.ISequence _433_fn; - if (_415_is__forall) { - _433_fn = Dafny.Sequence.UnicodeFromString("all"); + (this).GenExpr(_426_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out350, out _out351, out _out352); + _429_lambdaGen = _out350; + _430___v135 = _out351; + _431_recLambdaIdents = _out352; + Dafny.ISequence _432_fn; + if (_414_is__forall) { + _432_fn = Dafny.Sequence.UnicodeFromString("all"); } else { - _433_fn = Dafny.Sequence.UnicodeFromString("any"); + _432_fn = Dafny.Sequence.UnicodeFromString("any"); } - r = ((_418_collectionGen).Sel(_433_fn)).Apply1(((_430_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); - readIdents = Dafny.Set>.Union(_420_recIdents, _432_recLambdaIdents); + r = ((_417_collectionGen).Sel(_432_fn)).Apply1(((_429_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); + readIdents = Dafny.Set>.Union(_419_recIdents, _431_recLambdaIdents); } else { RAST._IExpr _out353; _out353 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index 2f4bf7adf64..57fefbcfd6c 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -572,6 +572,20 @@ public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, RAST.Type.create_DynType(RAST.__default.AnyTrait), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_4_isBody))), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(datatypeType), Std.Wrappers.Option.create_Some(_6_asBody))))))); } } + public static Std.Wrappers._IOption DowncastNotImplFor(Dafny.ISequence rTypeParamsDecls, RAST._IType traitType, RAST._IType datatypeType) + { + Std.Wrappers._IOption _0_valueOrError0 = (traitType).ToDowncast(); + if ((_0_valueOrError0).IsFailure()) { + return (_0_valueOrError0).PropagateFailure(); + } else { + RAST._IType _1_downcast__type = (_0_valueOrError0).Extract(); + bool _2_isRc = (datatypeType).IsRc(); + RAST._IType _3_datatypeTypeRaw = ((_2_isRc) ? ((datatypeType).RcUnderlying()) : (datatypeType)); + RAST._IExpr _4_isBody = RAST.Expr.create_LiteralBool(false); + RAST._IExpr _5_asBody = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply0(); + return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, _3_datatypeTypeRaw, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat((_3_datatypeTypeRaw)._ToString(Dafny.Sequence.UnicodeFromString("")), Dafny.Sequence.UnicodeFromString(" does not implement that trait")), RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_4_isBody))), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(traitType), Std.Wrappers.Option.create_Some(_5_asBody))))))); + } + } public static Std.Wrappers._IOption DowncastImplTraitFor(Dafny.ISequence rTypeParamsDecls, RAST._IType traitType, bool implementsTrait, RAST._IType datatypeType) { Std.Wrappers._IOption _0_valueOrError0 = (traitType).ToDowncast(); diff --git a/Source/DafnyCore/Resolver/ModuleResolver.cs b/Source/DafnyCore/Resolver/ModuleResolver.cs index ade4003df23..077c6f7c03a 100644 --- a/Source/DafnyCore/Resolver/ModuleResolver.cs +++ b/Source/DafnyCore/Resolver/ModuleResolver.cs @@ -2111,6 +2111,12 @@ void ResolveParentTraitTypes(TopLevelDeclWithMembers cl, Graph = BDatatype(i: int) { function GetInt(): int { i } } +datatype CDatatype extends SuperTrait = CDatatype(i: int) { // But not superSubTrait + function GetBool(): bool { + i % 2 == 0 + } +} + method StaticWithGenerics(c: bool, a: T, b: T) returns (t: T){ if c { t := a; @@ -151,8 +157,20 @@ method MainBDatatype() { var sxa := sx as BDatatype; } +method MainCDatatype() { + var c := CDatatype(1); + var s := c as SuperTrait; + expect c.GetBool() == s.GetBool(); + expect !(s is SuperSubTrait); + expect c is CDatatype; + expect !(s is ADatatype); + var d := s as CDatatype; + expect c == d; +} + method Main() { MainADatatype(); MainBDatatype(); + MainCDatatype(); print "Main passed all the tests"; } \ No newline at end of file From 01100877371da08d2fbf5064c8a96bdce6eea299 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 9 Dec 2024 23:20:05 +0100 Subject: [PATCH 23/69] WIP to fix remaining bugs --- Makefile | 18 +- Source/DafnyCore/Backends/Dafny/AST.dfy | 4 +- Source/DafnyCore/Backends/Dafny/ASTBuilder.cs | 24 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 114 ++- .../Rust/Dafny-compiler-rust-definitions.dfy | 76 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 177 ++-- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 115 ++- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 952 ++++++++++-------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 54 +- .../DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 8 +- .../comp/rust/small/01-hash.dfy.expect | 2 + .../comp/rust/small/02-binary.dfy.expect | 2 + .../comp/rust/small/06-type-bounds.dfy | 25 + .../comp/rust/small/06-type-bounds.dfy.expect | 2 + .../rust/small/07-instantiated-methods.dfy | 20 + .../small/07-instantiated-methods.dfy.expect | 2 + .../08-not-all-trait-items-implemented.dfy | 27 + ...not-all-trait-items-implemented.dfy.expect | 2 + .../comp/rust/small/09-trait-method.dfy | 11 + 19 files changed, 1013 insertions(+), 622 deletions(-) create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy diff --git a/Makefile b/Makefile index 07389337b05..72082165662 100644 --- a/Makefile +++ b/Makefile @@ -37,20 +37,10 @@ test: # Run Dafny on an integration test case directly in the folder itself. # make test-run name= action="run ..." test-dafny: - name="$(name)"; \ - files=$$(cd "${DIR}"/Source/IntegrationTests/TestFiles/LitTests/LitTest; find . -type f -wholename "*$$name*" | grep -E '\.dfy$$'); \ - if [ -z "$files" ]; then \ - echo "No files found matching pattern: $$name"; \ - exit 1; \ - else \ - count=$$(echo "$$files" | wc -l); \ - echo "$${files}"; \ - echo "$$count test files found."; \ - for file in $$files; do \ - filedir=$$(dirname "$$file"); \ - (cd "${DIR}/Source/IntegrationTests/TestFiles/LitTests/LitTest/$${filedir}"; dotnet run --project "${DIR}"/Source/Dafny -- $(action) "$$(basename $$file)" ); \ - done; \ - fi + @name="$(name)" DIR="$(DIR)" action="$(action)" bash scripts/test-dafny.sh + +test-dafny-nobuild: + @name="$(name)" DIR="$(DIR)" action="$(action)" NO_BUILD="true" bash scripts/test-dafny.sh tests-verbose: (cd "${DIR}"; dotnet test --logger "console;verbosity=normal" Source/IntegrationTests ) diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index fa369bf5051..59d82814d60 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -215,6 +215,7 @@ module {:extern "DAST"} DAST { datatype TypeArgBound = | SupportsEquality | SupportsDefault + | TraitBound(typ: Type) datatype Primitive = Int | Real | String | Bool | Char | Native @@ -367,11 +368,12 @@ module {:extern "DAST"} DAST { name: Name, typeParams: seq, params: seq, + inheritedParams: seq, body: seq, outTypes: seq, outVars: Option>) - datatype CallSignature = CallSignature(parameters: seq) + datatype CallSignature = CallSignature(parameters: seq, inheritedParams: seq) datatype CallName = CallName(name: Name, onType: Option, receiverArg: Option, receiverAsArgument: bool, signature: CallSignature) | diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index d8bded0b388..f2676a3feb6 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -412,9 +412,9 @@ public MethodBuilder Method(bool isStatic, bool hasBody, bool outVarsAreUninitFi ISequence<_IAttribute> attributes, string name, List typeArgs, - Sequence params_, + Sequence params_, Sequence inheritedParams, List outTypes, List> outVars) { - return new MethodBuilder(this, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, docString, attributes, name, typeArgs, params_, outTypes, outVars); + return new MethodBuilder(this, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, docString, attributes, name, typeArgs, params_, inheritedParams, outTypes, outVars); } public object Finish(); @@ -430,6 +430,7 @@ class MethodBuilder : StatementContainer { readonly ISequence> overridingPath; readonly List typeArgs; readonly Sequence params_; + readonly Sequence inheritedParams; readonly List outTypes; readonly List> outVars; readonly List body = new(); @@ -444,9 +445,8 @@ public MethodBuilder( ISequence<_IAttribute> attributes, string name, List typeArgs, - Sequence params_, - List outTypes, List> outVars - ) { + Sequence params_, Sequence inheritedParams, + List outTypes, List> outVars) { this.parent = parent; this.isStatic = isStatic; this.hasBody = hasBody; @@ -460,6 +460,7 @@ public MethodBuilder( this.params_ = params_; this.outTypes = outTypes; this.outVars = outVars; + this.inheritedParams = inheritedParams; } public List ForkList() { @@ -490,6 +491,7 @@ public DAST.Method Build() { Sequence.UnicodeFromString(this.name), Sequence.FromArray(typeArgs.ToArray()), params_, + inheritedParams, Sequence.FromArray(builtStatements.ToArray()), Sequence.FromArray(outTypes.ToArray()), outVars != null ? Option>>.create_Some(Sequence>.FromArray(outVars.ToArray())) : Option>>.create_None() @@ -570,7 +572,7 @@ public TailRecursiveBuilder TailRecursive() { return ret; } - public CallStmtBuilder Call(ISequence<_IFormal> signature) { + public CallStmtBuilder Call(_ICallSignature signature) { var ret = new CallStmtBuilder(signature); AddBuildable(ret); return ret; @@ -976,9 +978,9 @@ class CallStmtBuilder : ExprContainer, BuildableStatement { List typeArgs = null; readonly List args = new(); List> outs = null; - public readonly ISequence<_IFormal> Signature; + public readonly _ICallSignature Signature; - public CallStmtBuilder(ISequence<_IFormal> signature) { + public CallStmtBuilder(_ICallSignature signature) { this.Signature = signature; } @@ -1293,7 +1295,7 @@ BinOpBuilder BinOp(string op, Func signature) { + CallExprBuilder Call(_ICallSignature signature) { var ret = new CallExprBuilder(signature); AddBuildable(ret); return ret; @@ -1478,9 +1480,9 @@ class CallExprBuilder : ExprContainer, BuildableExpr { readonly List args = new(); List> outs = null; - public ISequence<_IFormal> Signature { get; } + public _ICallSignature Signature { get; } - public CallExprBuilder(ISequence<_IFormal> signature) { + public CallExprBuilder(_ICallSignature signature) { Signature = signature; } diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index b20a09c5b6a..a78f5137bad 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -225,7 +225,7 @@ private Variance GenTypeVariance(TypeParameter tp) { return (Variance)Variance.create_Nonvariant(); } - private static ISequence<_ITypeArgBound> GenTypeBounds(TypeParameter tp) { + private ISequence<_ITypeArgBound> GenTypeBounds(TypeParameter tp) { var characteristics = new List<_ITypeArgBound>(); if (tp.Characteristics.AutoInit is Type.AutoInitInfo.CompilableValue) { characteristics.Add(DAST.TypeArgBound.create_SupportsDefault()); @@ -235,6 +235,11 @@ private static ISequence<_ITypeArgBound> GenTypeBounds(TypeParameter tp) { characteristics.Add(DAST.TypeArgBound.create_SupportsEquality()); } + foreach (var typebound in tp.TypeBounds) { + var traitType = GenType(typebound); + characteristics.Add(DAST.TypeArgBound.create_TraitBound(traitType)); + } + var bounds = Sequence<_ITypeArgBound>.FromArray(characteristics.ToArray()); return bounds; } @@ -337,8 +342,15 @@ private static bool CanDowncast(Type parentTrait, TraitDecl subTrait, out Type d var allTypeParametersCovered = subTrait.TypeArgs.TrueForAll( tp => mapping.ContainsKey(tp)); if (allTypeParametersCovered) { - + // Now we need to make sure that type characteristics are compatible var typeArgs = subTrait.TypeArgs.Select(tp => mapping[tp]).ToList(); + for (var i = 0; i < typeArgs.Count; i++) { + var downcastTypeParam = subTrait.TypeArgs[i]; + var parentType = typeArgs[i]; + if (!IsCompatibleWith(parentType, downcastTypeParam)) { + return false; + } + } var subTraitTypeDowncastable = new UserDefinedType(Token.NoToken, subTrait.Name, subTrait, typeArgs); @@ -350,6 +362,12 @@ private static bool CanDowncast(Type parentTrait, TraitDecl subTrait, out Type d return canDowncast; } + private static bool IsCompatibleWith(Type type, TypeParameter typeParameter) + { + return (typeParameter.Characteristics.EqualitySupport == TypeParameter.EqualitySupportValue.Unspecified || + type.SupportsEquality) && typeParameter.TypeBounds.TrueForAll(t => type.IsSubtypeOf(t, false, true)); + } + protected override ConcreteSyntaxTree CreateIterator(IteratorDecl iter, ConcreteSyntaxTree wr) { AddUnsupportedFeature(iter.tok, Feature.Iterators); return wr; @@ -640,6 +658,14 @@ protected override bool InstanceConstAreStatic() { return false; } + [CanBeNull] + public MemberDecl GetTopMostOverriddenMemberDeclIfDifferent(MemberDecl member) { + while (member.OverriddenMember is { OverriddenMember: { } } upMember) { + member = upMember; + } + return member.OverriddenMember; + } + private class ClassWriter : IClassWriter { private readonly DafnyCodeGenerator compiler; private readonly ClassLike builder; @@ -656,7 +682,7 @@ public ConcreteSyntaxTree CreateMethod(Method m, List bool forBodyInheritance, bool lookasideBody) { var astTypeArgs = m.TypeArgs.Select(typeArg => compiler.GenTypeArgDecl(typeArg)).ToList(); - var params_ = compiler.GenFormals(m.Ins); + var params_ = compiler.GetParameters(m, out var inheritedParams, out var overriddenMethod); List> outVars = new(); List outTypes = new(); @@ -667,10 +693,6 @@ public ConcreteSyntaxTree CreateMethod(Method m, List } } - var overriddenMethod = m.OverriddenMethod; - while (overriddenMethod != null && overriddenMethod.OverriddenMethod != null) { - overriddenMethod = overriddenMethod.OverriddenMethod; - } var overridingTrait = overriddenMethod?.EnclosingClass; if (m is Constructor { EnclosingClass: TopLevelDeclWithMembers cm }) { @@ -694,9 +716,8 @@ public ConcreteSyntaxTree CreateMethod(Method m, List compiler.GetDocString(m), attributes, m.GetCompileName(compiler.Options), - astTypeArgs, params_, - outTypes, outVars - ); + astTypeArgs, params_, inheritedParams, + outTypes, outVars); methods.Add(builder); if (createBody) { @@ -718,9 +739,19 @@ public ConcreteSyntaxTree CreateFunction(string name, List()).Select(typeArg => compiler.GenTypeArgDecl(typeArg)).ToList(); - var params_ = compiler.GenFormals(formals); + Sequence params_; + Sequence inheritedParams; + MemberDecl overridingFunction; + if (member is Function fun2) { + params_ = compiler.GetParameters(fun2, out inheritedParams, out overridingFunction); + } else { + params_ = compiler.GenFormals(formals); + overridingFunction = compiler.GetTopMostOverriddenMemberDeclIfDifferent(member); + inheritedParams = params_; + } + + var overridingTrait = overridingFunction?.EnclosingClass; - var overridingTrait = member.OverriddenMember?.EnclosingClass; var attributes = compiler.ParseAttributes(member.Attributes); var builder = this.builder.Method( isStatic, createBody, false, true, @@ -728,11 +759,10 @@ public ConcreteSyntaxTree CreateFunction(string name, List(new StatementBuffer(), this.compiler); } - var overridingTrait = member.OverriddenMember?.EnclosingClass; + var overridingTrait = compiler.GetTopMostOverriddenMemberDeclIfDifferent(member)?.EnclosingClass; var attributes = compiler.ParseAttributes(enclosingDecl.Attributes); @@ -760,10 +790,10 @@ public ConcreteSyntaxTree CreateGetter(string name, TopLevelDecl enclosingDecl, attributes, name, new(), (Sequence)Sequence.Empty, + (Sequence)Sequence.Empty, new() { compiler.GenType(resultType) - }, null - ); + }, null); methods.Add(builder); if (createBody) { @@ -1115,8 +1145,8 @@ protected override void TrCallStmt(CallStmt s, string receiverReplacement, Concr if (s.Method == enclosingMethod && enclosingMethod.IsTailRecursive) { base.TrCallStmt(s, receiverReplacement, wr, wrStmts, wrStmtsAfterCall); } else { - var parameters = GenFormals(s.Method.Ins); - var callBuilder = stmtContainer.Builder.Call(parameters); + var signature = GetCallSignature(s.Method);; + var callBuilder = stmtContainer.Builder.Call(signature); base.TrCallStmt(s, receiverReplacement, new BuilderSyntaxTree(callBuilder, this), wrStmts, wrStmtsAfterCall); } } else { @@ -1143,17 +1173,37 @@ protected override void EmitStaticExternMethodQualifier(string qual, ConcreteSyn protected override void EmitCallToInheritedMethod(Method method, [CanBeNull] TopLevelDeclWithMembers heir, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts, ConcreteSyntaxTree wStmtsAfterCall) { if (wr is BuilderSyntaxTree stmtContainer) { - var callBuilder = stmtContainer.Builder.Call(GenFormals(method.Ins)); + var signature = GetCallSignature(method); + var callBuilder = stmtContainer.Builder.Call(signature); base.EmitCallToInheritedMethod(method, heir, new BuilderSyntaxTree(callBuilder, this), wStmts, wStmtsAfterCall); } else { throw new InvalidOperationException("Cannot call inherited method in this context: " + currentBuilder); } } + private _ICallSignature GetCallSignature(MethodOrFunction method) + { + var parameters = GetParameters(method, out var inheritedParameters, out _); + var signature = DAST.CallSignature.create_CallSignature(parameters, inheritedParameters); + return signature; + } + + private Sequence GetParameters(MethodOrFunction method, out Sequence inheritedParameters, out MemberDecl inheritedMethod) + { + var parameters = GenFormals(method.Ins); + inheritedMethod = GetTopMostOverriddenMemberDeclIfDifferent(method); + var oldThisContext = thisContext; + thisContext = null; + inheritedParameters = inheritedMethod is MethodOrFunction m ? GenFormals(m.Ins) : parameters; + thisContext = oldThisContext; + return parameters; + } + protected override void EmitCallToInheritedFunction(Function f, [CanBeNull] TopLevelDeclWithMembers heir, ConcreteSyntaxTree wr) { if (wr is BuilderSyntaxTree exprContainer) { - var callBuilder = exprContainer.Builder.Call(GenFormals(f.Ins)); + var signature = GetCallSignature(f); + var callBuilder = exprContainer.Builder.Call(signature); base.EmitCallToInheritedFunction(f, heir, new BuilderSyntaxTree(callBuilder, this)); } else { throw new InvalidOperationException("Cannot call inherited function in this context: " + currentBuilder); @@ -1175,7 +1225,8 @@ protected override void CompileFunctionCallExpr(FunctionCallExpr e, ConcreteSynt wr = EmitCoercionIfNecessary(fromType, toType, e.tok, wr); if (wr is BuilderSyntaxTree builder) { - var callBuilder = builder.Builder.Call(GenFormals(e.Function.Ins)); + var signature = GetCallSignature(e.Function); + var callBuilder = builder.Builder.Call(signature); base.CompileFunctionCallExpr(e, new BuilderSyntaxTree(callBuilder, this), inLetExprBody, wStmts, tr, true); } else { throw new InvalidOperationException("Cannot call function in this context: " + currentBuilder); @@ -2553,9 +2604,10 @@ protected override ConcreteSyntaxTree EmitCallToIsMethod(RedirectingTypeDecl dec return wrRhs; } - var signature = Sequence<_IFormal>.FromArray(new[] { + var parameters = Sequence<_IFormal>.FromArray(new[] { new DAST.Formal(Sequence.UnicodeFromString("_dummy_"), GenType(type), Sequence.Empty) }); + var signature = CreateSignature(parameters); var c = builder.Builder.Call(signature); c.SetName((DAST.CallName)DAST.CallName.create_CallName(Sequence.UnicodeFromString("is"), Option<_IType>.create_None(), Option<_IFormal>.create_None(), false, signature)); @@ -2662,7 +2714,8 @@ protected override void EmitDatatypeBoundedPool(IVariable bv, string propertySuf if (GetExprConverter(wr, wStmts, out var exprBuilder, out var convert)) { if (bv.Type.IsDatatype && bv.Type.AsDatatype is { } datatypeDecl) { - var signature = Sequence<_IFormal>.FromArray(new _IFormal[] { }); + var parameters = Sequence<_IFormal>.FromArray(new _IFormal[] { }); + var signature = CreateSignature(parameters); var c = exprBuilder.Builder.Call(signature); c.SetName((DAST.CallName)DAST.CallName.create_CallName(Sequence.UnicodeFromString("_AllSingletonConstructors"), Option<_IType>.create_None(), Option<_IFormal>.create_None(), false, signature)); @@ -3194,7 +3247,7 @@ protected override void EmitMapBuilder_New(ConcreteSyntaxTree wr, MapComprehensi protected override void EmitSetBuilder_Add(CollectionType ct, string collName, Expression elmt, bool inLetExprBody, ConcreteSyntaxTree wr) { if (GetStatementBuilder(wr, out var builder)) { - var stmtBuilder = new CallStmtBuilder(Sequence<_IFormal>.Empty); + var stmtBuilder = new CallStmtBuilder(CreateSignature(Sequence<_IFormal>.Empty)); stmtBuilder.SetName((DAST.CallName)DAST.CallName.create_SetBuilderAdd()); stmtBuilder.SetTypeArgs(new List { }); stmtBuilder.SetOuts(new List> { }); ; @@ -3207,6 +3260,11 @@ protected override void EmitSetBuilder_Add(CollectionType ct, string collName, E //throw new InvalidOperationException(); } + private static _ICallSignature CreateSignature(ISequence<_IFormal> params_) + { + return CallSignature.create_CallSignature(params_, params_); + } + // Normally wStmt is a BuilderSyntaxTree but it might not while the compiler is being developed private DAST.Expression ConvertExpression(Expression term, ConcreteSyntaxTree wStmt) { EmitExpr(term, false, WrBuffer(out var buffer0), wStmt); @@ -3226,7 +3284,7 @@ private BuilderSyntaxTree CreateExprBuilder() { protected override ConcreteSyntaxTree EmitMapBuilder_Add(MapType mt, IOrigin tok, string collName, Expression term, bool inLetExprBody, ConcreteSyntaxTree wr) { if (GetStatementBuilder(wr, out var builder)) { - var stmtBuilder = new CallStmtBuilder(Sequence<_IFormal>.Empty); + var stmtBuilder = new CallStmtBuilder(CreateSignature(Sequence<_IFormal>.Empty)); stmtBuilder.SetName((DAST.CallName)DAST.CallName.create_MapBuilderAdd()); stmtBuilder.SetTypeArgs(new List { }); stmtBuilder.SetOuts(new List> { }); ; @@ -3308,7 +3366,7 @@ protected override Action GetSubtypeCondition(string tmpVarN protected override void GetCollectionBuilder_Build(CollectionType ct, IOrigin tok, string collName, ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmt) { if (GetExprBuilder(wr, out var builder)) { - var callExpr = new CallExprBuilder(Sequence<_IFormal>.Empty); + var callExpr = new CallExprBuilder(CreateSignature(Sequence<_IFormal>.Empty)); if (ct.IsMapType) { callExpr.SetName((DAST.CallName)DAST.CallName.create_MapBuilderBuild()); } else { diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 6805500f938..5f90b65f073 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -297,6 +297,25 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { predicate IsClassOrObjectTrait() { ThisTyped? && dafnyType.IsClassOrObjectTrait() } + predicate IsRcWrappedDatatype() { + ThisTyped? && IsRcWrappedDatatypeRec(dafnyType) + } + } + + predicate IsRcWrappedDatatypeRec(dafnyType: Type) { + match dafnyType { + case UserDefined(ResolvedType(_, _, Datatype(_), attributes, _, _)) => + IsRcWrapped(attributes) + case UserDefined(ResolvedType(_, _, SynonymType(tpe), attributes, _, _)) => + IsRcWrappedDatatypeRec(tpe) + case _ => false + } + } + + predicate IsRcWrapped(attributes: seq) { + (Attribute("auto-nongrowing-size", []) !in attributes && + Attribute("rust_rc", ["false"]) !in attributes) || + Attribute("rust_rc", ["true"]) in attributes } datatype ExternAttribute = @@ -684,37 +703,44 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { self.hash(&mut hasher); hasher.finish() } */ - const hasher_trait := + function hasher_trait(supportsEquality: bool, pointerType: PointerType): R.ImplMember { R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_hash", [], [R.Formal.selfBorrowed], Some(R.Type.U64), Some( - R.DeclareVar(R.MUT, "hasher", None, Some(R.std.MSel("hash").MSel("DefaultHasher").AsExpr().FSel("new").Apply0())).Then( - R.self.Sel("hash").Apply1(R.UnaryOp("&mut", R.Identifier("hasher"), Format.UnaryOpFormat.NoFormat)).Then( - R.Identifier("hasher").Sel("finish").Apply0() + if supportsEquality then + R.DeclareVar(R.MUT, "hasher", None, Some(R.std.MSel("hash").MSel("DefaultHasher").AsExpr().FSel("new").Apply0())).Then( + R.self.Sel("hash").Apply1(R.UnaryOp("&mut", R.Identifier("hasher"), Format.UnaryOpFormat.NoFormat)).Then( + R.Identifier("hasher").Sel("finish").Apply0() + ) ) - ) + else + UnreachablePanicIfVerified(pointerType, "The type does not support equality") ))) + } /** fn _eq(&self, other: &Box) -> bool { Test::_as_any(other.as_ref()).downcast_ref::().map_or(false, |x| self == x) } */ - function eq_trait(fullTraitPath: R.Type, fullTraitExpr: R.Expr): R.ImplMember { + function eq_trait(fullTraitPath: R.Type, fullTraitExpr: R.Expr, supportsEquality: bool, pointerType: PointerType): R.ImplMember { R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.Borrowed(R.Box(R.DynType(fullTraitPath))))], Some(R.Type.Bool), Some( - fullTraitExpr.FSel("_as_any").Apply1(R.Identifier("other").Sel("as_ref").Apply0()).Sel("downcast_ref").ApplyType([R.SelfOwned]).Apply0().Sel("map_or").Apply( - [ - R.LiteralBool(false), - R.Lambda([R.Formal("x", R.RawType("_"))], None, R.BinaryOp("==", R.self, R.Identifier("x"), Format.BinaryOpFormat.NoFormat)) - ] - ) + if supportsEquality then + fullTraitExpr.FSel("_as_any").Apply1(R.Identifier("other").Sel("as_ref").Apply0()).Sel("downcast_ref").ApplyType([R.SelfOwned]).Apply0().Sel("map_or").Apply( + [ + R.LiteralBool(false), + R.Lambda([R.Formal("x", R.RawType("_"))], None, R.BinaryOp("==", R.self, R.Identifier("x"), Format.BinaryOpFormat.NoFormat)) + ] + ) + else + UnreachablePanicIfVerified(pointerType, "The type does not support equality") ))) } @@ -1008,6 +1034,32 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { ) } + /* + impl UpcastBox for Box { + fn upcast(&self) -> Box { + SuperTrait::_clone(self.as_ref()) + } + } + */ + function UpcastDynTraitFor( + rTypeParamsDecls: seq, + forBoxedTraitType: R.Type, + superTraitType: R.Type, + superTraitExpr: R.Expr + ): R.ModDecl { + var superBoxedTraitType := R.Box(R.DynType(superTraitType)); + var body := superTraitExpr.FSel("_clone").Apply1(R.self.Sel("as_ref").Apply0()); + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.dafny_runtime.MSel("UpcastBox").AsType().Apply([R.DynType(superTraitType)]), + forBoxedTraitType, + [ R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn("upcast", [], [R.Formal.selfBorrowed], Some(superBoxedTraitType), Some(body))) + ])) + } + // Overapproximate but sound static analysis domain for assignment of a variable datatype AssignmentStatus = NotAssigned | SurelyAssigned | Unknown { // After a if, typically. What we know if either of the assignment status is taken diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 7656e9caa43..405d0a7d516 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -146,13 +146,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenTypeParam(tp: TypeArgDecl) returns (typeArg: Type, typeParam: R.TypeParamDecl) { typeArg := TypeArg(tp.name); - var genTpConstraint := if SupportsEquality in tp.bounds then - [R.DafnyTypeEq] - else - [R.DafnyType]; - if SupportsDefault in tp.bounds { - genTpConstraint := genTpConstraint + [R.DefaultTrait]; + var supportsEquality := false; + var supportsDefault := false; + var genTpConstraint := []; + for i := 0 to |tp.bounds| { + var bound := tp.bounds[i]; + match bound + case SupportsEquality() => + supportsEquality := true; + case SupportsDefault() => + supportsDefault := true; + case TraitBound(typ) => + var tpe := GenType(typ, GenTypeContext.ForTraitParents()); + var upcast_tpe := R.dafny_runtime.MSel("UpcastBox").AsType().Apply([R.DynType(tpe)]); + genTpConstraint := genTpConstraint + [upcast_tpe]; + } + if supportsDefault { + genTpConstraint := [R.DefaultTrait] + genTpConstraint; } + var dafnyType := if supportsEquality then R.DafnyTypeEq else R.DafnyType; + genTpConstraint := [dafnyType] + genTpConstraint; typeParam := R.TypeParamDecl(escapeName(tp.name.id), genTpConstraint); } @@ -255,6 +268,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { superTraitTypes: seq, traitBodies: map, seq>, extern: ExternAttribute, + supportsEquality: bool, kind: string) returns (s: seq) modifies this @@ -319,8 +333,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { body := body + [ clone_trait(fullTraitPath), print_trait, - hasher_trait, - eq_trait(fullTraitPath, fullTraitExpr), + hasher_trait(supportsEquality, pointerType), + eq_trait(fullTraitPath, fullTraitExpr, supportsEquality, pointerType), as_any_trait ]; } else { @@ -513,6 +527,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { superTraitTypes, traitBodies, extern, + true, "class"); s := s + superTraitImplementations; } @@ -550,41 +565,32 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // fn _clone(&self) -> Box; implBody := implBody + [ R.FnDecl( - R.NoDoc, R.NoAttr, - R.PRIV, + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_clone", [], [R.Formal.selfBorrowed], Some(R.Box(R.DynType(traitFullType))), None )), R.FnDecl( - R.NoDoc, R.NoAttr, - R.PRIV, + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_fmt_print", [], fmt_print_parameters, Some(fmt_print_result), None - ) - ), + )), R.FnDecl( - R.NoDoc, R.NoAttr, - R.PRIV, + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_hash", [], [R.Formal.selfBorrowed], Some(R.Type.U64), None - ) - ), + )), R.FnDecl( - R.NoDoc, R.NoAttr, - R.PRIV, + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.Borrowed(R.Box(R.DynType(traitFullType))))], Some(R.Bool), None - ) - ), + )), R.FnDecl( - R.NoDoc, R.NoAttr, - R.PRIV, + R.NoDoc, R.NoAttr, R.PRIV, R.Fn( - "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.std.MSel("any").MSel("Any").AsType()))), None - ) - ) + "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.AnyTrait))), None + )) ]; } while |implBodyImplementingOtherTraits| > 0 { @@ -596,7 +602,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { implBodyImplementingOtherTraits := implBodyImplementingOtherTraits - {otherTrait}; } var parents: seq := []; - var upcastImplemented := []; + var upcastImplemented: seq := []; + var instantiatedFullType := R.Box(R.DynType(traitFullType)); // TODO: make the object version as well + if instantiatedFullType.IsBox() { // TODO: Make it work also for object traits + var upcastDynTrait := UpcastDynTraitFor(rTypeParamsDecls, instantiatedFullType, traitFullType, traitFullExpr); + upcastImplemented := upcastImplemented + [upcastDynTrait]; + } for i := 0 to |t.parents| { var parentTyp := t.parents[i]; var parentTpe := GenType(parentTyp, GenTypeContext.ForTraitParents()); @@ -610,9 +621,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { parents := parents + [parentTpe]; var upcastTrait := if parentTyp.IsGeneralTrait() then "UpcastBox" else Upcast; parents := parents + [R.dafny_runtime.MSel(upcastTrait).AsType().Apply1(R.DynType(parentTpe))]; + if parentTyp.IsGeneralTrait() { + var upcastDynTrait := UpcastDynTraitFor(rTypeParamsDecls, instantiatedFullType, parentTpe, parentTpeExpr); + upcastImplemented := upcastImplemented + [upcastDynTrait]; + } } var downcastDefinition := []; - var instantiatedFullType := R.Box(R.DynType(traitFullType)); if |t.parents| > 0 { // We will need to downcast var downcastDefinitionOpt := DowncastTraitDeclFor(rTypeParamsDecls, instantiatedFullType); if downcastDefinitionOpt.None? { @@ -681,7 +695,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Fn("fmt_print", [], fmt_print_parameters, Some(fmt_print_result), Some(traitFullExpr.FSel("_fmt_print").Apply([R.self.Sel("as_ref").Apply0(), R.Identifier("_formatter"), R.Identifier("in_seq")])) - ))])), + ))]))]; + s := s + [ /* impl PartialEq for Box { fn eq(&self, other: &Self) -> bool { @@ -707,7 +722,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.std.MSel("cmp").MSel("Eq").AsType(), R.Box(R.DynType(traitFullType)), - [])), + []))]; + s := s + [ /* impl Hash for Box { @@ -723,14 +739,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Hash, R.Box(R.DynType(traitFullType)), [R.FnDecl( - R.NoDoc, R.NoAttr, - R.PRIV, - R.Fn( - "hash", hash_type_parameters, - hash_parameters, - None, - Some(hash_function.Apply([R.Borrow(traitFullExpr.FSel("_hash").Apply1(R.self.Sel("as_ref").Apply0())), R.Identifier("_state")])) - ))])) + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn( + "hash", hash_type_parameters, + hash_parameters, + None, + Some(hash_function.Apply([R.Borrow(traitFullExpr.FSel("_hash").Apply1(R.self.Sel("as_ref").Apply0())), R.Identifier("_state")])) + ))])) ]; } s := s + upcastImplemented; @@ -954,28 +969,29 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - predicate TypeIsEq(t: Type) + predicate TypeIsEq(t: Type, typeParametersSupportingEquality: set) // TODO: Take into account enclosing type parameters decreases t { match t + case UserDefined(ResolvedType(_, _, SynonymType(tpe), _, _, _)) => TypeIsEq(tpe, typeParametersSupportingEquality) case UserDefined(_) => true // ResolvedTypes are assumed to support equality - case Tuple(ts) => forall t <- ts :: TypeIsEq(t) + case Tuple(ts) => forall t <- ts :: TypeIsEq(t, typeParametersSupportingEquality) case Array(t, _) => true // Reference equality - case Seq(t) => TypeIsEq(t) - case Set(t) => TypeIsEq(t) - case Multiset(t) => TypeIsEq(t) - case Map(k, v) => TypeIsEq(k) && TypeIsEq(v) - case SetBuilder(t) => TypeIsEq(t) - case MapBuilder(k, v) => TypeIsEq(k) && TypeIsEq(v) + case Seq(t) => TypeIsEq(t, typeParametersSupportingEquality) + case Set(t) => true + case Multiset(t) => true + case Map(k, v) => TypeIsEq(v, typeParametersSupportingEquality) + case SetBuilder(t) => true // Irrelevant + case MapBuilder(k, v) => TypeIsEq(v, typeParametersSupportingEquality) // Irrelevant case Arrow(_, _) => false case Primitive(_) => true case Passthrough(_) => true // should be Rust primitive types - case TypeArg(i) => true // i(==) is asserted at the point of use by the verifier + case TypeArg(i) => i in typeParametersSupportingEquality // i(==) is asserted at the point of use by the verifier case Object() => true } - predicate DatatypeIsEq(c: Datatype) { - !c.isCo && forall ctor <- c.ctors, arg <- ctor.args :: TypeIsEq(arg.formal.typ) + predicate DatatypeIsEq(c: Datatype, typeParametersSupportingEquality: set) { + !c.isCo && forall ctor <- c.ctors, arg <- ctor.args :: TypeIsEq(arg.formal.typ, typeParametersSupportingEquality) } function write(r: R.Expr, final: bool := false): R.Expr { @@ -1188,8 +1204,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { )]; } } - - var cIsEq := DatatypeIsEq(c); + var typeParametersSupportingEquality: set := + set tp <- c.typeParams | SupportsEquality in tp.bounds :: tp.name; + var cIsEq := DatatypeIsEq(c, typeParametersSupportingEquality); var datatypeType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); // Derive PartialEq when c supports equality / derive Clone in all cases @@ -1468,6 +1485,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { c.superTraitTypes, traitBodies, extern, + cIsEq, "datatype"); s := s + superTraitImplementations; } @@ -1523,12 +1541,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - predicate IsRcWrapped(attributes: seq) { - (Attribute("auto-nongrowing-size", []) !in attributes && - Attribute("rust_rc", ["false"]) !in attributes) || - Attribute("rust_rc", ["true"]) in attributes - } - /** The type context is useful in the case when we need to generate a type in a position that requires a variant of the given type. @@ -1722,14 +1734,16 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } // Transform DAST formals to Rust formals - method GenParams(params: seq, forLambda: bool := false) returns (s: seq) + method GenParams(params: seq, inheritedParams: seq := params, forLambda: bool := false) returns (s: seq) ensures |s| == |params| { s := []; for i := 0 to |params| invariant |s| == i && i <= |params| { var param := params[i]; + var inheritedParam := if i < |inheritedParams| then inheritedParams[i] else param; var paramType := GenType(param.typ, GenTypeContext.default()); - if (!paramType.CanReadWithoutClone() || forLambda) && AttributeOwned !in param.attributes { + var inheritedParamType := GenType(inheritedParam.typ, GenTypeContext.default()); + if (!inheritedParamType.CanReadWithoutClone() || forLambda) && AttributeOwned !in param.attributes { paramType := R.Borrowed(paramType); } s := s + [R.Formal(escapeVar(param.name), paramType)]; @@ -1739,7 +1753,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { method GenMethod(m: Method, forTrait: bool, enclosingType: Type, enclosingTypeParams: seq) returns (s: R.ImplMember) modifies this { - var params: seq := GenParams(m.params); + var params: seq := GenParams(m.params, m.inheritedParams); var paramNames := []; var paramTypes := map[]; for paramI := 0 to |m.params| { @@ -1777,12 +1791,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } else if selfId == "self" { if tpe.IsObjectOrPointer() { // For classes and traits tpe := R.SelfBorrowed; - } else { // For Rc-defined datatypes - if enclosingType.UserDefined? && enclosingType.resolved.kind.Datatype? - && IsRcWrapped(enclosingType.resolved.attributes) { - tpe := R.Borrowed(R.Rc(R.SelfOwned)); - } else if enclosingType.UserDefined? && enclosingType.resolved.kind.Newtype? - && IsNewtypeCopy(enclosingType.resolved.kind.range) { + } else { + if enclosingType.UserDefined? && enclosingType.resolved.kind.Newtype? + && IsNewtypeCopy(enclosingType.resolved.kind.range) + && !forTrait { tpe := R.TMetaData( R.SelfOwned, copySemantics := true, @@ -3262,9 +3274,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } resultingOwnership := OwnershipBorrowedMut; } else if expectedOwnership == OwnershipOwned { - var needObjectFromRef := isSelf && selfIdent.IsClassOrObjectTrait(); - if needObjectFromRef { + var needsObjectFromRef := isSelf && selfIdent.IsClassOrObjectTrait(); + var needsRcWrapping := isSelf && selfIdent.IsRcWrappedDatatype(); + if needsObjectFromRef { r := R.dafny_runtime.MSel("Object").AsExpr().ApplyType([R.TIdentifier("_")]).FSel("from_ref").Apply([r]); + } else if needsRcWrapping { + r := R.RcNew(r.Clone()); } else { if !noNeedOfClone { var needUnderscoreClone := isSelf && selfIdent.IsGeneralTrait(); @@ -3329,18 +3344,20 @@ module {:extern "DCOMP"} DafnyToRustCompiler { { argExprs := []; readIdents := {}; - var signature := - if name.CallName? then - if name.receiverArg.Some? && name.receiverAsArgument then - [name.receiverArg.value] + name.signature.parameters - else - name.signature.parameters - else - []; + var borrowSignature; + if name.CallName? { + if name.receiverArg.Some? && name.receiverAsArgument { + borrowSignature := [name.receiverArg.value] + name.signature.inheritedParams; + } else { + borrowSignature := name.signature.inheritedParams; + } + } else { + borrowSignature := []; + } for i := 0 to |args| { var argOwnership := OwnershipBorrowed; - if i < |signature| { - var tpe := GenType(signature[i].typ, GenTypeContext.default()); + if i < |borrowSignature| { + var tpe := GenType(borrowSignature[i].typ, GenTypeContext.default()); // Take the typ from the signature, but ownership from the trait. if tpe.CanReadWithoutClone() { argOwnership := OwnershipOwned; } @@ -4067,7 +4084,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case Lambda(paramsDafny, retType, body) => { - var params := GenParams(paramsDafny, true); + var params := GenParams(paramsDafny, forLambda := true); var paramNames := []; var paramTypesMap := map[]; for i := 0 to |params| { diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 3b506e78feb..5f9800ed607 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -1538,6 +1538,8 @@ public DAST._IVariance dtor_variance { public interface _ITypeArgBound { bool is_SupportsEquality { get; } bool is_SupportsDefault { get; } + bool is_TraitBound { get; } + DAST._IType dtor_typ { get; } _ITypeArgBound DowncastClone(); } public abstract class TypeArgBound : _ITypeArgBound { @@ -1557,12 +1559,16 @@ public static _ITypeArgBound create_SupportsEquality() { public static _ITypeArgBound create_SupportsDefault() { return new TypeArgBound_SupportsDefault(); } + public static _ITypeArgBound create_TraitBound(DAST._IType typ) { + return new TypeArgBound_TraitBound(typ); + } public bool is_SupportsEquality { get { return this is TypeArgBound_SupportsEquality; } } public bool is_SupportsDefault { get { return this is TypeArgBound_SupportsDefault; } } - public static System.Collections.Generic.IEnumerable<_ITypeArgBound> AllSingletonConstructors { + public bool is_TraitBound { get { return this is TypeArgBound_TraitBound; } } + public DAST._IType dtor_typ { get { - yield return TypeArgBound.create_SupportsEquality(); - yield return TypeArgBound.create_SupportsDefault(); + var d = this; + return ((TypeArgBound_TraitBound)d)._typ; } } public abstract _ITypeArgBound DowncastClone(); @@ -1609,6 +1615,33 @@ public override string ToString() { return s; } } + public class TypeArgBound_TraitBound : TypeArgBound { + public readonly DAST._IType _typ; + public TypeArgBound_TraitBound(DAST._IType typ) : base() { + this._typ = typ; + } + public override _ITypeArgBound DowncastClone() { + if (this is _ITypeArgBound dt) { return dt; } + return new TypeArgBound_TraitBound(_typ); + } + public override bool Equals(object other) { + var oth = other as DAST.TypeArgBound_TraitBound; + return oth != null && object.Equals(this._typ, oth._typ); + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._typ)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.TypeArgBound.TraitBound"; + s += "("; + s += Dafny.Helpers.ToString(this._typ); + s += ")"; + return s; + } + } public interface _IPrimitive { bool is_Int { get; } @@ -3990,6 +4023,7 @@ public interface _IMethod { Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } Dafny.ISequence dtor_params { get; } + Dafny.ISequence dtor_inheritedParams { get; } Dafny.ISequence dtor_body { get; } Dafny.ISequence dtor_outTypes { get; } Std.Wrappers._IOption>> dtor_outVars { get; } @@ -4006,10 +4040,11 @@ public class Method : _IMethod { public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _typeParams; public readonly Dafny.ISequence _params; + public readonly Dafny.ISequence _inheritedParams; public readonly Dafny.ISequence _body; public readonly Dafny.ISequence _outTypes; public readonly Std.Wrappers._IOption>> _outVars; - public Method(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { + public Method(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence inheritedParams, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { this._docString = docString; this._attributes = attributes; this._isStatic = isStatic; @@ -4020,17 +4055,18 @@ public Method(Dafny.ISequence docString, Dafny.ISequence.Empty, Dafny.Sequence.Empty, false, false, false, false, Std.Wrappers.Option>>.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Std.Wrappers.Option>>.Default()); + private static readonly DAST._IMethod theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, false, false, false, false, Std.Wrappers.Option>>.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Std.Wrappers.Option>>.Default()); public static DAST._IMethod Default() { return theDefault; } @@ -4089,11 +4128,11 @@ public static DAST._IMethod Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IMethod create(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { - return new Method(docString, attributes, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, name, typeParams, @params, body, outTypes, outVars); + public static _IMethod create(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence inheritedParams, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { + return new Method(docString, attributes, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, name, typeParams, @params, inheritedParams, body, outTypes, outVars); } - public static _IMethod create_Method(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { - return create(docString, attributes, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, name, typeParams, @params, body, outTypes, outVars); + public static _IMethod create_Method(Dafny.ISequence docString, Dafny.ISequence attributes, bool isStatic, bool hasBody, bool outVarsAreUninitFieldsToAssign, bool wasFunction, Std.Wrappers._IOption>> overridingPath, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence @params, Dafny.ISequence inheritedParams, Dafny.ISequence body, Dafny.ISequence outTypes, Std.Wrappers._IOption>> outVars) { + return create(docString, attributes, isStatic, hasBody, outVarsAreUninitFieldsToAssign, wasFunction, overridingPath, name, typeParams, @params, inheritedParams, body, outTypes, outVars); } public bool is_Method { get { return true; } } public Dafny.ISequence dtor_docString { @@ -4146,6 +4185,11 @@ public Dafny.ISequence dtor_params { return this._params; } } + public Dafny.ISequence dtor_inheritedParams { + get { + return this._inheritedParams; + } + } public Dafny.ISequence dtor_body { get { return this._body; @@ -4166,45 +4210,53 @@ public Std.Wrappers._IOption>> dtor_ public interface _ICallSignature { bool is_CallSignature { get; } Dafny.ISequence dtor_parameters { get; } + Dafny.ISequence dtor_inheritedParams { get; } + _ICallSignature DowncastClone(); } public class CallSignature : _ICallSignature { public readonly Dafny.ISequence _parameters; - public CallSignature(Dafny.ISequence parameters) { + public readonly Dafny.ISequence _inheritedParams; + public CallSignature(Dafny.ISequence parameters, Dafny.ISequence inheritedParams) { this._parameters = parameters; + this._inheritedParams = inheritedParams; } - public static Dafny.ISequence DowncastClone(Dafny.ISequence _this) { - return _this; + public _ICallSignature DowncastClone() { + if (this is _ICallSignature dt) { return dt; } + return new CallSignature(_parameters, _inheritedParams); } public override bool Equals(object other) { var oth = other as DAST.CallSignature; - return oth != null && object.Equals(this._parameters, oth._parameters); + return oth != null && object.Equals(this._parameters, oth._parameters) && object.Equals(this._inheritedParams, oth._inheritedParams); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._parameters)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._inheritedParams)); return (int) hash; } public override string ToString() { string s = "DAST.CallSignature.CallSignature"; s += "("; s += Dafny.Helpers.ToString(this._parameters); + s += ", "; + s += Dafny.Helpers.ToString(this._inheritedParams); s += ")"; return s; } - private static readonly Dafny.ISequence theDefault = Dafny.Sequence.Empty; - public static Dafny.ISequence Default() { + private static readonly DAST._ICallSignature theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty); + public static DAST._ICallSignature Default() { return theDefault; } - private static readonly Dafny.TypeDescriptor> _TYPE = new Dafny.TypeDescriptor>(Dafny.Sequence.Empty); - public static Dafny.TypeDescriptor> _TypeDescriptor() { + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.CallSignature.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ICallSignature create(Dafny.ISequence parameters) { - return new CallSignature(parameters); + public static _ICallSignature create(Dafny.ISequence parameters, Dafny.ISequence inheritedParams) { + return new CallSignature(parameters, inheritedParams); } - public static _ICallSignature create_CallSignature(Dafny.ISequence parameters) { - return create(parameters); + public static _ICallSignature create_CallSignature(Dafny.ISequence parameters, Dafny.ISequence inheritedParams) { + return create(parameters, inheritedParams); } public bool is_CallSignature { get { return true; } } public Dafny.ISequence dtor_parameters { @@ -4212,6 +4264,11 @@ public Dafny.ISequence dtor_parameters { return this._parameters; } } + public Dafny.ISequence dtor_inheritedParams { + get { + return this._inheritedParams; + } + } } public interface _ICallName { @@ -4224,13 +4281,13 @@ public interface _ICallName { Std.Wrappers._IOption dtor_onType { get; } Std.Wrappers._IOption dtor_receiverArg { get; } bool dtor_receiverAsArgument { get; } - Dafny.ISequence dtor_signature { get; } + DAST._ICallSignature dtor_signature { get; } _ICallName DowncastClone(); } public abstract class CallName : _ICallName { public CallName() { } - private static readonly DAST._ICallName theDefault = create_CallName(Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Std.Wrappers.Option.Default(), false, Dafny.Sequence.Empty); + private static readonly DAST._ICallName theDefault = create_CallName(Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Std.Wrappers.Option.Default(), false, DAST.CallSignature.Default()); public static DAST._ICallName Default() { return theDefault; } @@ -4238,7 +4295,7 @@ public static DAST._ICallName Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ICallName create_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArg, bool receiverAsArgument, Dafny.ISequence signature) { + public static _ICallName create_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArg, bool receiverAsArgument, DAST._ICallSignature signature) { return new CallName_CallName(name, onType, receiverArg, receiverAsArgument, signature); } public static _ICallName create_MapBuilderAdd() { @@ -4282,7 +4339,7 @@ public bool dtor_receiverAsArgument { return ((CallName_CallName)d)._receiverAsArgument; } } - public Dafny.ISequence dtor_signature { + public DAST._ICallSignature dtor_signature { get { var d = this; return ((CallName_CallName)d)._signature; @@ -4295,8 +4352,8 @@ public class CallName_CallName : CallName { public readonly Std.Wrappers._IOption _onType; public readonly Std.Wrappers._IOption _receiverArg; public readonly bool _receiverAsArgument; - public readonly Dafny.ISequence _signature; - public CallName_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArg, bool receiverAsArgument, Dafny.ISequence signature) : base() { + public readonly DAST._ICallSignature _signature; + public CallName_CallName(Dafny.ISequence name, Std.Wrappers._IOption onType, Std.Wrappers._IOption receiverArg, bool receiverAsArgument, DAST._ICallSignature signature) : base() { this._name = name; this._onType = onType; this._receiverArg = receiverArg; diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 4eee4d82e18..87cdd6596c5 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -160,16 +160,52 @@ public void GenTypeParam(DAST._ITypeArgDecl tp, out DAST._IType typeArg, out RAS typeArg = DAST.Type.Default(); typeParam = RAST.TypeParamDecl.Default(); typeArg = DAST.Type.create_TypeArg((tp).dtor_name); - Dafny.ISequence _0_genTpConstraint; - if (((tp).dtor_bounds).Contains(DAST.TypeArgBound.create_SupportsEquality())) { - _0_genTpConstraint = Dafny.Sequence.FromElements(RAST.__default.DafnyTypeEq); - } else { - _0_genTpConstraint = Dafny.Sequence.FromElements(RAST.__default.DafnyType); + bool _0_supportsEquality; + _0_supportsEquality = false; + bool _1_supportsDefault; + _1_supportsDefault = false; + Dafny.ISequence _2_genTpConstraint; + _2_genTpConstraint = Dafny.Sequence.FromElements(); + BigInteger _hi0 = new BigInteger(((tp).dtor_bounds).Count); + for (BigInteger _3_i = BigInteger.Zero; _3_i < _hi0; _3_i++) { + DAST._ITypeArgBound _4_bound; + _4_bound = ((tp).dtor_bounds).Select(_3_i); + DAST._ITypeArgBound _source0 = _4_bound; + { + if (_source0.is_SupportsEquality) { + _0_supportsEquality = true; + goto after_match0; + } + } + { + if (_source0.is_SupportsDefault) { + _1_supportsDefault = true; + goto after_match0; + } + } + { + DAST._IType _5_typ = _source0.dtor_typ; + RAST._IType _6_tpe; + RAST._IType _out0; + _out0 = (this).GenType(_5_typ, Defs.GenTypeContext.ForTraitParents()); + _6_tpe = _out0; + RAST._IType _7_upcast__tpe; + _7_upcast__tpe = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(_6_tpe))); + _2_genTpConstraint = Dafny.Sequence.Concat(_2_genTpConstraint, Dafny.Sequence.FromElements(_7_upcast__tpe)); + } + after_match0: ; + } + if (_1_supportsDefault) { + _2_genTpConstraint = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(RAST.__default.DefaultTrait), _2_genTpConstraint); } - if (((tp).dtor_bounds).Contains(DAST.TypeArgBound.create_SupportsDefault())) { - _0_genTpConstraint = Dafny.Sequence.Concat(_0_genTpConstraint, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + RAST._IType _8_dafnyType; + if (_0_supportsEquality) { + _8_dafnyType = RAST.__default.DafnyTypeEq; + } else { + _8_dafnyType = RAST.__default.DafnyType; } - typeParam = RAST.TypeParamDecl.create(Defs.__default.escapeName(((tp).dtor_name)), _0_genTpConstraint); + _2_genTpConstraint = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_8_dafnyType), _2_genTpConstraint); + typeParam = RAST.TypeParamDecl.create(Defs.__default.escapeName(((tp).dtor_name)), _2_genTpConstraint); } public void GenTypeParameters(Dafny.ISequence @params, out Dafny.ISequence typeParamsSeq, out Dafny.ISequence rTypeParams, out Dafny.ISequence rTypeParamsDecls) { @@ -278,7 +314,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } } } - public Dafny.ISequence GenTraitImplementations(Dafny.ISequence> path, Dafny.ISequence rTypeParams, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence superTraitTypes, Dafny.IMap>,Dafny.ISequence> traitBodies, Defs._IExternAttribute @extern, Dafny.ISequence kind) + public Dafny.ISequence GenTraitImplementations(Dafny.ISequence> path, Dafny.ISequence rTypeParams, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence superTraitTypes, Dafny.IMap>,Dafny.ISequence> traitBodies, Defs._IExternAttribute @extern, bool supportsEquality, Dafny.ISequence kind) { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.FromElements(); @@ -337,7 +373,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } } if ((_7_traitType).is_GeneralTrait) { - _12_body = Dafny.Sequence.Concat(_12_body, Dafny.Sequence.FromElements(Defs.__default.clone__trait(_13_fullTraitPath), Defs.__default.print__trait, Defs.__default.hasher__trait, Defs.__default.eq__trait(_13_fullTraitPath, _14_fullTraitExpr), Defs.__default.as__any__trait)); + _12_body = Dafny.Sequence.Concat(_12_body, Dafny.Sequence.FromElements(Defs.__default.clone__trait(_13_fullTraitPath), Defs.__default.print__trait, Defs.__default.hasher__trait(supportsEquality, (this).pointerType), Defs.__default.eq__trait(_13_fullTraitPath, _14_fullTraitExpr, supportsEquality, (this).pointerType), Defs.__default.as__any__trait)); } else { if (((kind).Equals(Dafny.Sequence.UnicodeFromString("datatype"))) || ((kind).Equals(Dafny.Sequence.UnicodeFromString("newtype")))) { RAST._IExpr _17_dummy; @@ -498,7 +534,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } Dafny.ISequence _30_superTraitImplementations; Dafny.ISequence _out14; - _out14 = (this).GenTraitImplementations(path, _1_rTypeParams, _2_rTypeParamsDecls, _29_superTraitTypes, _20_traitBodies, _17_extern, Dafny.Sequence.UnicodeFromString("class")); + _out14 = (this).GenTraitImplementations(path, _1_rTypeParams, _2_rTypeParamsDecls, _29_superTraitTypes, _20_traitBodies, _17_extern, true, Dafny.Sequence.UnicodeFromString("class")); _30_superTraitImplementations = _out14; s = Dafny.Sequence.Concat(s, _30_superTraitImplementations); return s; @@ -549,7 +585,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _12_implBody = _out3; _13_implBodyImplementingOtherTraits = _out4; if (((t).dtor_traitType).is_GeneralTrait) { - _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType()))), Std.Wrappers.Option.create_None())))); + _12_implBody = Dafny.Sequence.Concat(_12_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType(RAST.__default.AnyTrait))), Std.Wrappers.Option.create_None())))); } while ((new BigInteger((_13_implBodyImplementingOtherTraits).Count)).Sign == 1) { Dafny.ISequence> _14_otherTrait; @@ -573,74 +609,86 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _17_parents = Dafny.Sequence.FromElements(); Dafny.ISequence _18_upcastImplemented; _18_upcastImplemented = Dafny.Sequence.FromElements(); + RAST._IType _19_instantiatedFullType; + _19_instantiatedFullType = RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)); + if ((_19_instantiatedFullType).IsBox()) { + RAST._IModDecl _20_upcastDynTrait; + _20_upcastDynTrait = Defs.__default.UpcastDynTraitFor(_1_rTypeParamsDecls, _19_instantiatedFullType, _10_traitFullType, _11_traitFullExpr); + _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(_20_upcastDynTrait)); + } BigInteger _hi2 = new BigInteger(((t).dtor_parents).Count); - for (BigInteger _19_i = BigInteger.Zero; _19_i < _hi2; _19_i++) { - DAST._IType _20_parentTyp; - _20_parentTyp = ((t).dtor_parents).Select(_19_i); - RAST._IType _21_parentTpe; + for (BigInteger _21_i = BigInteger.Zero; _21_i < _hi2; _21_i++) { + DAST._IType _22_parentTyp; + _22_parentTyp = ((t).dtor_parents).Select(_21_i); + RAST._IType _23_parentTpe; RAST._IType _out5; - _out5 = (this).GenType(_20_parentTyp, Defs.GenTypeContext.ForTraitParents()); - _21_parentTpe = _out5; - Std.Wrappers._IOption _22_parentTpeExprMaybe; - _22_parentTpeExprMaybe = (_21_parentTpe).ToExpr(); - RAST._IExpr _23_parentTpeExpr = RAST.Expr.Default(); - if ((_22_parentTpeExprMaybe).is_None) { + _out5 = (this).GenType(_22_parentTyp, Defs.GenTypeContext.ForTraitParents()); + _23_parentTpe = _out5; + Std.Wrappers._IOption _24_parentTpeExprMaybe; + _24_parentTpeExprMaybe = (_23_parentTpe).ToExpr(); + RAST._IExpr _25_parentTpeExpr = RAST.Expr.Default(); + if ((_24_parentTpeExprMaybe).is_None) { RAST._IExpr _out6; - _out6 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Cannot convert "), (_21_parentTpe)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); - _23_parentTpeExpr = _out6; + _out6 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Cannot convert "), (_23_parentTpe)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); + _25_parentTpeExpr = _out6; } else { - _23_parentTpeExpr = (_22_parentTpeExprMaybe).dtor_value; + _25_parentTpeExpr = (_24_parentTpeExprMaybe).dtor_value; } - _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements(_21_parentTpe)); - Dafny.ISequence _24_upcastTrait; - if ((_20_parentTyp).IsGeneralTrait()) { - _24_upcastTrait = Dafny.Sequence.UnicodeFromString("UpcastBox"); + _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements(_23_parentTpe)); + Dafny.ISequence _26_upcastTrait; + if ((_22_parentTyp).IsGeneralTrait()) { + _26_upcastTrait = Dafny.Sequence.UnicodeFromString("UpcastBox"); } else { - _24_upcastTrait = (this).Upcast; + _26_upcastTrait = (this).Upcast; + } + _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_26_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_23_parentTpe)))); + if ((_22_parentTyp).IsGeneralTrait()) { + RAST._IModDecl _27_upcastDynTrait; + _27_upcastDynTrait = Defs.__default.UpcastDynTraitFor(_1_rTypeParamsDecls, _19_instantiatedFullType, _23_parentTpe, _25_parentTpeExpr); + _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(_27_upcastDynTrait)); } - _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_24_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_21_parentTpe)))); } - Dafny.ISequence _25_downcastDefinition; - _25_downcastDefinition = Dafny.Sequence.FromElements(); - RAST._IType _26_instantiatedFullType; - _26_instantiatedFullType = RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)); + Dafny.ISequence _28_downcastDefinition; + _28_downcastDefinition = Dafny.Sequence.FromElements(); if ((new BigInteger(((t).dtor_parents).Count)).Sign == 1) { - Std.Wrappers._IOption _27_downcastDefinitionOpt; - _27_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_1_rTypeParamsDecls, _26_instantiatedFullType); - if ((_27_downcastDefinitionOpt).is_None) { - RAST._IExpr _28_dummy; + Std.Wrappers._IOption _29_downcastDefinitionOpt; + _29_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_1_rTypeParamsDecls, _19_instantiatedFullType); + if ((_29_downcastDefinitionOpt).is_None) { + RAST._IExpr _30_dummy; RAST._IExpr _out7; - _out7 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_26_instantiatedFullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _28_dummy = _out7; + _out7 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_19_instantiatedFullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _30_dummy = _out7; } else { - _25_downcastDefinition = Dafny.Sequence.FromElements((_27_downcastDefinitionOpt).dtor_value); + _28_downcastDefinition = Dafny.Sequence.FromElements((_29_downcastDefinitionOpt).dtor_value); } } else if (((t).dtor_traitType).is_GeneralTrait) { _17_parents = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsType()), _17_parents); } if ((new BigInteger(((t).dtor_downcastableTraits).Count)).Sign == 1) { BigInteger _hi3 = new BigInteger(((t).dtor_downcastableTraits).Count); - for (BigInteger _29_i = BigInteger.Zero; _29_i < _hi3; _29_i++) { - RAST._IType _30_downcastableTrait; + for (BigInteger _31_i = BigInteger.Zero; _31_i < _hi3; _31_i++) { + RAST._IType _32_downcastableTrait; RAST._IType _out8; - _out8 = (this).GenType(((t).dtor_downcastableTraits).Select(_29_i), Defs.GenTypeContext.ForTraitParents()); - _30_downcastableTrait = _out8; - Std.Wrappers._IOption _31_downcastTraitOpt; - _31_downcastTraitOpt = (_30_downcastableTrait).ToDowncast(); - if ((_31_downcastTraitOpt).is_Some) { - _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((_31_downcastTraitOpt).dtor_value)); + _out8 = (this).GenType(((t).dtor_downcastableTraits).Select(_31_i), Defs.GenTypeContext.ForTraitParents()); + _32_downcastableTrait = _out8; + Std.Wrappers._IOption _33_downcastTraitOpt; + _33_downcastTraitOpt = (_32_downcastableTrait).ToDowncast(); + if ((_33_downcastTraitOpt).is_Some) { + _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((_33_downcastTraitOpt).dtor_value)); } else { - RAST._IExpr _32_r; + RAST._IExpr _34_r; RAST._IExpr _out9; - _out9 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Cannot convert "), (_30_downcastableTrait)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to its downcast version")), (this).InitEmptyExpr()); - _32_r = _out9; + _out9 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Cannot convert "), (_32_downcastableTrait)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to its downcast version")), (this).InitEmptyExpr()); + _34_r = _out9; } } } s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create((t).dtor_docString, Dafny.Sequence>.FromElements(), _1_rTypeParamsDecls, _10_traitFullType, _17_parents, _12_implBody))); - s = Dafny.Sequence.Concat(s, _25_downcastDefinition); + s = Dafny.Sequence.Concat(s, _28_downcastDefinition); if (((t).dtor_traitType).is_GeneralTrait) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialEq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_eq"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Eq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.Hash, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_hash"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialEq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_eq"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("Eq"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements())))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.Hash, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_hash"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))))))))))); } s = Dafny.Sequence.Concat(s, _18_upcastImplemented); return s; @@ -736,7 +784,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _21_newEnv = _out9; Dafny.ISequence _22_rFormals; Dafny.ISequence _out10; - _out10 = (this).GenParams(Dafny.Sequence.FromElements(_17_formal), false); + _out10 = (this).GenParams(Dafny.Sequence.FromElements(_17_formal), Dafny.Sequence.FromElements(_17_formal), false); _22_rFormals = _out10; s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Constraint check"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _22_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_19_rStmts)))))))); } @@ -828,8 +876,19 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc after_match0: ; return s; } - public bool TypeIsEq(DAST._IType t) { + public bool TypeIsEq(DAST._IType t, Dafny.ISet> typeParametersSupportingEquality) + { DAST._IType _source0 = t; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; + if (kind0.is_SynonymType) { + DAST._IType _0_tpe = kind0.dtor_baseType; + return (this).TypeIsEq(_0_tpe, typeParametersSupportingEquality); + } + } + } { if (_source0.is_UserDefined) { return true; @@ -837,55 +896,55 @@ public bool TypeIsEq(DAST._IType t) { } { if (_source0.is_Tuple) { - Dafny.ISequence _0_ts = _source0.dtor_Tuple_a0; - return Dafny.Helpers.Id, bool>>((_1_ts) => Dafny.Helpers.Quantifier((_1_ts).UniqueElements, true, (((_forall_var_0) => { - DAST._IType _2_t = (DAST._IType)_forall_var_0; - return !((_1_ts).Contains(_2_t)) || ((this).TypeIsEq(_2_t)); - }))))(_0_ts); + Dafny.ISequence _1_ts = _source0.dtor_Tuple_a0; + return Dafny.Helpers.Id, Dafny.ISet>, bool>>((_2_ts, _3_typeParametersSupportingEquality) => Dafny.Helpers.Quantifier((_2_ts).UniqueElements, true, (((_forall_var_0) => { + DAST._IType _4_t = (DAST._IType)_forall_var_0; + return !((_2_ts).Contains(_4_t)) || ((this).TypeIsEq(_4_t, _3_typeParametersSupportingEquality)); + }))))(_1_ts, typeParametersSupportingEquality); } } { if (_source0.is_Array) { - DAST._IType _3_t = _source0.dtor_element; + DAST._IType _5_t = _source0.dtor_element; return true; } } { if (_source0.is_Seq) { - DAST._IType _4_t = _source0.dtor_element; - return (this).TypeIsEq(_4_t); + DAST._IType _6_t = _source0.dtor_element; + return (this).TypeIsEq(_6_t, typeParametersSupportingEquality); } } { if (_source0.is_Set) { - DAST._IType _5_t = _source0.dtor_element; - return (this).TypeIsEq(_5_t); + DAST._IType _7_t = _source0.dtor_element; + return true; } } { if (_source0.is_Multiset) { - DAST._IType _6_t = _source0.dtor_element; - return (this).TypeIsEq(_6_t); + DAST._IType _8_t = _source0.dtor_element; + return true; } } { if (_source0.is_Map) { - DAST._IType _7_k = _source0.dtor_key; - DAST._IType _8_v = _source0.dtor_value; - return ((this).TypeIsEq(_7_k)) && ((this).TypeIsEq(_8_v)); + DAST._IType _9_k = _source0.dtor_key; + DAST._IType _10_v = _source0.dtor_value; + return (this).TypeIsEq(_10_v, typeParametersSupportingEquality); } } { if (_source0.is_SetBuilder) { - DAST._IType _9_t = _source0.dtor_element; - return (this).TypeIsEq(_9_t); + DAST._IType _11_t = _source0.dtor_element; + return true; } } { if (_source0.is_MapBuilder) { - DAST._IType _10_k = _source0.dtor_key; - DAST._IType _11_v = _source0.dtor_value; - return ((this).TypeIsEq(_10_k)) && ((this).TypeIsEq(_11_v)); + DAST._IType _12_k = _source0.dtor_key; + DAST._IType _13_v = _source0.dtor_value; + return (this).TypeIsEq(_13_v, typeParametersSupportingEquality); } } { @@ -905,22 +964,23 @@ public bool TypeIsEq(DAST._IType t) { } { if (_source0.is_TypeArg) { - Dafny.ISequence _12_i = _source0.dtor_TypeArg_a0; - return true; + Dafny.ISequence _14_i = _source0.dtor_TypeArg_a0; + return (typeParametersSupportingEquality).Contains(_14_i); } } { return true; } } - public bool DatatypeIsEq(DAST._IDatatype c) { - return (!((c).dtor_isCo)) && (Dafny.Helpers.Id>((_0_c) => Dafny.Helpers.Quantifier(((_0_c).dtor_ctors).UniqueElements, true, (((_forall_var_0) => { - DAST._IDatatypeCtor _1_ctor = (DAST._IDatatypeCtor)_forall_var_0; - return Dafny.Helpers.Quantifier(((_1_ctor).dtor_args).UniqueElements, true, (((_forall_var_1) => { - DAST._IDatatypeDtor _2_arg = (DAST._IDatatypeDtor)_forall_var_1; - return !((((_0_c).dtor_ctors).Contains(_1_ctor)) && (((_1_ctor).dtor_args).Contains(_2_arg))) || ((this).TypeIsEq(((_2_arg).dtor_formal).dtor_typ)); + public bool DatatypeIsEq(DAST._IDatatype c, Dafny.ISet> typeParametersSupportingEquality) + { + return (!((c).dtor_isCo)) && (Dafny.Helpers.Id>, bool>>((_0_c, _1_typeParametersSupportingEquality) => Dafny.Helpers.Quantifier(((_0_c).dtor_ctors).UniqueElements, true, (((_forall_var_0) => { + DAST._IDatatypeCtor _2_ctor = (DAST._IDatatypeCtor)_forall_var_0; + return Dafny.Helpers.Quantifier(((_2_ctor).dtor_args).UniqueElements, true, (((_forall_var_1) => { + DAST._IDatatypeDtor _3_arg = (DAST._IDatatypeDtor)_forall_var_1; + return !((((_0_c).dtor_ctors).Contains(_2_ctor)) && (((_2_ctor).dtor_args).Contains(_3_arg))) || ((this).TypeIsEq(((_3_arg).dtor_formal).dtor_typ, _1_typeParametersSupportingEquality)); }))); - }))))(c)); + }))))(c, typeParametersSupportingEquality)); } public RAST._IExpr write(RAST._IExpr r, bool final) { @@ -939,7 +999,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) { Dafny.ISequence s = Dafny.Sequence.Empty; bool _0_isRcWrapped; - _0_isRcWrapped = (this).IsRcWrapped((c).dtor_attributes); + _0_isRcWrapped = Defs.__default.IsRcWrapped((c).dtor_attributes); Dafny.ISequence _1_typeParamsSeq; Dafny.ISequence _2_rTypeParams; Dafny.ISequence _3_rTypeParamsDecls; @@ -1180,234 +1240,245 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) })), _54_types))))); } } - bool _68_cIsEq; - _68_cIsEq = (this).DatatypeIsEq(c); - RAST._IType _69_datatypeType; - _69_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, ((_68_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _69_datatypeType, _27_implBody))); + Dafny.ISet> _68_typeParametersSupportingEquality; + _68_typeParametersSupportingEquality = Dafny.Helpers.Id>>>((_69_c) => ((System.Func>>)(() => { + var _coll1 = new System.Collections.Generic.List>(); + foreach (DAST._ITypeArgDecl _compr_1 in ((_69_c).dtor_typeParams).CloneAsArray()) { + DAST._ITypeArgDecl _70_tp = (DAST._ITypeArgDecl)_compr_1; + if ((((_69_c).dtor_typeParams).Contains(_70_tp)) && (((_70_tp).dtor_bounds).Contains(DAST.TypeArgBound.create_SupportsEquality()))) { + _coll1.Add((_70_tp).dtor_name); + } + } + return Dafny.Set>.FromCollection(_coll1); + }))())(c); + bool _71_cIsEq; + _71_cIsEq = (this).DatatypeIsEq(c, _68_typeParametersSupportingEquality); + RAST._IType _72_datatypeType; + _72_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, ((_71_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _72_datatypeType, _27_implBody))); if ((new BigInteger(((c).dtor_superTraitTypes).Count)).Sign == 1) { - RAST._IType _70_fullType; + RAST._IType _73_fullType; if (_0_isRcWrapped) { - _70_fullType = RAST.__default.Rc(_69_datatypeType); + _73_fullType = RAST.__default.Rc(_72_datatypeType); } else { - _70_fullType = _69_datatypeType; + _73_fullType = _72_datatypeType; } - Std.Wrappers._IOption _71_downcastDefinitionOpt; - _71_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_3_rTypeParamsDecls, _70_fullType); - if ((_71_downcastDefinitionOpt).is_None) { - RAST._IExpr _72_dummy; + Std.Wrappers._IOption _74_downcastDefinitionOpt; + _74_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_3_rTypeParamsDecls, _73_fullType); + if ((_74_downcastDefinitionOpt).is_None) { + RAST._IExpr _75_dummy; RAST._IExpr _out15; - _out15 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _72_dummy = _out15; + _out15 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_73_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _75_dummy = _out15; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_71_downcastDefinitionOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_74_downcastDefinitionOpt).dtor_value)); } - Std.Wrappers._IOption _73_downcastImplementationsOpt; - _73_downcastImplementationsOpt = Defs.__default.DowncastImplFor(_3_rTypeParamsDecls, _70_fullType); - if ((_73_downcastImplementationsOpt).is_None) { - RAST._IExpr _74_dummy; + Std.Wrappers._IOption _76_downcastImplementationsOpt; + _76_downcastImplementationsOpt = Defs.__default.DowncastImplFor(_3_rTypeParamsDecls, _73_fullType); + if ((_76_downcastImplementationsOpt).is_None) { + RAST._IExpr _77_dummy; RAST._IExpr _out16; - _out16 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _74_dummy = _out16; + _out16 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation for "), (_73_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _77_dummy = _out16; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_73_downcastImplementationsOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_76_downcastImplementationsOpt).dtor_value)); } BigInteger _hi7 = new BigInteger(((c).dtor_superTraitNegativeTypes).Count); - for (BigInteger _75_i = BigInteger.Zero; _75_i < _hi7; _75_i++) { - RAST._IType _76_negativeTraitType; + for (BigInteger _78_i = BigInteger.Zero; _78_i < _hi7; _78_i++) { + RAST._IType _79_negativeTraitType; RAST._IType _out17; - _out17 = (this).GenType(((c).dtor_superTraitNegativeTypes).Select(_75_i), Defs.GenTypeContext.@default()); - _76_negativeTraitType = _out17; - Std.Wrappers._IOption _77_downcastDefinitionOpt; - _77_downcastDefinitionOpt = Defs.__default.DowncastNotImplFor(_3_rTypeParamsDecls, _76_negativeTraitType, _70_fullType); - if ((_77_downcastDefinitionOpt).is_None) { - RAST._IExpr _78_dummy; + _out17 = (this).GenType(((c).dtor_superTraitNegativeTypes).Select(_78_i), Defs.GenTypeContext.@default()); + _79_negativeTraitType = _out17; + Std.Wrappers._IOption _80_downcastDefinitionOpt; + _80_downcastDefinitionOpt = Defs.__default.DowncastNotImplFor(_3_rTypeParamsDecls, _79_negativeTraitType, _73_fullType); + if ((_80_downcastDefinitionOpt).is_None) { + RAST._IExpr _81_dummy; RAST._IExpr _out18; - _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate negative downcast definition for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _78_dummy = _out18; + _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate negative downcast definition for "), (_73_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _81_dummy = _out18; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_77_downcastDefinitionOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_80_downcastDefinitionOpt).dtor_value)); } } BigInteger _hi8 = new BigInteger(((c).dtor_superTraitTypes).Count); - for (BigInteger _79_i = BigInteger.Zero; _79_i < _hi8; _79_i++) { - DAST._IType _80_c; - _80_c = ((c).dtor_superTraitTypes).Select(_79_i); - if ((((_80_c).is_UserDefined) && ((((_80_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_80_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { + for (BigInteger _82_i = BigInteger.Zero; _82_i < _hi8; _82_i++) { + DAST._IType _83_c; + _83_c = ((c).dtor_superTraitTypes).Select(_82_i); + if ((((_83_c).is_UserDefined) && ((((_83_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_83_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { goto continue_3_0; } - RAST._IType _81_cType; + RAST._IType _84_cType; RAST._IType _out19; - _out19 = (this).GenType(_80_c, Defs.GenTypeContext.@default()); - _81_cType = _out19; - bool _82_isImplementing; - _82_isImplementing = true; - Std.Wrappers._IOption _83_downcastImplementationsOpt; - _83_downcastImplementationsOpt = Defs.__default.DowncastImplTraitFor(_3_rTypeParamsDecls, _81_cType, _82_isImplementing, _70_fullType); - if ((_83_downcastImplementationsOpt).is_None) { - RAST._IExpr _84_dummy; + _out19 = (this).GenType(_83_c, Defs.GenTypeContext.@default()); + _84_cType = _out19; + bool _85_isImplementing; + _85_isImplementing = true; + Std.Wrappers._IOption _86_downcastImplementationsOpt; + _86_downcastImplementationsOpt = Defs.__default.DowncastImplTraitFor(_3_rTypeParamsDecls, _84_cType, _85_isImplementing, _73_fullType); + if ((_86_downcastImplementationsOpt).is_None) { + RAST._IExpr _87_dummy; RAST._IExpr _out20; - _out20 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation of "), (_81_cType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" for ")), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _84_dummy = _out20; + _out20 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation of "), (_84_cType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" for ")), (_73_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _87_dummy = _out20; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_83_downcastImplementationsOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_86_downcastImplementationsOpt).dtor_value)); } continue_3_0: ; } after_3_0: ; } - Dafny.ISequence _85_printImplBodyCases; - _85_printImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _86_hashImplBodyCases; - _86_hashImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _87_coerceImplBodyCases; - _87_coerceImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _88_printImplBodyCases; + _88_printImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _89_hashImplBodyCases; + _89_hashImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _90_coerceImplBodyCases; + _90_coerceImplBodyCases = Dafny.Sequence.FromElements(); BigInteger _hi9 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _88_i = BigInteger.Zero; _88_i < _hi9; _88_i++) { - DAST._IDatatypeCtor _89_ctor; - _89_ctor = ((c).dtor_ctors).Select(_88_i); - Dafny.ISequence _90_ctorMatch; - _90_ctorMatch = Defs.__default.escapeName((_89_ctor).dtor_name); - Dafny.ISequence _91_modulePrefix; + for (BigInteger _91_i = BigInteger.Zero; _91_i < _hi9; _91_i++) { + DAST._IDatatypeCtor _92_ctor; + _92_ctor = ((c).dtor_ctors).Select(_91_i); + Dafny.ISequence _93_ctorMatch; + _93_ctorMatch = Defs.__default.escapeName((_92_ctor).dtor_name); + Dafny.ISequence _94_modulePrefix; if (((((c).dtor_enclosingModule))).Equals(Dafny.Sequence.UnicodeFromString("_module"))) { - _91_modulePrefix = Dafny.Sequence.UnicodeFromString(""); + _94_modulePrefix = Dafny.Sequence.UnicodeFromString(""); } else { - _91_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); - } - Dafny.ISequence _92_ctorName; - _92_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_91_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_89_ctor).dtor_name)); - if (((new BigInteger((_92_ctorName).Count)) >= (new BigInteger(13))) && (((_92_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { - _92_ctorName = Dafny.Sequence.UnicodeFromString(""); - } - RAST._IExpr _93_printRhs; - _93_printRhs = (this).writeStr(Dafny.Sequence.Concat(_92_ctorName, (((_89_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); - RAST._IExpr _94_hashRhs; - _94_hashRhs = (this).InitEmptyExpr(); - Dafny.ISequence _95_coerceRhsArgs; - _95_coerceRhsArgs = Dafny.Sequence.FromElements(); - bool _96_isNumeric; - _96_isNumeric = false; - Dafny.ISequence _97_ctorMatchInner; - _97_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); - BigInteger _hi10 = new BigInteger(((_89_ctor).dtor_args).Count); - for (BigInteger _98_j = BigInteger.Zero; _98_j < _hi10; _98_j++) { - DAST._IDatatypeDtor _99_dtor; - _99_dtor = ((_89_ctor).dtor_args).Select(_98_j); - Dafny.ISequence _100_patternName; - _100_patternName = Defs.__default.escapeVar(((_99_dtor).dtor_formal).dtor_name); - DAST._IType _101_formalType; - _101_formalType = ((_99_dtor).dtor_formal).dtor_typ; - if (((_98_j).Sign == 0) && ((_100_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _96_isNumeric = true; - } - if (_96_isNumeric) { - _100_patternName = Std.Wrappers.Option>.GetOr((_99_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_98_j))); - } - if ((_101_formalType).is_Arrow) { - _94_hashRhs = (_94_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + _94_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); + } + Dafny.ISequence _95_ctorName; + _95_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_92_ctor).dtor_name)); + if (((new BigInteger((_95_ctorName).Count)) >= (new BigInteger(13))) && (((_95_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { + _95_ctorName = Dafny.Sequence.UnicodeFromString(""); + } + RAST._IExpr _96_printRhs; + _96_printRhs = (this).writeStr(Dafny.Sequence.Concat(_95_ctorName, (((_92_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); + RAST._IExpr _97_hashRhs; + _97_hashRhs = (this).InitEmptyExpr(); + Dafny.ISequence _98_coerceRhsArgs; + _98_coerceRhsArgs = Dafny.Sequence.FromElements(); + bool _99_isNumeric; + _99_isNumeric = false; + Dafny.ISequence _100_ctorMatchInner; + _100_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); + BigInteger _hi10 = new BigInteger(((_92_ctor).dtor_args).Count); + for (BigInteger _101_j = BigInteger.Zero; _101_j < _hi10; _101_j++) { + DAST._IDatatypeDtor _102_dtor; + _102_dtor = ((_92_ctor).dtor_args).Select(_101_j); + Dafny.ISequence _103_patternName; + _103_patternName = Defs.__default.escapeVar(((_102_dtor).dtor_formal).dtor_name); + DAST._IType _104_formalType; + _104_formalType = ((_102_dtor).dtor_formal).dtor_typ; + if (((_101_j).Sign == 0) && ((_103_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _99_isNumeric = true; + } + if (_99_isNumeric) { + _103_patternName = Std.Wrappers.Option>.GetOr((_102_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_101_j))); + } + if ((_104_formalType).is_Arrow) { + _97_hashRhs = (_97_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); } else { - _94_hashRhs = (_94_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_100_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); + _97_hashRhs = (_97_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_103_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); } - _97_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_97_ctorMatchInner, _100_patternName), Dafny.Sequence.UnicodeFromString(", ")); - if ((_98_j).Sign == 1) { - _93_printRhs = (_93_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); + _100_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_100_ctorMatchInner, _103_patternName), Dafny.Sequence.UnicodeFromString(", ")); + if ((_101_j).Sign == 1) { + _96_printRhs = (_96_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); } - _93_printRhs = (_93_printRhs).Then((((_101_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_100_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); - RAST._IExpr _102_coerceRhsArg = RAST.Expr.Default(); - RAST._IType _103_formalTpe; + _96_printRhs = (_96_printRhs).Then((((_104_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_103_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); + RAST._IExpr _105_coerceRhsArg = RAST.Expr.Default(); + RAST._IType _106_formalTpe; RAST._IType _out21; - _out21 = (this).GenType(_101_formalType, Defs.GenTypeContext.@default()); - _103_formalTpe = _out21; - DAST._IType _104_newFormalType; - _104_newFormalType = (_101_formalType).Replace(_51_coerceMap); - RAST._IType _105_newFormalTpe; - _105_newFormalTpe = (_103_formalTpe).ReplaceMap(_52_rCoerceMap); - Std.Wrappers._IResult,RAST._IExpr>>> _106_upcastConverter; - _106_upcastConverter = (this).UpcastConversionLambda(_101_formalType, _103_formalTpe, _104_newFormalType, _105_newFormalTpe, _53_coerceMapToArg); - if ((_106_upcastConverter).is_Success) { - RAST._IExpr _107_coercionFunction; - _107_coercionFunction = (_106_upcastConverter).dtor_value; - _102_coerceRhsArg = (_107_coercionFunction).Apply1(RAST.Expr.create_Identifier(_100_patternName)); + _out21 = (this).GenType(_104_formalType, Defs.GenTypeContext.@default()); + _106_formalTpe = _out21; + DAST._IType _107_newFormalType; + _107_newFormalType = (_104_formalType).Replace(_51_coerceMap); + RAST._IType _108_newFormalTpe; + _108_newFormalTpe = (_106_formalTpe).ReplaceMap(_52_rCoerceMap); + Std.Wrappers._IResult,RAST._IExpr>>> _109_upcastConverter; + _109_upcastConverter = (this).UpcastConversionLambda(_104_formalType, _106_formalTpe, _107_newFormalType, _108_newFormalTpe, _53_coerceMapToArg); + if ((_109_upcastConverter).is_Success) { + RAST._IExpr _110_coercionFunction; + _110_coercionFunction = (_109_upcastConverter).dtor_value; + _105_coerceRhsArg = (_110_coercionFunction).Apply1(RAST.Expr.create_Identifier(_103_patternName)); } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_98_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); - _102_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_101_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); + _105_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); } - _95_coerceRhsArgs = Dafny.Sequence.Concat(_95_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_100_patternName, _102_coerceRhsArg))); + _98_coerceRhsArgs = Dafny.Sequence.Concat(_98_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_103_patternName, _105_coerceRhsArg))); } - RAST._IExpr _108_coerceRhs; - _108_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_89_ctor).dtor_name)), _95_coerceRhsArgs); - if (_96_isNumeric) { - _90_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_90_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _97_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + RAST._IExpr _111_coerceRhs; + _111_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_92_ctor).dtor_name)), _98_coerceRhsArgs); + if (_99_isNumeric) { + _93_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _100_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); } else { - _90_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_90_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _97_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + _93_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _100_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); } - if ((_89_ctor).dtor_hasAnyArgs) { - _93_printRhs = (_93_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); + if ((_92_ctor).dtor_hasAnyArgs) { + _96_printRhs = (_96_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); } - _93_printRhs = (_93_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); - _85_printImplBodyCases = Dafny.Sequence.Concat(_85_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _90_ctorMatch), RAST.Expr.create_Block(_93_printRhs)))); - _86_hashImplBodyCases = Dafny.Sequence.Concat(_86_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _90_ctorMatch), RAST.Expr.create_Block(_94_hashRhs)))); - _87_coerceImplBodyCases = Dafny.Sequence.Concat(_87_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _90_ctorMatch), RAST.Expr.create_Block(_108_coerceRhs)))); + _96_printRhs = (_96_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); + _88_printImplBodyCases = Dafny.Sequence.Concat(_88_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _93_ctorMatch), RAST.Expr.create_Block(_96_printRhs)))); + _89_hashImplBodyCases = Dafny.Sequence.Concat(_89_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _93_ctorMatch), RAST.Expr.create_Block(_97_hashRhs)))); + _90_coerceImplBodyCases = Dafny.Sequence.Concat(_90_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _93_ctorMatch), RAST.Expr.create_Block(_111_coerceRhs)))); } if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { - Dafny.ISequence _109_extraCases; - _109_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); - _85_printImplBodyCases = Dafny.Sequence.Concat(_85_printImplBodyCases, _109_extraCases); - _86_hashImplBodyCases = Dafny.Sequence.Concat(_86_hashImplBodyCases, _109_extraCases); - _87_coerceImplBodyCases = Dafny.Sequence.Concat(_87_coerceImplBodyCases, _109_extraCases); - } - Dafny.ISequence _110_defaultConstrainedTypeParams; - _110_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - Dafny.ISequence _111_rTypeParamsDeclsWithEq; - _111_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); - Dafny.ISequence _112_rTypeParamsDeclsWithHash; - _112_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - RAST._IExpr _113_printImplBody; - _113_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _85_printImplBodyCases); - RAST._IExpr _114_hashImplBody; - _114_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _86_hashImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams, _113_printImplBody))); + Dafny.ISequence _112_extraCases; + _112_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + _88_printImplBodyCases = Dafny.Sequence.Concat(_88_printImplBodyCases, _112_extraCases); + _89_hashImplBodyCases = Dafny.Sequence.Concat(_89_hashImplBodyCases, _112_extraCases); + _90_coerceImplBodyCases = Dafny.Sequence.Concat(_90_coerceImplBodyCases, _112_extraCases); + } + Dafny.ISequence _113_defaultConstrainedTypeParams; + _113_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + Dafny.ISequence _114_rTypeParamsDeclsWithEq; + _114_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); + Dafny.ISequence _115_rTypeParamsDeclsWithHash; + _115_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); + RAST._IExpr _116_printImplBody; + _116_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _88_printImplBodyCases); + RAST._IExpr _117_hashImplBody; + _117_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _89_hashImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams, _116_printImplBody))); if ((new BigInteger((_49_rCoerceTypeParams).Count)).Sign == 1) { - RAST._IExpr _115_coerceImplBody; - _115_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _87_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _69_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _115_coerceImplBody))); + RAST._IExpr _118_coerceImplBody; + _118_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _90_coerceImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _72_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _118_coerceImplBody))); } if ((new BigInteger((_9_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { - RAST._IType _116_instantiationType; + RAST._IType _119_instantiationType; if (_0_isRcWrapped) { - _116_instantiationType = RAST.__default.Rc(_69_datatypeType); + _119_instantiationType = RAST.__default.Rc(_72_datatypeType); } else { - _116_instantiationType = _69_datatypeType; + _119_instantiationType = _72_datatypeType; } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _69_datatypeType, _116_instantiationType, _9_singletonConstructors))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _72_datatypeType, _119_instantiationType, _9_singletonConstructors))); } - if (_68_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_111_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), Dafny.Sequence.FromElements())))); + if (_71_cIsEq) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_114_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), Dafny.Sequence.FromElements())))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_112_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), _114_hashImplBody))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_115_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), _117_hashImplBody))); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - RAST._IExpr _117_structName; - _117_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _118_structAssignments; - _118_structAssignments = Dafny.Sequence.FromElements(); + RAST._IExpr _120_structName; + _120_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _121_structAssignments; + _121_structAssignments = Dafny.Sequence.FromElements(); BigInteger _hi11 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); - for (BigInteger _119_i = BigInteger.Zero; _119_i < _hi11; _119_i++) { - DAST._IDatatypeDtor _120_dtor; - _120_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_119_i); - _118_structAssignments = Dafny.Sequence.Concat(_118_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_120_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); + for (BigInteger _122_i = BigInteger.Zero; _122_i < _hi11; _122_i++) { + DAST._IDatatypeDtor _123_dtor; + _123_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_122_i); + _121_structAssignments = Dafny.Sequence.Concat(_121_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_123_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); } - RAST._IType _121_fullType; - _121_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); - if ((false) && (_68_cIsEq)) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _121_fullType, _117_structName, _118_structAssignments))); + RAST._IType _124_fullType; + _124_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); + if ((false) && (_71_cIsEq)) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _124_fullType, _120_structName, _121_structAssignments))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _121_fullType))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _124_fullType))); } - Dafny.ISequence _122_superTraitImplementations; + Dafny.ISequence _125_superTraitImplementations; Dafny.ISequence _out22; - _out22 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, Dafny.Sequence.UnicodeFromString("datatype")); - _122_superTraitImplementations = _out22; - s = Dafny.Sequence.Concat(s, _122_superTraitImplementations); + _out22 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, _71_cIsEq, Dafny.Sequence.UnicodeFromString("datatype")); + _125_superTraitImplementations = _out22; + s = Dafny.Sequence.Concat(s, _125_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -1487,9 +1558,6 @@ public RAST._IExpr GenPathExpr(Dafny.ISequence> p, b } return s; } - public bool IsRcWrapped(Dafny.ISequence attributes) { - return ((!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("auto-nongrowing-size"), Dafny.Sequence>.FromElements()))) && (!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("false")))))) || ((attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("true"))))); - } public RAST._IType GenType(DAST._IType c, bool genTypeContext) { RAST._IType s = RAST.Type.Default(); @@ -1523,7 +1591,7 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) { if (_source1.is_Datatype) { { - if ((this).IsRcWrapped((_0_resolved).dtor_attributes)) { + if (Defs.__default.IsRcWrapped((_0_resolved).dtor_attributes)) { s = RAST.__default.Rc(s); } } @@ -1886,7 +1954,7 @@ public void GenClassImplBody(Dafny.ISequence body, bool forTrait, after_match0: ; } } - public Dafny.ISequence GenParams(Dafny.ISequence @params, bool forLambda) + public Dafny.ISequence GenParams(Dafny.ISequence @params, Dafny.ISequence inheritedParams, bool forLambda) { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.FromElements(); @@ -1894,14 +1962,24 @@ public void GenClassImplBody(Dafny.ISequence body, bool forTrait, for (BigInteger _0_i = BigInteger.Zero; _0_i < _hi0; _0_i++) { DAST._IFormal _1_param; _1_param = (@params).Select(_0_i); - RAST._IType _2_paramType; + DAST._IFormal _2_inheritedParam; + if ((_0_i) < (new BigInteger((inheritedParams).Count))) { + _2_inheritedParam = (inheritedParams).Select(_0_i); + } else { + _2_inheritedParam = _1_param; + } + RAST._IType _3_paramType; RAST._IType _out0; _out0 = (this).GenType((_1_param).dtor_typ, Defs.GenTypeContext.@default()); - _2_paramType = _out0; - if (((!((_2_paramType).CanReadWithoutClone())) || (forLambda)) && (!((_1_param).dtor_attributes).Contains(Defs.__default.AttributeOwned))) { - _2_paramType = RAST.Type.create_Borrowed(_2_paramType); + _3_paramType = _out0; + RAST._IType _4_inheritedParamType; + RAST._IType _out1; + _out1 = (this).GenType((_2_inheritedParam).dtor_typ, Defs.GenTypeContext.@default()); + _4_inheritedParamType = _out1; + if (((!((_4_inheritedParamType).CanReadWithoutClone())) || (forLambda)) && (!((_1_param).dtor_attributes).Contains(Defs.__default.AttributeOwned))) { + _3_paramType = RAST.Type.create_Borrowed(_3_paramType); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.Formal.create(Defs.__default.escapeVar((_1_param).dtor_name), _2_paramType))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.Formal.create(Defs.__default.escapeVar((_1_param).dtor_name), _3_paramType))); } return s; } @@ -1910,7 +1988,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e RAST._IImplMember s = RAST.ImplMember.Default(); Dafny.ISequence _0_params; Dafny.ISequence _out0; - _out0 = (this).GenParams((m).dtor_params, false); + _out0 = (this).GenParams((m).dtor_params, (m).dtor_inheritedParams, false); _0_params = _out0; Dafny.ISequence> _1_paramNames; _1_paramNames = Dafny.Sequence>.FromElements(); @@ -1968,9 +2046,7 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e if ((_15_tpe).IsObjectOrPointer()) { _15_tpe = RAST.__default.SelfBorrowed; } else { - if ((((enclosingType).is_UserDefined) && ((((enclosingType).dtor_resolved).dtor_kind).is_Datatype)) && ((this).IsRcWrapped(((enclosingType).dtor_resolved).dtor_attributes))) { - _15_tpe = RAST.Type.create_Borrowed(RAST.__default.Rc(RAST.__default.SelfOwned)); - } else if ((((enclosingType).is_UserDefined) && ((((enclosingType).dtor_resolved).dtor_kind).is_Newtype)) && (Defs.__default.IsNewtypeCopy((((enclosingType).dtor_resolved).dtor_kind).dtor_range))) { + if (((((enclosingType).is_UserDefined) && ((((enclosingType).dtor_resolved).dtor_kind).is_Newtype)) && (Defs.__default.IsNewtypeCopy((((enclosingType).dtor_resolved).dtor_kind).dtor_range))) && (!(forTrait))) { _15_tpe = RAST.Type.create_TMetaData(RAST.__default.SelfOwned, true, ((((enclosingType).dtor_resolved).dtor_kind).dtor_range).CanOverflow()); } else { _15_tpe = RAST.__default.SelfBorrowed; @@ -2103,15 +2179,15 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e after_match1: ; _32_env = Defs.Environment.create(Dafny.Sequence>.Concat(_34_preAssignNames, _1_paramNames), Dafny.Map, RAST._IType>.Merge(_35_preAssignTypes, _2_paramTypes), Dafny.Set>.FromElements()); RAST._IExpr _50_body; - Dafny.ISet> _51___v19; - Defs._IEnvironment _52___v20; + Dafny.ISet> _51___v24; + Defs._IEnvironment _52___v25; RAST._IExpr _out6; Dafny.ISet> _out7; Defs._IEnvironment _out8; (this).GenStmts((m).dtor_body, _8_selfIdent, _32_env, true, _36_earlyReturn, out _out6, out _out7, out _out8); _50_body = _out6; - _51___v19 = _out7; - _52___v20 = _out8; + _51___v24 = _out7; + _52___v25 = _out8; _31_fBody = Std.Wrappers.Option.create_Some((_33_preBody).Then(_50_body)); } else { _32_env = Defs.Environment.create(_1_paramNames, _2_paramTypes, Dafny.Set>.FromElements()); @@ -2404,14 +2480,14 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Defs._ISelfInfo BigInteger _hi0 = new BigInteger((_12_indices).Count); for (BigInteger _18_i = BigInteger.Zero; _18_i < _hi0; _18_i++) { RAST._IExpr _19_idx; - Defs._IOwnership _20___v28; + Defs._IOwnership _20___v33; Dafny.ISet> _21_recIdentsIdx; RAST._IExpr _out6; Defs._IOwnership _out7; Dafny.ISet> _out8; (this).GenExpr((_12_indices).Select(_18_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out6, out _out7, out _out8); _19_idx = _out6; - _20___v28 = _out7; + _20___v33 = _out7; _21_recIdentsIdx = _out8; Dafny.ISequence _22_varName; _22_varName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("__idx"), Std.Strings.__default.OfNat(_18_i)); @@ -2619,15 +2695,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _5_isAssignedVar = Defs.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { RAST._IExpr _6_rhs; - Defs._IOwnership _7___v42; - Dafny.ISet> _8___v43; + Defs._IOwnership _7___v47; + Dafny.ISet> _8___v48; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr(DAST.Expression.create_InitializationValue(((_2_field).dtor_formal).dtor_typ), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); _6_rhs = _out1; - _7___v42 = _out2; - _8___v43 = _out3; + _7___v47 = _out2; + _8___v48 = _out3; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); Dafny.ISequence _9_update__if__uninit; if ((_2_field).dtor_isConstant) { @@ -2722,14 +2798,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _22_expression = _source0.dtor_value; { RAST._IExpr _23_exprGen; - Defs._IOwnership _24___v44; + Defs._IOwnership _24___v49; Dafny.ISet> _25_exprIdents; RAST._IExpr _out12; Defs._IOwnership _out13; Dafny.ISet> _out14; (this).GenExpr(_22_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out12, out _out13, out _out14); _23_exprGen = _out12; - _24___v44 = _out13; + _24___v49 = _out13; _25_exprIdents = _out14; if ((_21_lhs).is_Ident) { Dafny.ISequence _26_rustId; @@ -2779,14 +2855,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _36_elsDafny = _source0.dtor_els; { RAST._IExpr _37_cond; - Defs._IOwnership _38___v45; + Defs._IOwnership _38___v50; Dafny.ISet> _39_recIdents; RAST._IExpr _out19; Defs._IOwnership _out20; Dafny.ISet> _out21; (this).GenExpr(_34_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out19, out _out20, out _out21); _37_cond = _out19; - _38___v45 = _out20; + _38___v50 = _out20; _39_recIdents = _out21; Dafny.ISequence _40_condString; _40_condString = (_37_cond)._ToString(Defs.__default.IND); @@ -2847,14 +2923,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _53_body = _source0.dtor_body; { RAST._IExpr _54_cond; - Defs._IOwnership _55___v46; + Defs._IOwnership _55___v51; Dafny.ISet> _56_recIdents; RAST._IExpr _out31; Defs._IOwnership _out32; Dafny.ISet> _out33; (this).GenExpr(_52_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out31, out _out32, out _out33); _54_cond = _out31; - _55___v46 = _out32; + _55___v51 = _out32; _56_recIdents = _out33; readIdents = _56_recIdents; RAST._IExpr _57_bodyExpr; @@ -2882,14 +2958,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _63_body = _source0.dtor_body; { RAST._IExpr _64_over; - Defs._IOwnership _65___v47; + Defs._IOwnership _65___v52; Dafny.ISet> _66_recIdents; RAST._IExpr _out37; Defs._IOwnership _out38; Dafny.ISet> _out39; (this).GenExpr(_62_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out37, out _out38, out _out39); _64_over = _out37; - _65___v47 = _out38; + _65___v52 = _out38; _66_recIdents = _out39; if (((_62_overExpr).is_MapBoundedPool) || ((_62_overExpr).is_SetBoundedPool)) { _64_over = ((_64_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); @@ -2953,15 +3029,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _75_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { RAST._IExpr _76_selfClone; - Defs._IOwnership _77___v48; - Dafny.ISet> _78___v49; + Defs._IOwnership _77___v53; + Dafny.ISet> _78___v54; RAST._IExpr _out44; Defs._IOwnership _out45; Dafny.ISet> _out46; (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out44, out _out45, out _out46); _76_selfClone = _out44; - _77___v48 = _out45; - _78___v49 = _out46; + _77___v53 = _out45; + _78___v54 = _out46; generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_76_selfClone))); if (((_75_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { _75_oldEnv = (_75_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); @@ -2978,15 +3054,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv goto continue_4_0; } RAST._IExpr _82_paramInit; - Defs._IOwnership _83___v50; - Dafny.ISet> _84___v51; + Defs._IOwnership _83___v55; + Dafny.ISet> _84___v56; RAST._IExpr _out47; Defs._IOwnership _out48; Dafny.ISet> _out49; (this).GenIdent(_81_param, selfIdent, _75_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out47, out _out48, out _out49); _82_paramInit = _out47; - _83___v50 = _out48; - _84___v51 = _out49; + _83___v55 = _out48; + _84___v56 = _out49; Dafny.ISequence _85_recVar; _85_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_80_paramI)); generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _85_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_82_paramInit))); @@ -3078,14 +3154,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _102_exprDafny = _source0.dtor_expr; { RAST._IExpr _103_expr; - Defs._IOwnership _104___v52; + Defs._IOwnership _104___v57; Dafny.ISet> _105_recIdents; RAST._IExpr _out55; Defs._IOwnership _out56; Dafny.ISet> _out57; (this).GenExpr(_102_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out55, out _out56, out _out57); _103_expr = _out55; - _104___v52 = _out56; + _104___v57 = _out56; _105_recIdents = _out57; readIdents = _105_recIdents; if (isLast) { @@ -3115,15 +3191,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv BigInteger _hi3 = new BigInteger((_106_rustIdents).Count); for (BigInteger _108_i = BigInteger.Zero; _108_i < _hi3; _108_i++) { RAST._IExpr _109_rIdent; - Defs._IOwnership _110___v53; - Dafny.ISet> _111___v54; + Defs._IOwnership _110___v58; + Dafny.ISet> _111___v59; RAST._IExpr _out58; Defs._IOwnership _out59; Dafny.ISet> _out60; (this).GenIdent((_106_rustIdents).Select(_108_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out58, out _out59, out _out60); _109_rIdent = _out58; - _110___v53 = _out59; - _111___v54 = _out60; + _110___v58 = _out59; + _111___v59 = _out60; _107_tupleArgs = Dafny.Sequence.Concat(_107_tupleArgs, Dafny.Sequence.FromElements(_109_rIdent)); } if ((new BigInteger((_107_tupleArgs).Count)) == (BigInteger.One)) { @@ -3519,24 +3595,24 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ _10_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); } RAST._IExpr _11_left; - Defs._IOwnership _12___v55; + Defs._IOwnership _12___v60; Dafny.ISet> _13_recIdentsL; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(_4_lExpr, selfIdent, env, _9_expectedLeftOwnership, out _out0, out _out1, out _out2); _11_left = _out0; - _12___v55 = _out1; + _12___v60 = _out1; _13_recIdentsL = _out2; RAST._IExpr _14_right; - Defs._IOwnership _15___v56; + Defs._IOwnership _15___v61; Dafny.ISet> _16_recIdentsR; RAST._IExpr _out3; Defs._IOwnership _out4; Dafny.ISet> _out5; (this).GenExpr(_5_rExpr, selfIdent, env, _10_expectedRightOwnership, out _out3, out _out4, out _out5); _14_right = _out3; - _15___v56 = _out4; + _15___v61 = _out4; _16_recIdentsR = _out5; DAST._IBinOp _source0 = _0_op; { @@ -4574,27 +4650,31 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden } resultingOwnership = Defs.Ownership.create_OwnershipBorrowedMut(); } else if (object.Equals(expectedOwnership, Defs.Ownership.create_OwnershipOwned())) { - bool _5_needObjectFromRef; - _5_needObjectFromRef = (_4_isSelf) && ((selfIdent).IsClassOrObjectTrait()); - if (_5_needObjectFromRef) { + bool _5_needsObjectFromRef; + _5_needsObjectFromRef = (_4_isSelf) && ((selfIdent).IsClassOrObjectTrait()); + bool _6_needsRcWrapping; + _6_needsRcWrapping = (_4_isSelf) && ((selfIdent).IsRcWrappedDatatype()); + if (_5_needsObjectFromRef) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Object"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))).FSel(Dafny.Sequence.UnicodeFromString("from_ref"))).Apply(Dafny.Sequence.FromElements(r)); + } else if (_6_needsRcWrapping) { + r = RAST.__default.RcNew((r).Clone()); } else { if (!(_3_noNeedOfClone)) { - bool _6_needUnderscoreClone; - _6_needUnderscoreClone = (_4_isSelf) && ((selfIdent).IsGeneralTrait()); - if (_6_needUnderscoreClone) { - RAST._IType _7_traitType; + bool _7_needUnderscoreClone; + _7_needUnderscoreClone = (_4_isSelf) && ((selfIdent).IsGeneralTrait()); + if (_7_needUnderscoreClone) { + RAST._IType _8_traitType; RAST._IType _out0; _out0 = (this).GenType((selfIdent).dtor_dafnyType, Defs.GenTypeContext.ForTraitParents()); - _7_traitType = _out0; - Std.Wrappers._IOption _8_traitExpr; - _8_traitExpr = (_7_traitType).ToExpr(); - if ((_8_traitExpr).is_None) { + _8_traitType = _out0; + Std.Wrappers._IOption _9_traitExpr; + _9_traitExpr = (_8_traitType).ToExpr(); + if ((_9_traitExpr).is_None) { RAST._IExpr _out1; - _out1 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_7_traitType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); + _out1 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_8_traitType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); r = _out1; } else { - r = (((_8_traitExpr).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(r); + r = (((_9_traitExpr).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(r); } } else { r = (r).Clone(); @@ -4605,15 +4685,15 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden } else if (_2_currentlyBorrowed) { resultingOwnership = Defs.Ownership.create_OwnershipBorrowed(); } else { - bool _9_selfIsGeneralTrait; - _9_selfIsGeneralTrait = (_4_isSelf) && (((System.Func)(() => { + bool _10_selfIsGeneralTrait; + _10_selfIsGeneralTrait = (_4_isSelf) && (((System.Func)(() => { DAST._IType _source0 = (selfIdent).dtor_dafnyType; { if (_source0.is_UserDefined) { DAST._IResolvedType resolved0 = _source0.dtor_resolved; - DAST._IResolvedTypeBase _10_base = resolved0.dtor_kind; - Dafny.ISequence _11_attributes = resolved0.dtor_attributes; - return ((_10_base).is_Trait) && (((_10_base).dtor_traitType).is_GeneralTrait); + DAST._IResolvedTypeBase _11_base = resolved0.dtor_kind; + Dafny.ISequence _12_attributes = resolved0.dtor_attributes; + return ((_11_base).is_Trait) && (((_11_base).dtor_traitType).is_GeneralTrait); } } { @@ -4646,38 +4726,38 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ fullNameQualifier = Std.Wrappers.Option.Default(); argExprs = Dafny.Sequence.FromElements(); readIdents = Dafny.Set>.FromElements(); - Dafny.ISequence _0_signature; + Dafny.ISequence _0_borrowSignature = Dafny.Sequence.Empty; if ((name).is_CallName) { if ((((name).dtor_receiverArg).is_Some) && ((name).dtor_receiverAsArgument)) { - _0_signature = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(((name).dtor_receiverArg).dtor_value), ((name).dtor_signature)); + _0_borrowSignature = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(((name).dtor_receiverArg).dtor_value), ((name).dtor_signature).dtor_inheritedParams); } else { - _0_signature = ((name).dtor_signature); + _0_borrowSignature = ((name).dtor_signature).dtor_inheritedParams; } } else { - _0_signature = Dafny.Sequence.FromElements(); + _0_borrowSignature = Dafny.Sequence.FromElements(); } BigInteger _hi0 = new BigInteger((args).Count); for (BigInteger _1_i = BigInteger.Zero; _1_i < _hi0; _1_i++) { Defs._IOwnership _2_argOwnership; _2_argOwnership = Defs.Ownership.create_OwnershipBorrowed(); - if ((_1_i) < (new BigInteger((_0_signature).Count))) { + if ((_1_i) < (new BigInteger((_0_borrowSignature).Count))) { RAST._IType _3_tpe; RAST._IType _out0; - _out0 = (this).GenType(((_0_signature).Select(_1_i)).dtor_typ, Defs.GenTypeContext.@default()); + _out0 = (this).GenType(((_0_borrowSignature).Select(_1_i)).dtor_typ, Defs.GenTypeContext.@default()); _3_tpe = _out0; if ((_3_tpe).CanReadWithoutClone()) { _2_argOwnership = Defs.Ownership.create_OwnershipOwned(); } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v69; + Defs._IOwnership _5___v74; Dafny.ISet> _6_argIdents; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); _4_argExpr = _out1; - _5___v69 = _out2; + _5___v74 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -4875,14 +4955,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi1 = new BigInteger((_9_values).Count); for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13___v79; + Defs._IOwnership _13___v84; Dafny.ISet> _14_recIdents; RAST._IExpr _out16; Defs._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); _12_recursiveGen = _out16; - _13___v79 = _out17; + _13___v84 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -4931,14 +5011,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi3 = new BigInteger((_17_args).Count); for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { RAST._IExpr _23_recursiveGen; - Defs._IOwnership _24___v80; + Defs._IOwnership _24___v85; Dafny.ISet> _25_recIdents; RAST._IExpr _out23; Defs._IOwnership _out24; Dafny.ISet> _out25; (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); _23_recursiveGen = _out23; - _24___v80 = _out24; + _24___v85 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -4976,14 +5056,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi4 = new BigInteger((_26_dims).Count); for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { RAST._IExpr _31_recursiveGen; - Defs._IOwnership _32___v81; + Defs._IOwnership _32___v86; Dafny.ISet> _33_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr((_26_dims).Select(_30_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _31_recursiveGen = _out30; - _32___v81 = _out31; + _32___v86 = _out31; _33_recIdents = _out32; _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); @@ -5010,14 +5090,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _35_underlying = _source0.dtor_value; { RAST._IExpr _36_recursiveGen; - Defs._IOwnership _37___v82; + Defs._IOwnership _37___v87; Dafny.ISet> _38_recIdents; RAST._IExpr _out35; Defs._IOwnership _out36; Dafny.ISet> _out37; (this).GenExpr(_35_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out35, out _out36, out _out37); _36_recursiveGen = _out35; - _37___v82 = _out36; + _37___v87 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -5040,14 +5120,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out40 = (this).GenType(_40_typ, Defs.GenTypeContext.@default()); _41_tpe = _out40; RAST._IExpr _42_recursiveGen; - Defs._IOwnership _43___v83; + Defs._IOwnership _43___v88; Dafny.ISet> _44_recIdents; RAST._IExpr _out41; Defs._IOwnership _out42; Dafny.ISet> _out43; (this).GenExpr(_39_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); _42_recursiveGen = _out41; - _43___v83 = _out42; + _43___v88 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -5113,14 +5193,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; if (_50_isCo) { RAST._IExpr _59_recursiveGen; - Defs._IOwnership _60___v84; + Defs._IOwnership _60___v89; Dafny.ISet> _61_recIdents; RAST._IExpr _out50; Defs._IOwnership _out51; Dafny.ISet> _out52; (this).GenExpr(_58_value, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); _59_recursiveGen = _out50; - _60___v84 = _out51; + _60___v89 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -5143,21 +5223,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _64_wasAssigned))); } else { RAST._IExpr _65_recursiveGen; - Defs._IOwnership _66___v85; + Defs._IOwnership _66___v90; Dafny.ISet> _67_recIdents; RAST._IExpr _out53; Defs._IOwnership _out54; Dafny.ISet> _out55; (this).GenExpr(_58_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out53, out _out54, out _out55); _65_recursiveGen = _out53; - _66___v85 = _out54; + _66___v90 = _out54; _67_recIdents = _out55; _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _65_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); } } r = RAST.Expr.create_StructBuild(r, _55_assignments); - if ((this).IsRcWrapped((_47_datatypeType).dtor_attributes)) { + if (Defs.__default.IsRcWrapped((_47_datatypeType).dtor_attributes)) { r = RAST.__default.RcNew(r); } RAST._IExpr _out56; @@ -5190,24 +5270,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _69_expr = _source0.dtor_elem; { RAST._IExpr _70_recursiveGen; - Defs._IOwnership _71___v89; + Defs._IOwnership _71___v94; Dafny.ISet> _72_recIdents; RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; (this).GenExpr(_69_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); _70_recursiveGen = _out61; - _71___v89 = _out62; + _71___v94 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v90; + Defs._IOwnership _74___v95; Dafny.ISet> _75_lengthIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_68_length, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); _73_lengthGen = _out64; - _74___v90 = _out65; + _74___v95 = _out65; _75_lengthIdents = _out66; r = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("_initializer"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_70_recursiveGen)); RAST._IExpr _76_range; @@ -5246,14 +5326,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _82_args = Dafny.Sequence.FromElements(); while ((_81_i) < (new BigInteger((_78_exprs).Count))) { RAST._IExpr _83_recursiveGen; - Defs._IOwnership _84___v91; + Defs._IOwnership _84___v96; Dafny.ISet> _85_recIdents; RAST._IExpr _out70; Defs._IOwnership _out71; Dafny.ISet> _out72; (this).GenExpr((_78_exprs).Select(_81_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out70, out _out71, out _out72); _83_recursiveGen = _out70; - _84___v91 = _out71; + _84___v96 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -5284,14 +5364,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _88_i = BigInteger.Zero; while ((_88_i) < (new BigInteger((_86_exprs).Count))) { RAST._IExpr _89_recursiveGen; - Defs._IOwnership _90___v92; + Defs._IOwnership _90___v97; Dafny.ISet> _91_recIdents; RAST._IExpr _out75; Defs._IOwnership _out76; Dafny.ISet> _out77; (this).GenExpr((_86_exprs).Select(_88_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out75, out _out76, out _out77); _89_recursiveGen = _out75; - _90___v92 = _out76; + _90___v97 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -5319,14 +5399,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _94_i = BigInteger.Zero; while ((_94_i) < (new BigInteger((_92_exprs).Count))) { RAST._IExpr _95_recursiveGen; - Defs._IOwnership _96___v93; + Defs._IOwnership _96___v98; Dafny.ISet> _97_recIdents; RAST._IExpr _out80; Defs._IOwnership _out81; Dafny.ISet> _out82; (this).GenExpr((_92_exprs).Select(_94_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out80, out _out81, out _out82); _95_recursiveGen = _out80; - _96___v93 = _out81; + _96___v98 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -5348,14 +5428,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _98_expr = _source0.dtor_ToMultiset_a0; { RAST._IExpr _99_recursiveGen; - Defs._IOwnership _100___v94; + Defs._IOwnership _100___v99; Dafny.ISet> _101_recIdents; RAST._IExpr _out85; Defs._IOwnership _out86; Dafny.ISet> _out87; (this).GenExpr(_98_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out85, out _out86, out _out87); _99_recursiveGen = _out85; - _100___v94 = _out86; + _100___v99 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -5380,24 +5460,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _104_i = BigInteger.Zero; while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v95; + Defs._IOwnership _106___v100; Dafny.ISet> _107_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); _105_recursiveGenKey = _out90; - _106___v95 = _out91; + _106___v100 = _out91; _107_recIdentsKey = _out92; RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v96; + Defs._IOwnership _109___v101; Dafny.ISet> _110_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); _108_recursiveGenValue = _out93; - _109___v96 = _out94; + _109___v101 = _out94; _110_recIdentsValue = _out95; _103_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_103_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_105_recursiveGenKey, _108_recursiveGenValue))); readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _107_recIdentsKey), _110_recIdentsValue); @@ -5432,14 +5512,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _116_value = _source0.dtor_value; { RAST._IExpr _117_exprR; - Defs._IOwnership _118___v97; + Defs._IOwnership _118___v102; Dafny.ISet> _119_exprIdents; RAST._IExpr _out98; Defs._IOwnership _out99; Dafny.ISet> _out100; (this).GenExpr(_114_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out98, out _out99, out _out100); _117_exprR = _out98; - _118___v97 = _out99; + _118___v102 = _out99; _119_exprIdents = _out100; RAST._IExpr _120_indexR; Defs._IOwnership _121_indexOwnership; @@ -5480,14 +5560,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _128_value = _source0.dtor_value; { RAST._IExpr _129_exprR; - Defs._IOwnership _130___v98; + Defs._IOwnership _130___v103; Dafny.ISet> _131_exprIdents; RAST._IExpr _out109; Defs._IOwnership _out110; Dafny.ISet> _out111; (this).GenExpr(_126_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out109, out _out110, out _out111); _129_exprR = _out109; - _130___v98 = _out110; + _130___v103 = _out110; _131_exprIdents = _out111; RAST._IExpr _132_indexR; Defs._IOwnership _133_indexOwnership; @@ -5568,14 +5648,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _143_f = _source0.dtor_els; { RAST._IExpr _144_cond; - Defs._IOwnership _145___v99; + Defs._IOwnership _145___v104; Dafny.ISet> _146_recIdentsCond; RAST._IExpr _out126; Defs._IOwnership _out127; Dafny.ISet> _out128; (this).GenExpr(_141_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out126, out _out127, out _out128); _144_cond = _out126; - _145___v99 = _out127; + _145___v104 = _out127; _146_recIdentsCond = _out128; RAST._IExpr _147_fExpr; Defs._IOwnership _148_fOwned; @@ -5588,14 +5668,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _148_fOwned = _out130; _149_recIdentsF = _out131; RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v100; + Defs._IOwnership _151___v105; Dafny.ISet> _152_recIdentsT; RAST._IExpr _out132; Defs._IOwnership _out133; Dafny.ISet> _out134; (this).GenExpr(_142_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); _150_tExpr = _out132; - _151___v100 = _out133; + _151___v105 = _out133; _152_recIdentsT = _out134; r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); RAST._IExpr _out135; @@ -5617,14 +5697,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; { RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v101; + Defs._IOwnership _156___v106; Dafny.ISet> _157_recIdents; RAST._IExpr _out137; Defs._IOwnership _out138; Dafny.ISet> _out139; (this).GenExpr(_153_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out137, out _out138, out _out139); _155_recursiveGen = _out137; - _156___v101 = _out138; + _156___v106 = _out138; _157_recIdents = _out139; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); RAST._IExpr _out140; @@ -5647,14 +5727,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; { RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v102; + Defs._IOwnership _161___v107; Dafny.ISet> _162_recIdents; RAST._IExpr _out142; Defs._IOwnership _out143; Dafny.ISet> _out144; (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out142, out _out143, out _out144); _160_recursiveGen = _out142; - _161___v102 = _out143; + _161___v107 = _out143; _162_recIdents = _out144; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); RAST._IExpr _out145; @@ -5719,14 +5799,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _171_native = _source0.dtor_native; { RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v107; + Defs._IOwnership _173___v112; Dafny.ISet> _174_recIdents; RAST._IExpr _out155; Defs._IOwnership _out156; Dafny.ISet> _out157; (this).GenExpr(_168_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out155, out _out156, out _out157); _172_recursiveGen = _out155; - _173___v107 = _out156; + _173___v112 = _out156; _174_recIdents = _out157; RAST._IType _175_arrayType; RAST._IType _out158; @@ -5768,14 +5848,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _177_expr = _source0.dtor_expr; { RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v108; + Defs._IOwnership _179___v113; Dafny.ISet> _180_recIdents; RAST._IExpr _out162; Defs._IOwnership _out163; Dafny.ISet> _out164; (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); _178_recursiveGen = _out162; - _179___v108 = _out163; + _179___v113 = _out163; _180_recIdents = _out164; readIdents = _180_recIdents; r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); @@ -5794,14 +5874,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _181_expr = _source0.dtor_expr; { RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v109; + Defs._IOwnership _183___v114; Dafny.ISet> _184_recIdents; RAST._IExpr _out167; Defs._IOwnership _out168; Dafny.ISet> _out169; (this).GenExpr(_181_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); _182_recursiveGen = _out167; - _183___v109 = _out168; + _183___v114 = _out168; _184_recIdents = _out169; readIdents = _184_recIdents; r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); @@ -5820,14 +5900,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _185_expr = _source0.dtor_expr; { RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v110; + Defs._IOwnership _187___v115; Dafny.ISet> _188_recIdents; RAST._IExpr _out172; Defs._IOwnership _out173; Dafny.ISet> _out174; (this).GenExpr(_185_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out172, out _out173, out _out174); _186_recursiveGen = _out172; - _187___v110 = _out173; + _187___v115 = _out173; _188_recIdents = _out174; readIdents = _188_recIdents; r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); @@ -5899,15 +5979,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _209_name = _let_tmp_rhs1.dtor__0; RAST._IType _210_ty = _let_tmp_rhs1.dtor__1; RAST._IExpr _211_rIdent; - Defs._IOwnership _212___v111; - Dafny.ISet> _213___v112; + Defs._IOwnership _212___v116; + Dafny.ISet> _213___v117; RAST._IExpr _out181; Defs._IOwnership _out182; Dafny.ISet> _out183; (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((!(_193_isConstant)) && ((_210_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); _211_rIdent = _out181; - _212___v111 = _out182; - _213___v112 = _out183; + _212___v116 = _out182; + _213___v117 = _out183; _207_onExprArgs = Dafny.Sequence.Concat(_207_onExprArgs, Dafny.Sequence.FromElements(_211_rIdent)); } _206_body = (_206_body).Apply(_207_onExprArgs); @@ -6225,14 +6305,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _260_l = _source5.dtor_value; { RAST._IExpr _261_lExpr; - Defs._IOwnership _262___v115; + Defs._IOwnership _262___v120; Dafny.ISet> _263_recIdentsL; RAST._IExpr _out222; Defs._IOwnership _out223; Dafny.ISet> _out224; (this).GenExpr(_260_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out222, out _out223, out _out224); _261_lExpr = _out222; - _262___v115 = _out223; + _262___v120 = _out223; _263_recIdentsL = _out224; _259_arguments = Dafny.Sequence.Concat(_259_arguments, Dafny.Sequence.FromElements(_261_lExpr)); readIdents = Dafny.Set>.Union(readIdents, _263_recIdentsL); @@ -6249,14 +6329,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _264_h = _source6.dtor_value; { RAST._IExpr _265_hExpr; - Defs._IOwnership _266___v116; + Defs._IOwnership _266___v121; Dafny.ISet> _267_recIdentsH; RAST._IExpr _out225; Defs._IOwnership _out226; Dafny.ISet> _out227; (this).GenExpr(_264_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out225, out _out226, out _out227); _265_hExpr = _out225; - _266___v116 = _out226; + _266___v121 = _out226; _267_recIdentsH = _out227; _259_arguments = Dafny.Sequence.Concat(_259_arguments, Dafny.Sequence.FromElements(_265_hExpr)); readIdents = Dafny.Set>.Union(readIdents, _267_recIdentsH); @@ -6369,7 +6449,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { Dafny.ISequence _284_params; Dafny.ISequence _out239; - _out239 = (this).GenParams(_281_paramsDafny, true); + _out239 = (this).GenParams(_281_paramsDafny, _281_paramsDafny, true); _284_params = _out239; Dafny.ISequence> _285_paramNames; _285_paramNames = Dafny.Sequence>.FromElements(); @@ -6386,14 +6466,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _289_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_285_paramNames, _286_paramTypesMap, Dafny.Set>.FromElements())); RAST._IExpr _290_recursiveGen; Dafny.ISet> _291_recIdents; - Defs._IEnvironment _292___v118; + Defs._IEnvironment _292___v123; RAST._IExpr _out240; Dafny.ISet> _out241; Defs._IEnvironment _out242; (this).GenStmts(_283_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _289_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out240, out _out241, out _out242); _290_recursiveGen = _out240; _291_recIdents = _out241; - _292___v118 = _out242; + _292___v123 = _out242; readIdents = Dafny.Set>.FromElements(); _291_recIdents = Dafny.Set>.Difference(_291_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_293_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); @@ -6419,15 +6499,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir after__ASSIGN_SUCH_THAT_1: ; if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_296_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { RAST._IExpr _297_selfCloned; - Defs._IOwnership _298___v119; - Dafny.ISet> _299___v120; + Defs._IOwnership _298___v124; + Dafny.ISet> _299___v125; RAST._IExpr _out243; Defs._IOwnership _out244; Dafny.ISet> _out245; (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out243, out _out244, out _out245); _297_selfCloned = _out243; - _298___v119 = _out244; - _299___v120 = _out245; + _298___v124 = _out244; + _299___v125 = _out245; _295_allReadCloned = (_295_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_297_selfCloned))); } else if (!((_285_paramNames).Contains(_296_next))) { RAST._IExpr _300_copy; @@ -6464,6 +6544,8 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _out249; _out249 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_307_value) => { return (_307_value).dtor__0; + })), _302_values), Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_307_value) => { + return (_307_value).dtor__0; })), _302_values), false); _306_paramFormals = _out249; Dafny.IMap,RAST._IType> _308_paramTypes; @@ -6489,14 +6571,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out250 = (this).GenType((((_302_values).Select(_313_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); _314_typeGen = _out250; RAST._IExpr _315_valueGen; - Defs._IOwnership _316___v121; + Defs._IOwnership _316___v126; Dafny.ISet> _317_recIdents; RAST._IExpr _out251; Defs._IOwnership _out252; Dafny.ISet> _out253; (this).GenExpr(((_302_values).Select(_313_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out251, out _out252, out _out253); _315_valueGen = _out251; - _316___v121 = _out252; + _316___v126 = _out252; _317_recIdents = _out253; r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_302_values).Select(_313_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_314_typeGen), Std.Wrappers.Option.create_Some(_315_valueGen))); readIdents = Dafny.Set>.Union(readIdents, _317_recIdents); @@ -6533,14 +6615,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _325_iifeBody = _source0.dtor_iifeBody; { RAST._IExpr _326_valueGen; - Defs._IOwnership _327___v122; + Defs._IOwnership _327___v127; Dafny.ISet> _328_recIdents; RAST._IExpr _out259; Defs._IOwnership _out260; Dafny.ISet> _out261; (this).GenExpr(_324_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out259, out _out260, out _out261); _326_valueGen = _out259; - _327___v122 = _out260; + _327___v127 = _out260; _328_recIdents = _out261; readIdents = _328_recIdents; RAST._IType _329_valueTypeGen; @@ -6550,14 +6632,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _330_iifeVar; _330_iifeVar = Defs.__default.escapeVar(_322_name); RAST._IExpr _331_bodyGen; - Defs._IOwnership _332___v123; + Defs._IOwnership _332___v128; Dafny.ISet> _333_bodyIdents; RAST._IExpr _out263; Defs._IOwnership _out264; Dafny.ISet> _out265; (this).GenExpr(_325_iifeBody, selfIdent, (env).AddAssigned(_330_iifeVar, _329_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out263, out _out264, out _out265); _331_bodyGen = _out263; - _332___v123 = _out264; + _332___v128 = _out264; _333_bodyIdents = _out265; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_333_bodyIdents, Dafny.Set>.FromElements(_330_iifeVar))); r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _330_iifeVar, Std.Wrappers.Option.create_Some(_329_valueTypeGen), Std.Wrappers.Option.create_Some(_326_valueGen))).Then(_331_bodyGen)); @@ -6577,14 +6659,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _335_args = _source0.dtor_args; { RAST._IExpr _336_funcExpr; - Defs._IOwnership _337___v124; + Defs._IOwnership _337___v129; Dafny.ISet> _338_recIdents; RAST._IExpr _out268; Defs._IOwnership _out269; Dafny.ISet> _out270; (this).GenExpr(_334_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out268, out _out269, out _out270); _336_funcExpr = _out268; - _337___v124 = _out269; + _337___v129 = _out269; _338_recIdents = _out270; readIdents = _338_recIdents; Dafny.ISequence _339_rArgs; @@ -6622,14 +6704,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _346_variant = _source0.dtor_variant; { RAST._IExpr _347_exprGen; - Defs._IOwnership _348___v125; + Defs._IOwnership _348___v130; Dafny.ISet> _349_recIdents; RAST._IExpr _out276; Defs._IOwnership _out277; Dafny.ISet> _out278; (this).GenExpr(_344_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out276, out _out277, out _out278); _347_exprGen = _out276; - _348___v125 = _out277; + _348___v130 = _out277; _349_recIdents = _out278; RAST._IExpr _350_variantExprPath; RAST._IExpr _out279; @@ -6764,14 +6846,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _368_of = _source0.dtor_of; { RAST._IExpr _369_exprGen; - Defs._IOwnership _370___v126; + Defs._IOwnership _370___v131; Dafny.ISet> _371_recIdents; RAST._IExpr _out300; Defs._IOwnership _out301; Dafny.ISet> _out302; (this).GenExpr(_368_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out300, out _out301, out _out302); _369_exprGen = _out300; - _370___v126 = _out301; + _370___v131 = _out301; _371_recIdents = _out302; r = ((_369_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out303; @@ -6791,14 +6873,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _373_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _374_exprGen; - Defs._IOwnership _375___v127; + Defs._IOwnership _375___v132; Dafny.ISet> _376_recIdents; RAST._IExpr _out305; Defs._IOwnership _out306; Dafny.ISet> _out307; (this).GenExpr(_372_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out305, out _out306, out _out307); _374_exprGen = _out305; - _375___v127 = _out306; + _375___v132 = _out306; _376_recIdents = _out307; r = ((_374_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_373_includeDuplicates)) { @@ -6821,14 +6903,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _378_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _379_exprGen; - Defs._IOwnership _380___v128; + Defs._IOwnership _380___v133; Dafny.ISet> _381_recIdents; RAST._IExpr _out310; Defs._IOwnership _out311; Dafny.ISet> _out312; (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out310, out _out311, out _out312); _379_exprGen = _out310; - _380___v128 = _out311; + _380___v133 = _out311; _381_recIdents = _out312; r = ((_379_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_378_includeDuplicates)) { @@ -6850,14 +6932,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _382_of = _source0.dtor_of; { RAST._IExpr _383_exprGen; - Defs._IOwnership _384___v129; + Defs._IOwnership _384___v134; Dafny.ISet> _385_recIdents; RAST._IExpr _out315; Defs._IOwnership _out316; Dafny.ISet> _out317; (this).GenExpr(_382_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out315, out _out316, out _out317); _383_exprGen = _out315; - _384___v129 = _out316; + _384___v134 = _out316; _385_recIdents = _out317; r = ((((_383_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); readIdents = _385_recIdents; @@ -6875,14 +6957,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _386_of = _source0.dtor_of; { RAST._IExpr _387_exprGen; - Defs._IOwnership _388___v130; + Defs._IOwnership _388___v135; Dafny.ISet> _389_recIdents; RAST._IExpr _out320; Defs._IOwnership _out321; Dafny.ISet> _out322; (this).GenExpr(_386_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out320, out _out321, out _out322); _387_exprGen = _out320; - _388___v130 = _out321; + _388___v135 = _out321; _389_recIdents = _out322; r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_387_exprGen); readIdents = _389_recIdents; @@ -6903,24 +6985,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _393_up = _source0.dtor_up; { RAST._IExpr _394_lo; - Defs._IOwnership _395___v131; + Defs._IOwnership _395___v136; Dafny.ISet> _396_recIdentsLo; RAST._IExpr _out325; Defs._IOwnership _out326; Dafny.ISet> _out327; (this).GenExpr(_391_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out325, out _out326, out _out327); _394_lo = _out325; - _395___v131 = _out326; + _395___v136 = _out326; _396_recIdentsLo = _out327; RAST._IExpr _397_hi; - Defs._IOwnership _398___v132; + Defs._IOwnership _398___v137; Dafny.ISet> _399_recIdentsHi; RAST._IExpr _out328; Defs._IOwnership _out329; Dafny.ISet> _out330; (this).GenExpr(_392_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out328, out _out329, out _out330); _397_hi = _out328; - _398___v132 = _out329; + _398___v137 = _out329; _399_recIdentsHi = _out330; if (_393_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_394_lo, _397_hi)); @@ -6951,14 +7033,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _402_up = _source0.dtor_up; { RAST._IExpr _403_start; - Defs._IOwnership _404___v133; + Defs._IOwnership _404___v138; Dafny.ISet> _405_recIdentStart; RAST._IExpr _out334; Defs._IOwnership _out335; Dafny.ISet> _out336; (this).GenExpr(_401_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); _403_start = _out334; - _404___v133 = _out335; + _404___v138 = _out335; _405_recIdentStart = _out336; if (_402_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_403_start); @@ -7032,14 +7114,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out346 = (this).GenType(_412_elemType, Defs.GenTypeContext.@default()); _416_tpe = _out346; RAST._IExpr _417_collectionGen; - Defs._IOwnership _418___v134; + Defs._IOwnership _418___v139; Dafny.ISet> _419_recIdents; RAST._IExpr _out347; Defs._IOwnership _out348; Dafny.ISet> _out349; (this).GenExpr(_413_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out347, out _out348, out _out349); _417_collectionGen = _out347; - _418___v134 = _out348; + _418___v139 = _out348; _419_recIdents = _out349; Dafny.ISequence _420_extraAttributes; _420_extraAttributes = Dafny.Sequence.FromElements(); @@ -7062,14 +7144,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _428_dt__update_hparams_h0 = _422_newFormals; _426_newLambda = DAST.Expression.create_Lambda(_428_dt__update_hparams_h0, (_427_dt__update__tmp_h1).dtor_retType, (_427_dt__update__tmp_h1).dtor_body); RAST._IExpr _429_lambdaGen; - Defs._IOwnership _430___v135; + Defs._IOwnership _430___v140; Dafny.ISet> _431_recLambdaIdents; RAST._IExpr _out350; Defs._IOwnership _out351; Dafny.ISet> _out352; (this).GenExpr(_426_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out350, out _out351, out _out352); _429_lambdaGen = _out350; - _430___v135 = _out351; + _430___v140 = _out351; _431_recLambdaIdents = _out352; Dafny.ISequence _432_fn; if (_414_is__forall) { @@ -7176,15 +7258,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v136; - Dafny.ISet> _2___v137; + Defs._IOwnership _1___v141; + Dafny.ISet> _2___v142; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v136 = _out1; - _2___v137 = _out2; + _1___v141 = _out1; + _2___v142 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index 57fefbcfd6c..af5997844e7 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -169,6 +169,39 @@ public static bool is__idiomatic__rust__id(Dafny.ISequence i) { return Defs.__default.TraitTypeContainingMethodAux(_5_extendedTypes, dafnyName); } } + public static bool IsRcWrappedDatatypeRec(DAST._IType dafnyType) { + TAIL_CALL_START: ; + DAST._IType _source0 = dafnyType; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; + if (kind0.is_Datatype) { + Dafny.ISequence _0_attributes = resolved0.dtor_attributes; + return Defs.__default.IsRcWrapped(_0_attributes); + } + } + } + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved1 = _source0.dtor_resolved; + DAST._IResolvedTypeBase kind1 = resolved1.dtor_kind; + if (kind1.is_SynonymType) { + DAST._IType _1_tpe = kind1.dtor_baseType; + Dafny.ISequence _2_attributes = resolved1.dtor_attributes; + DAST._IType _in0 = _1_tpe; + dafnyType = _in0; + goto TAIL_CALL_START; + } + } + } + { + return false; + } + } + public static bool IsRcWrapped(Dafny.ISequence attributes) { + return ((!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("auto-nongrowing-size"), Dafny.Sequence>.FromElements()))) && (!(attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("false")))))) || ((attributes).Contains(DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("rust_rc"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("true"))))); + } public static Std.Wrappers._IOption OptExtern(DAST._IAttribute attr, Dafny.ISequence dafnyName) { if (((attr).dtor_name).Equals(Dafny.Sequence.UnicodeFromString("extern"))) { @@ -497,9 +530,13 @@ public static RAST._IModDecl HashImpl(Dafny.ISequence rTyp { return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithHash, RAST.__default.Hash, datatypeOrNewtypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("hash"), Defs.__default.hash__type__parameters, Defs.__default.hash__parameters, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(hashImplBody)))))); } - public static RAST._IImplMember eq__trait(RAST._IType fullTraitPath, RAST._IExpr fullTraitExpr) + public static RAST._IImplMember hasher__trait(bool supportsEquality, Defs._IPointerType pointerType) { - return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(fullTraitPath))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some((((((((fullTraitExpr).FSel(Dafny.Sequence.UnicodeFromString("_as_any"))).Apply1(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())).Sel(Dafny.Sequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(RAST.__default.SelfOwned))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("map_or"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralBool(false), RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("x"), RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("_")))), Std.Wrappers.Option.create_None(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), DAST.Format.BinaryOpFormat.create_NoFormat()))))))); + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Std.Wrappers.Option.create_Some(((supportsEquality) ? ((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("hasher"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("DefaultHasher"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0()))).Then((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&mut"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher")), DAST.Format.UnaryOpFormat.create_NoFormat()))).Then(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher"))).Sel(Dafny.Sequence.UnicodeFromString("finish"))).Apply0()))) : (Defs.__default.UnreachablePanicIfVerified(pointerType, Dafny.Sequence.UnicodeFromString("The type does not support equality"))))))); + } + public static RAST._IImplMember eq__trait(RAST._IType fullTraitPath, RAST._IExpr fullTraitExpr, bool supportsEquality, Defs._IPointerType pointerType) + { + return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.Type.create_Borrowed(RAST.__default.Box(RAST.Type.create_DynType(fullTraitPath))))), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(((supportsEquality) ? ((((((((fullTraitExpr).FSel(Dafny.Sequence.UnicodeFromString("_as_any"))).Apply1(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0())).Sel(Dafny.Sequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(RAST.__default.SelfOwned))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("map_or"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralBool(false), RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("x"), RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("_")))), Std.Wrappers.Option.create_None(), RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("x")), DAST.Format.BinaryOpFormat.create_NoFormat()))))) : (Defs.__default.UnreachablePanicIfVerified(pointerType, Dafny.Sequence.UnicodeFromString("The type does not support equality"))))))); } public static RAST._IImplMember clone__trait(RAST._IType fullTraitPath) { return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.Box(RAST.Type.create_DynType(fullTraitPath))), Std.Wrappers.Option.create_Some(RAST.__default.BoxNew(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0())))); @@ -601,6 +638,12 @@ public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, _3_forType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_5_isBody))), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(_4_resultType), Std.Wrappers.Option.create_Some(_6_asBody))))))); } } + public static RAST._IModDecl UpcastDynTraitFor(Dafny.ISequence rTypeParamsDecls, RAST._IType forBoxedTraitType, RAST._IType superTraitType, RAST._IExpr superTraitExpr) + { + RAST._IType _0_superBoxedTraitType = RAST.__default.Box(RAST.Type.create_DynType(superTraitType)); + RAST._IExpr _1_body = ((superTraitExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastBox"))).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(superTraitType))), forBoxedTraitType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("upcast"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(_0_superBoxedTraitType), Std.Wrappers.Option.create_Some(_1_body)))))); + } public static Defs._IAssignmentStatus DetectAssignmentStatus(Dafny.ISequence stmts__remainder, Dafny.ISequence dafny__name) { Defs._IAssignmentStatus _hresult = Defs.AssignmentStatus.Default(); @@ -766,9 +809,6 @@ public static Dafny.ISequence DAFNY__EXTERN__MODULE { get { public static RAST._IExpr hash__function { get { return ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hash"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("hash")); } } - public static RAST._IImplMember hasher__trait { get { - return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_hash"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_U64()), Std.Wrappers.Option.create_Some((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("hasher"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("DefaultHasher"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0()))).Then((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("&mut"), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher")), DAST.Format.UnaryOpFormat.create_NoFormat()))).Then(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("hasher"))).Sel(Dafny.Sequence.UnicodeFromString("finish"))).Apply0()))))); - } } public static RAST._IImplMember as__any__trait { get { return RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as_any"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(RAST.Type.create_DynType(RAST.__default.AnyTrait))), Std.Wrappers.Option.create_Some(RAST.__default.self))); } } @@ -1353,6 +1393,7 @@ public interface _ISelfInfo { bool IsSelf(); bool IsGeneralTrait(); bool IsClassOrObjectTrait(); + bool IsRcWrappedDatatype(); } public abstract class SelfInfo : _ISelfInfo { public SelfInfo() { @@ -1395,6 +1436,9 @@ public bool IsGeneralTrait() { public bool IsClassOrObjectTrait() { return ((this).is_ThisTyped) && (((this).dtor_dafnyType).IsClassOrObjectTrait()); } + public bool IsRcWrappedDatatype() { + return ((this).is_ThisTyped) && (Defs.__default.IsRcWrappedDatatypeRec((this).dtor_dafnyType)); + } } public class SelfInfo_NoSelf : SelfInfo { public SelfInfo_NoSelf() : base() { diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index abf64c2df1a..af5ef590f99 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -3939,6 +3939,7 @@ impl UpcastObject for T { pub trait UpcastBox { fn upcast(&self) -> Box; } + impl UpcastBox for Rc where U: UpcastBox { @@ -3946,13 +3947,6 @@ impl UpcastBox for Rc UpcastBox::upcast(AsRef::as_ref(self)) } } -impl UpcastBox for Box - where U: UpcastBox -{ - fn upcast(&self) -> Box { - UpcastBox::upcast(AsRef::as_ref(self)) - } -} pub trait AnyRef { fn as_any_ref(&self) -> &dyn Any; diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect new file mode 100644 index 00000000000..19e90eca854 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect @@ -0,0 +1,2 @@ +Dafny program verifier finished with 1 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect new file mode 100644 index 00000000000..19e90eca854 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect @@ -0,0 +1,2 @@ +Dafny program verifier finished with 1 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy new file mode 100644 index 00000000000..39f09d84335 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy @@ -0,0 +1,25 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --type-system-refresh --general-traits=datatype "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait SuperTrait { + function toString(): string +} + +trait SubSuperTrait extends SuperTrait { +} + +method PrintTwice(k: K) { + print (k as SuperTrait).toString(); + print (k as SuperTrait).toString(); +} + +datatype TestPrintTwice extends SubSuperTrait = TestPrintTwice { + function toString(): string { "hello" } +} + +method Main() { + PrintTwice(TestPrintTwice()); + PrintTwice((TestPrintTwice() as SubSuperTrait)); + PrintTwice((TestPrintTwice() as SuperTrait)); +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect new file mode 100644 index 00000000000..fabcdc8b30a --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect @@ -0,0 +1,2 @@ +Dafny program verifier finished with 2 verified, 0 errors +hellohellohellohellohellohello \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy new file mode 100644 index 00000000000..1e99245306a --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy @@ -0,0 +1,20 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Super { + function Compare(a: T, b: T, c: bool): bool + decreases a +} + +datatype BoolOps extends Super = BoolOps { + function Compare(a: bool, b: bool, c: bool): bool { + a == b + } +} + +method Main() { + expect BoolOps().Compare(true, true, true); + expect !BoolOps().Compare(true, false, true); + print "ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect new file mode 100644 index 00000000000..19e90eca854 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect @@ -0,0 +1,2 @@ +Dafny program verifier finished with 1 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy new file mode 100644 index 00000000000..e9bb4983400 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy @@ -0,0 +1,27 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Reversible { + function reverse():(r:Reversible) +} + +trait SubReversible extends Reversible { + function reverse():(r:Reversible) +} + +datatype {:rust_rc false} Ping extends Reversible, SubReversible = Ping { + function reverse():(r:Reversible) { Pong } +} + +datatype {:rust_rc false} Pong extends Reversible, SubReversible = Pong { + function reverse():(r:Reversible) { Ping } +} + + +method Main() { + var x := Pong; + expect x.reverse() is Ping; + expect Ping().reverse() is Pong; + print "ping pong"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect new file mode 100644 index 00000000000..fb7d2d153ca --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect @@ -0,0 +1,2 @@ +Dafny program verifier finished with 3 verified, 0 errors +ping pong \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy new file mode 100644 index 00000000000..022f03db2d1 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy @@ -0,0 +1,11 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --emit-uncompilable-code "%s" > "%t" + +datatype Super = Super + +datatype Test = Test { + static const cloud := Super.Super +} + +method Main() { +} \ No newline at end of file From 7375c25a573bea9b491fa38b0702898ba626bd57 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Wed, 11 Dec 2024 00:55:44 +0100 Subject: [PATCH 24/69] More fixes --- Source/DafnyCore/Backends/Dafny/AST.dfy | 15 +- Source/DafnyCore/Backends/Dafny/ASTBuilder.cs | 10 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 37 +- .../Rust/Dafny-compiler-rust-definitions.dfy | 29 +- .../Rust/Dafny-compiler-rust-rast.dfy | 8 + .../Backends/Rust/Dafny-compiler-rust.dfy | 185 +++-- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 259 ++++++- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 726 ++++++++++-------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 4 + Source/DafnyCore/GeneratedFromDafny/RAST.cs | 15 + Source/DafnyCore/Resolver/ModuleResolver.cs | 48 +- 11 files changed, 882 insertions(+), 454 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 59d82814d60..29032d7e246 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -171,7 +171,7 @@ module {:extern "DAST"} DAST { match typeKind { case SynonymType(typ) => typ.IsDatatype() - case Datatype(_) => true + case Datatype(_, _) => true case _ => false } case _ => false @@ -210,7 +210,10 @@ module {:extern "DAST"} DAST { | Covariant | Contravariant - datatype TypeArgDecl = TypeArgDecl(name: Ident, bounds: seq, variance: Variance) + datatype TypeArgDecl = TypeArgDecl( + name: Ident, + bounds: seq, + info: TypeParameterInfo) datatype TypeArgBound = | SupportsEquality @@ -252,9 +255,14 @@ module {:extern "DAST"} DAST { | ObjectTrait() // Traits that extend objects with --type-system-refresh, all traits otherwise | GeneralTrait() // Traits that don't necessarily extend objects with --type-system-refresh + datatype TypeParameterInfo = + TypeParameterInfo(variance: Variance, necessaryForEqualitySupportOfSurroundingInductiveDatatype: bool) + + datatype EqualitySupport = Never | Always | ConsultTypeArguments + datatype ResolvedTypeBase = | Class() - | Datatype(variances: seq) + | Datatype(equalitySupport: EqualitySupport, info: seq) | Trait(traitType: TraitType) | SynonymType(baseType: Type) | Newtype(baseType: Type, range: NewtypeRange, erase: bool) @@ -314,6 +322,7 @@ module {:extern "DAST"} DAST { ctors: seq, body: seq, isCo: bool, + equalitySupport: EqualitySupport, attributes: seq, superTraitTypes: seq, superTraitNegativeTypes: seq // Traits that one or more superTraits know they can downcast to, but the datatype does not. diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index f2676a3feb6..133ddb52435 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -346,8 +346,8 @@ interface DatatypeContainer : Container { public DatatypeBuilder Datatype(string name, string enclosingModule, List typeParams, List ctors, bool isCo, ISequence<_IAttribute> attributes, string docString, - List superTraitTypes, List superNegativeTraitTypes) { - return new DatatypeBuilder(this, name, docString, enclosingModule, typeParams, ctors, isCo, attributes, superTraitTypes, superNegativeTraitTypes); + List superTraitTypes, List superNegativeTraitTypes, _IEqualitySupport equalitySupport) { + return new DatatypeBuilder(this, name, docString, enclosingModule, typeParams, ctors, isCo, attributes, superTraitTypes, superNegativeTraitTypes, equalitySupport); } } @@ -363,8 +363,9 @@ class DatatypeBuilder : ClassLike { readonly string docString; readonly List superTraitTypes; readonly List superNegativeTraitTypes; + private _IEqualitySupport equalitySupport; - public DatatypeBuilder(DatatypeContainer parent, string name, string docString, string enclosingModule, List typeParams, List ctors, bool isCo, ISequence<_IAttribute> attributes, List superTraitTypes, List superNegativeTraitTypes) { + public DatatypeBuilder(DatatypeContainer parent, string name, string docString, string enclosingModule, List typeParams, List ctors, bool isCo, ISequence<_IAttribute> attributes, List superTraitTypes, List superNegativeTraitTypes, _IEqualitySupport equalitySupport) { this.parent = parent; this.name = name; this.docString = docString; @@ -375,6 +376,7 @@ public DatatypeBuilder(DatatypeContainer parent, string name, string docString, this.attributes = attributes; this.superTraitTypes = superTraitTypes; this.superNegativeTraitTypes = superNegativeTraitTypes; + this.equalitySupport = equalitySupport; } public void AddMethod(DAST.Method item) { @@ -393,7 +395,7 @@ public object Finish() { Sequence.FromArray(typeParams.ToArray()), Sequence.FromArray(ctors.ToArray()), Sequence.FromArray(body.ToArray()), - this.isCo, attributes, + this.isCo, equalitySupport, attributes, Sequence.FromArray(superTraitTypes.ToArray()), Sequence.FromArray(superNegativeTraitTypes.ToArray()) )); diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index a78f5137bad..f00ee18b1b7 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -214,6 +214,11 @@ protected override IClassWriter CreateClass(string moduleName, string name, bool } } + private TypeParameterInfo GenTypeParameterInfo(TypeParameter tp) { + return (TypeParameterInfo)TypeParameterInfo.create_TypeParameterInfo(GenTypeVariance(tp), + tp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype); + } + private Variance GenTypeVariance(TypeParameter tp) { if (tp.Variance is TypeParameter.TPVariance.Co) { return (Variance)Variance.create_Covariant(); @@ -251,8 +256,11 @@ protected TypeArgDecl GenTypeArgDecl(TypeParameter tp, string name = null) { name ??= tp.GetCompileName(Options); + var info = TypeParameterInfo.create_TypeParameterInfo(variance, + tp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype); + return (DAST.TypeArgDecl)DAST.TypeArgDecl.create_TypeArgDecl( - Sequence.UnicodeFromString(name), bounds, variance); + Sequence.UnicodeFromString(name), bounds, info); } protected override IClassWriter CreateTrait(string name, bool isExtern, List typeParameters, @@ -413,6 +421,8 @@ from arg in ctor.Formals var superNegativeTraitTypes = GetNegativeTraitTypes(superClasses); + var equalitySupport = GenEqualitySupport(dt); + var datatypeBuilder = builder.Datatype( dt.GetCompileName(Options), dt.EnclosingModuleDefinition.GetCompileName(Options), @@ -422,8 +432,7 @@ from arg in ctor.Formals ParseAttributes(dt.Attributes), GetDocString(dt), superTraitTypes, - superNegativeTraitTypes - ); + superNegativeTraitTypes, equalitySupport); return new ClassWriter(this, typeParams.Count > 0, datatypeBuilder); } else { @@ -774,11 +783,6 @@ public ConcreteSyntaxTree CreateFunction(string name, ListStatic fields with type arguments"); - return new BuilderSyntaxTree(new StatementBuffer(), this.compiler); - } - var overridingTrait = compiler.GetTopMostOverriddenMemberDeclIfDifferent(member)?.EnclosingClass; var attributes = compiler.ParseAttributes(enclosingDecl.Attributes); @@ -1954,8 +1958,10 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type : TraitType.create_GeneralTrait(); resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Trait(traitType); } else if (topLevel is DatatypeDecl dd) { - var variances = Sequence.FromArray(dd.TypeArgs.Select(GenTypeVariance).ToArray()); - resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Datatype(variances); + var infos = Sequence.FromArray(dd.TypeArgs.Select(GenTypeParameterInfo).ToArray()); + var equalitySupport = GenEqualitySupport(dd); + resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Datatype( + equalitySupport, infos); } else if (topLevel is ClassDecl) { resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Class(); } else { @@ -1970,6 +1976,17 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type return baseType; } + private static _IEqualitySupport GenEqualitySupport(DatatypeDecl dd) + { + return dd is IndDatatypeDecl indDecl ? + indDecl.EqualitySupport == IndDatatypeDecl.ES.Never ? + EqualitySupport.create_Never() : + indDecl.EqualitySupport == IndDatatypeDecl.ES.ConsultTypeArguments ? + EqualitySupport.create_ConsultTypeArguments() : + EqualitySupport.create_Never() : + EqualitySupport.create_Never(); + } + private static Type EraseNewtypeLayers(TopLevelDecl topLevel) { var topLevelType = UserDefinedType.FromTopLevelDecl(topLevel.tok, topLevel); return topLevelType.NormalizeToAncestorType(); diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 5f90b65f073..6078aa06a8e 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -304,7 +304,7 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { predicate IsRcWrappedDatatypeRec(dafnyType: Type) { match dafnyType { - case UserDefined(ResolvedType(_, _, Datatype(_), attributes, _, _)) => + case UserDefined(ResolvedType(_, _, Datatype(_, _), attributes, _, _)) => IsRcWrapped(attributes) case UserDefined(ResolvedType(_, _, SynonymType(tpe), attributes, _, _)) => IsRcWrappedDatatypeRec(tpe) @@ -618,6 +618,33 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { )) } + function EqImpl(rTypeParamsDeclsWithEq: seq, datatypeType: R.Type, rTypeParams: seq, eqImplBody: R.Expr): seq { + [ R.ImplDecl( + R.ImplFor( + rTypeParamsDeclsWithEq, + R.PartialEq, + datatypeType, + [ R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn( + "eq", + [], + [R.Formal.selfBorrowed, R.Formal("other", R.SelfBorrowed)], + Some(R.Bool), + Some(eqImplBody) + ) + )])), + R.ImplDecl( + R.ImplFor( + rTypeParamsDeclsWithEq, + R.Eq, + datatypeType, + [] + ) + ) + ] + } + function CoerceImpl( rTypeParamsDecls: seq, datatypeName: string, diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index 16affcf6e1a..e9504001787 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -1156,6 +1156,7 @@ module RAST const DafnyTypeEq := dafny_runtime.MSel("DafnyTypeEq").AsType() const Eq := std.MSel("cmp").MSel("Eq").AsType() const Hash := std.MSel("hash").MSel("Hash").AsType() + const PartialEq := std.MSel("cmp").MSel("PartialEq").AsType() const DafnyInt := dafny_runtime.MSel("DafnyInt").AsType() function SystemTuple(elements: seq): Expr { @@ -1872,6 +1873,13 @@ module RAST assert r.RawExpr?; AddIndent(r.content, ind) } } + function And(rhs2: Expr): Expr { + if this == LiteralBool(true) then rhs2 else + BinaryOp("&&", this, rhs2, Format.BinaryOpFormat.NoFormat) + } + function Equals(rhs2: Expr): Expr { + BinaryOp("==", this, rhs2, Format.BinaryOpFormat.NoFormat) + } function Then(rhs2: Expr): Expr { if this.StmtExpr? then StmtExpr(stmt, rhs.Then(rhs2)) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 405d0a7d516..79deda552c8 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -969,12 +969,23 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - predicate TypeIsEq(t: Type, typeParametersSupportingEquality: set) // TODO: Take into account enclosing type parameters + // Figure out if the type is always extending Eq + predicate TypeIsEq(t: Type, typeParametersSupportingEquality: set) decreases t { match t case UserDefined(ResolvedType(_, _, SynonymType(tpe), _, _, _)) => TypeIsEq(tpe, typeParametersSupportingEquality) - case UserDefined(_) => true // ResolvedTypes are assumed to support equality + case UserDefined(ResolvedType(_, _, Class(), _, _, _)) => true + case UserDefined(ResolvedType(_, _, Trait(GeneralTrait), _, _, _)) => false + case UserDefined(ResolvedType(_, _, Trait(ObjectTrait), _, _, _)) => true + case UserDefined(ResolvedType(_, _, Newtype(tpe, _, _), _, _, _)) => TypeIsEq(tpe, typeParametersSupportingEquality) + case UserDefined(ResolvedType(_, typeParams, Datatype(equalitySupport, tps), _, _, _)) => + !equalitySupport.Never? && + (equalitySupport.Always? || + (&& equalitySupport.ConsultTypeArguments? + && |tps| == |typeParams| + && forall i | 0 <= i < |tps| :: + (tps[i].necessaryForEqualitySupportOfSurroundingInductiveDatatype ==> TypeIsEq(typeParams[i], typeParametersSupportingEquality)))) case Tuple(ts) => forall t <- ts :: TypeIsEq(t, typeParametersSupportingEquality) case Array(t, _) => true // Reference equality case Seq(t) => TypeIsEq(t, typeParametersSupportingEquality) @@ -990,6 +1001,27 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case Object() => true } + function Combine(s: seq>>): Option> { + if |s| == 0 then Some({}) else + var idents :- s[|s|-1]; + var remaining_idents :- Combine(s[0..|s|-1]); + Some(idents + remaining_idents) + } by method { + if |s| == 0 { + return Some({}); + } + var result := {}; + for i := 0 to |s| + invariant Some(result) == Combine(s[0..i]) + { + if s[i].None? { + return None; + } + result := result + s[i].value; + } + return Some(result); + } + predicate DatatypeIsEq(c: Datatype, typeParametersSupportingEquality: set) { !c.isCo && forall ctor <- c.ctors, arg <- ctor.args :: TypeIsEq(arg.formal.typ, typeParametersSupportingEquality) } @@ -1016,7 +1048,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var typeParamsSeq, rTypeParams, rTypeParamsDecls := GenTypeParameters(c.typeParams); var datatypeName, extern := GetName(c.attributes, c.name, "datatypes"); var ctors: seq := []; - var variances := Std.Collections.Seq.Map((typeParamDecl: TypeArgDecl) => typeParamDecl.variance, c.typeParams); + var typeParamInfos := Std.Collections.Seq.Map((typeParamDecl: TypeArgDecl) => typeParamDecl.info, c.typeParams); var singletonConstructors := []; var usedTypeParams: set := {}; for i := 0 to |c.ctors| { @@ -1071,7 +1103,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ResolvedType( selfPath, typeParamsSeq, - ResolvedTypeBase.Datatype(variances), + ResolvedTypeBase.Datatype(c.equalitySupport, typeParamInfos), c.attributes, [], [])), typeParamsSeq); var implBody: seq := implBodyRaw; @@ -1172,7 +1204,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var rTypeArg := GenType(typeArg, GenTypeContext.default()); types := types + [R.TypeApp(R.std.MSel("marker").MSel("PhantomData").AsType(), [rTypeArg])]; // Coercion arguments - if typeI < |variances| && variances[typeI].Nonvariant? { + if typeI < |typeParamInfos| && typeParamInfos[typeI].variance.Nonvariant? { coerceTypes := coerceTypes + [rTypeArg]; continue; // We ignore nonvariant arguments } @@ -1206,7 +1238,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var typeParametersSupportingEquality: set := set tp <- c.typeParams | SupportsEquality in tp.bounds :: tp.name; - var cIsEq := DatatypeIsEq(c, typeParametersSupportingEquality); + var cIsAlwaysEq := DatatypeIsEq(c, typeParametersSupportingEquality); var datatypeType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); // Derive PartialEq when c supports equality / derive Clone in all cases @@ -1214,10 +1246,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { [R.EnumDecl( R.Enum( c.docString, - if cIsEq then - [R.RawAttribute("#[derive(PartialEq, Clone)]")] - else - [R.RawAttribute("#[derive(Clone)]")], + [R.RawAttribute("#[derive(Clone)]")], datatypeName, rTypeParamsDecls, ctors @@ -1271,6 +1300,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var printImplBodyCases: seq := []; var hashImplBodyCases: seq := []; var coerceImplBodyCases: seq := []; + var partialEqImplBodyCases: seq := []; for i := 0 to |c.ctors| { var ctor := c.ctors[i]; @@ -1283,10 +1313,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var printRhs := writeStr(ctorName + (if ctor.hasAnyArgs then "(" else "")); var hashRhs := InitEmptyExpr(); + var partialEqRhs := R.LiteralBool(true); var coerceRhsArgs := []; var isNumeric := false; var ctorMatchInner := ""; + var ctorMatchInner2 := ""; for j := 0 to |ctor.args| { var dtor := ctor.args[j]; var patternName := escapeVar(dtor.formal.name); @@ -1304,6 +1336,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { hashRhs.Then(hash_function.Apply([R.Identifier(patternName), R.Identifier("_state")])); ctorMatchInner := ctorMatchInner + patternName + ", "; + ctorMatchInner2 := ctorMatchInner2 + patternName + ": " + "_2_" + patternName + ", "; + partialEqRhs := + if formalType.Arrow? then + partialEqRhs.And(R.LiteralBool(false)) // No equality support for arrow + else + partialEqRhs.And(R.Identifier(patternName).Equals(R.Identifier("_2_"+patternName))); if (j > 0) { printRhs := printRhs.Then(writeStr(", ")); @@ -1313,13 +1351,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if formalType.Arrow? then writeStr("") else - R.UnaryOp("?", - R.dafny_runtime.MSel("DafnyPrint").AsExpr().FSel("fmt_print").Apply( - [ - R.Identifier(patternName), - R.Identifier("_formatter"), - R.LiteralBool(false) - ]), Format.UnaryOpFormat.NoFormat) + R.UnaryOp( + "?", + R.dafny_runtime.MSel("DafnyPrint").AsExpr().FSel("fmt_print").Apply( + [ + R.Identifier(patternName), + R.Identifier("_formatter"), + R.LiteralBool(false) + ]), Format.UnaryOpFormat.NoFormat) ); var coerceRhsArg: R.Expr; @@ -1344,11 +1383,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var coerceRhs := R.StructBuild(R.Identifier(datatypeName).FSel(escapeName(ctor.name)), coerceRhsArgs); - + var pattern, pattern2; if isNumeric { - ctorMatch := ctorMatch + "(" + ctorMatchInner + ")"; + pattern := ctorMatch + "(" + ctorMatchInner + ")"; + pattern2 := ctorMatch + "(" + ctorMatchInner2 + ")"; } else { - ctorMatch := ctorMatch + "{" + ctorMatchInner + "}"; + pattern := ctorMatch + "{" + ctorMatchInner + "}"; + pattern2 := ctorMatch + "{" + ctorMatchInner2 + "}"; } if (ctor.hasAnyArgs) { @@ -1358,18 +1399,27 @@ module {:extern "DCOMP"} DafnyToRustCompiler { printRhs := printRhs.Then(R.Identifier("Ok").Apply([R.Tuple([])])); printImplBodyCases := printImplBodyCases + [ - R.MatchCase(R.RawPattern(datatypeName + "::" + ctorMatch), + R.MatchCase(R.RawPattern(datatypeName + "::" + pattern), R.Block(printRhs)) ]; hashImplBodyCases := hashImplBodyCases + [ - R.MatchCase(R.RawPattern(datatypeName + "::" + ctorMatch), + R.MatchCase(R.RawPattern(datatypeName + "::" + pattern), R.Block(hashRhs)) ]; + partialEqImplBodyCases := partialEqImplBodyCases + [ + R.MatchCase(R.RawPattern("(" + datatypeName + "::" + pattern + ", " + datatypeName + "::" + pattern2 + ")"), + R.Block(partialEqRhs)) + ]; coerceImplBodyCases := coerceImplBodyCases + [ R.MatchCase(R.RawPattern(datatypeName + "::" + ctorMatch), R.Block(coerceRhs)) ]; } + partialEqImplBodyCases := partialEqImplBodyCases + [ + R.MatchCase( + R.RawPattern("_"), + R.Block(R.LiteralBool(false))) + ]; if |c.typeParams| > 0 && |unusedTypeParams| > 0 { var extraCases := [ @@ -1384,12 +1434,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var defaultConstrainedTypeParams := R.TypeParamDecl.AddConstraintsMultiple( rTypeParamsDecls, [R.DefaultTrait] ); - var rTypeParamsDeclsWithEq := R.TypeParamDecl.AddConstraintsMultiple( - rTypeParamsDecls, [R.Eq] - ); - var rTypeParamsDeclsWithHash := R.TypeParamDecl.AddConstraintsMultiple( - rTypeParamsDecls, [R.Hash] - ); var printImplBody := R.Match( R.self, printImplBodyCases); @@ -1397,6 +1441,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.self, hashImplBodyCases ); + var eqImplBody := R.Match( + R.Tuple([R.self, R.Identifier("other")]), + partialEqImplBodyCases + ); // Implementation of Debug and Print traits s := s + [ @@ -1422,26 +1470,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { SingletonsImpl(rTypeParamsDecls, datatypeType, instantiationType, singletonConstructors)]; } - // Implementation of Eq when c supports equality - if cIsEq { + if c.equalitySupport.Always? || c.equalitySupport.ConsultTypeArguments? { + var rTypeParamsDeclsWithEq := rTypeParamsDecls; + var rTypeParamsDeclsWithHash := rTypeParamsDecls; + if c.equalitySupport.ConsultTypeArguments? { + for i := 0 to |rTypeParamsDecls| { + if c.typeParams[i].info.necessaryForEqualitySupportOfSurroundingInductiveDatatype { + rTypeParamsDeclsWithEq := rTypeParamsDeclsWithEq[i := rTypeParamsDeclsWithEq[i].AddConstraints([R.Eq, R.Hash])]; + rTypeParamsDeclsWithHash := rTypeParamsDeclsWithHash[i := rTypeParamsDeclsWithHash[i].AddConstraints([R.Hash])]; + } + } + } + s := s + EqImpl(rTypeParamsDeclsWithEq, datatypeType, rTypeParams, eqImplBody); + // Implementation of Hash trait s := s + [ - R.ImplDecl( - R.ImplFor( - rTypeParamsDeclsWithEq, - R.Eq, - R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), - [] - ) - )]; + HashImpl( + rTypeParamsDeclsWithHash, + datatypeType, + hashImplBody)]; } - // Implementation of Hash trait - s := s + [ - HashImpl( - rTypeParamsDeclsWithHash, - R.TypeApp(R.TIdentifier(datatypeName), rTypeParams), - hashImplBody)]; - if |c.ctors| > 0 { var structName := R.Identifier(datatypeName).FSel(escapeName(c.ctors[0].name)); var structAssignments: seq := []; @@ -1453,10 +1501,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.std.MSel("default").MSel("Default").AsExpr().FSel("default").Apply0()) ]; } - var fullType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); // Implementation of Default trait when c supports equality - if false && cIsEq { // We don't emit default because datatype defaults are broken. + if false && cIsAlwaysEq { // We don't emit default because datatype defaults are broken. // - There should be no default when an argument is a lambda // - There is no possiblity to define witness for datatypes so that we know if it's (0) or (00) // - General traits don't have defaults but can be wrapped in datatypes and datatypes are assumed to have default values always @@ -1466,7 +1513,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := s + [ DefaultDatatypeImpl( rTypeParamsDecls, - fullType, + datatypeType, structName, structAssignments)]; } @@ -1475,7 +1522,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { s := s + [ AsRefDatatypeImpl( rTypeParamsDecls, - fullType + datatypeType )]; } var superTraitImplementations := GenTraitImplementations( @@ -1485,7 +1532,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { c.superTraitTypes, traitBodies, extern, - cIsEq, + cIsAlwaysEq, "datatype"); s := s + superTraitImplementations; } @@ -1570,7 +1617,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { case Class() => { s := Object(s); } - case Datatype(_) => { + case Datatype(_, _) => { if IsRcWrapped(resolved.attributes) { s := R.Rc(s); } @@ -3039,25 +3086,27 @@ module {:extern "DCOMP"} DafnyToRustCompiler { else if SameTypesButDifferentTypeParameters(fromType, fromTpe, toType, toTpe) then var indices := if fromType.UserDefined? && fromType.resolved.kind.Datatype? then - Std.Collections.Seq.Filter(i => - if 0 <= i < |fromTpe.arguments| then - (0 <= i < |fromType.resolved.kind.variances| ==> - !fromType.resolved.kind.variances[i].Nonvariant?) - else - false - , seq(|fromTpe.arguments|, i => i)) + Std.Collections.Seq.Filter( + i => + if 0 <= i < |fromTpe.arguments| then + (0 <= i < |fromType.resolved.kind.info| ==> + !fromType.resolved.kind.info[i].variance.Nonvariant?) + else + false + , seq(|fromTpe.arguments|, i => i)) else seq(|fromTpe.arguments|, i => i); - var lambdas :- SeqResultToResultSeq( - seq(|indices|, j requires 0 <= j < |indices| => - var i := indices[j]; - UpcastConversionLambda( - fromType.resolved.typeArgs[i], - fromTpe.arguments[i], - toType.resolved.typeArgs[i], - toTpe.arguments[i], - typeParams - ))); + var lambdas :- + SeqResultToResultSeq( + seq(|indices|, j requires 0 <= j < |indices| => + var i := indices[j]; + UpcastConversionLambda( + fromType.resolved.typeArgs[i], + fromTpe.arguments[i], + toType.resolved.typeArgs[i], + toTpe.arguments[i], + typeParams + ))); Success(R.ExprFromType(fromTpe.baseName).ApplyType( seq(|fromTpe.arguments|, i requires 0 <= i < |fromTpe.arguments| => fromTpe.arguments[i]) diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 5f9800ed607..6c1772d92bd 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -1464,32 +1464,32 @@ public interface _ITypeArgDecl { bool is_TypeArgDecl { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_bounds { get; } - DAST._IVariance dtor_variance { get; } + DAST._ITypeParameterInfo dtor_info { get; } _ITypeArgDecl DowncastClone(); } public class TypeArgDecl : _ITypeArgDecl { public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _bounds; - public readonly DAST._IVariance _variance; - public TypeArgDecl(Dafny.ISequence name, Dafny.ISequence bounds, DAST._IVariance variance) { + public readonly DAST._ITypeParameterInfo _info; + public TypeArgDecl(Dafny.ISequence name, Dafny.ISequence bounds, DAST._ITypeParameterInfo info) { this._name = name; this._bounds = bounds; - this._variance = variance; + this._info = info; } public _ITypeArgDecl DowncastClone() { if (this is _ITypeArgDecl dt) { return dt; } - return new TypeArgDecl(_name, _bounds, _variance); + return new TypeArgDecl(_name, _bounds, _info); } public override bool Equals(object other) { var oth = other as DAST.TypeArgDecl; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._bounds, oth._bounds) && object.Equals(this._variance, oth._variance); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._bounds, oth._bounds) && object.Equals(this._info, oth._info); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._bounds)); - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._variance)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._info)); return (int) hash; } public override string ToString() { @@ -1499,11 +1499,11 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._bounds); s += ", "; - s += Dafny.Helpers.ToString(this._variance); + s += Dafny.Helpers.ToString(this._info); s += ")"; return s; } - private static readonly DAST._ITypeArgDecl theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.Variance.Default()); + private static readonly DAST._ITypeArgDecl theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.TypeParameterInfo.Default()); public static DAST._ITypeArgDecl Default() { return theDefault; } @@ -1511,11 +1511,11 @@ public static DAST._ITypeArgDecl Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITypeArgDecl create(Dafny.ISequence name, Dafny.ISequence bounds, DAST._IVariance variance) { - return new TypeArgDecl(name, bounds, variance); + public static _ITypeArgDecl create(Dafny.ISequence name, Dafny.ISequence bounds, DAST._ITypeParameterInfo info) { + return new TypeArgDecl(name, bounds, info); } - public static _ITypeArgDecl create_TypeArgDecl(Dafny.ISequence name, Dafny.ISequence bounds, DAST._IVariance variance) { - return create(name, bounds, variance); + public static _ITypeArgDecl create_TypeArgDecl(Dafny.ISequence name, Dafny.ISequence bounds, DAST._ITypeParameterInfo info) { + return create(name, bounds, info); } public bool is_TypeArgDecl { get { return true; } } public Dafny.ISequence dtor_name { @@ -1528,9 +1528,9 @@ public Dafny.ISequence dtor_bounds { return this._bounds; } } - public DAST._IVariance dtor_variance { + public DAST._ITypeParameterInfo dtor_info { get { - return this._variance; + return this._info; } } } @@ -2505,13 +2505,180 @@ public override string ToString() { } } + public interface _ITypeParameterInfo { + bool is_TypeParameterInfo { get; } + DAST._IVariance dtor_variance { get; } + bool dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype { get; } + _ITypeParameterInfo DowncastClone(); + } + public class TypeParameterInfo : _ITypeParameterInfo { + public readonly DAST._IVariance _variance; + public readonly bool _necessaryForEqualitySupportOfSurroundingInductiveDatatype; + public TypeParameterInfo(DAST._IVariance variance, bool necessaryForEqualitySupportOfSurroundingInductiveDatatype) { + this._variance = variance; + this._necessaryForEqualitySupportOfSurroundingInductiveDatatype = necessaryForEqualitySupportOfSurroundingInductiveDatatype; + } + public _ITypeParameterInfo DowncastClone() { + if (this is _ITypeParameterInfo dt) { return dt; } + return new TypeParameterInfo(_variance, _necessaryForEqualitySupportOfSurroundingInductiveDatatype); + } + public override bool Equals(object other) { + var oth = other as DAST.TypeParameterInfo; + return oth != null && object.Equals(this._variance, oth._variance) && this._necessaryForEqualitySupportOfSurroundingInductiveDatatype == oth._necessaryForEqualitySupportOfSurroundingInductiveDatatype; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._variance)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._necessaryForEqualitySupportOfSurroundingInductiveDatatype)); + return (int) hash; + } + public override string ToString() { + string s = "DAST.TypeParameterInfo.TypeParameterInfo"; + s += "("; + s += Dafny.Helpers.ToString(this._variance); + s += ", "; + s += Dafny.Helpers.ToString(this._necessaryForEqualitySupportOfSurroundingInductiveDatatype); + s += ")"; + return s; + } + private static readonly DAST._ITypeParameterInfo theDefault = create(DAST.Variance.Default(), false); + public static DAST._ITypeParameterInfo Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.TypeParameterInfo.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _ITypeParameterInfo create(DAST._IVariance variance, bool necessaryForEqualitySupportOfSurroundingInductiveDatatype) { + return new TypeParameterInfo(variance, necessaryForEqualitySupportOfSurroundingInductiveDatatype); + } + public static _ITypeParameterInfo create_TypeParameterInfo(DAST._IVariance variance, bool necessaryForEqualitySupportOfSurroundingInductiveDatatype) { + return create(variance, necessaryForEqualitySupportOfSurroundingInductiveDatatype); + } + public bool is_TypeParameterInfo { get { return true; } } + public DAST._IVariance dtor_variance { + get { + return this._variance; + } + } + public bool dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype { + get { + return this._necessaryForEqualitySupportOfSurroundingInductiveDatatype; + } + } + } + + public interface _IEqualitySupport { + bool is_Never { get; } + bool is_Always { get; } + bool is_ConsultTypeArguments { get; } + _IEqualitySupport DowncastClone(); + } + public abstract class EqualitySupport : _IEqualitySupport { + public EqualitySupport() { + } + private static readonly DAST._IEqualitySupport theDefault = create_Never(); + public static DAST._IEqualitySupport Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(DAST.EqualitySupport.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _IEqualitySupport create_Never() { + return new EqualitySupport_Never(); + } + public static _IEqualitySupport create_Always() { + return new EqualitySupport_Always(); + } + public static _IEqualitySupport create_ConsultTypeArguments() { + return new EqualitySupport_ConsultTypeArguments(); + } + public bool is_Never { get { return this is EqualitySupport_Never; } } + public bool is_Always { get { return this is EqualitySupport_Always; } } + public bool is_ConsultTypeArguments { get { return this is EqualitySupport_ConsultTypeArguments; } } + public static System.Collections.Generic.IEnumerable<_IEqualitySupport> AllSingletonConstructors { + get { + yield return EqualitySupport.create_Never(); + yield return EqualitySupport.create_Always(); + yield return EqualitySupport.create_ConsultTypeArguments(); + } + } + public abstract _IEqualitySupport DowncastClone(); + } + public class EqualitySupport_Never : EqualitySupport { + public EqualitySupport_Never() : base() { + } + public override _IEqualitySupport DowncastClone() { + if (this is _IEqualitySupport dt) { return dt; } + return new EqualitySupport_Never(); + } + public override bool Equals(object other) { + var oth = other as DAST.EqualitySupport_Never; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + return (int) hash; + } + public override string ToString() { + string s = "DAST.EqualitySupport.Never"; + return s; + } + } + public class EqualitySupport_Always : EqualitySupport { + public EqualitySupport_Always() : base() { + } + public override _IEqualitySupport DowncastClone() { + if (this is _IEqualitySupport dt) { return dt; } + return new EqualitySupport_Always(); + } + public override bool Equals(object other) { + var oth = other as DAST.EqualitySupport_Always; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + return (int) hash; + } + public override string ToString() { + string s = "DAST.EqualitySupport.Always"; + return s; + } + } + public class EqualitySupport_ConsultTypeArguments : EqualitySupport { + public EqualitySupport_ConsultTypeArguments() : base() { + } + public override _IEqualitySupport DowncastClone() { + if (this is _IEqualitySupport dt) { return dt; } + return new EqualitySupport_ConsultTypeArguments(); + } + public override bool Equals(object other) { + var oth = other as DAST.EqualitySupport_ConsultTypeArguments; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 2; + return (int) hash; + } + public override string ToString() { + string s = "DAST.EqualitySupport.ConsultTypeArguments"; + return s; + } + } + public interface _IResolvedTypeBase { bool is_Class { get; } bool is_Datatype { get; } bool is_Trait { get; } bool is_SynonymType { get; } bool is_Newtype { get; } - Dafny.ISequence dtor_variances { get; } + DAST._IEqualitySupport dtor_equalitySupport { get; } + Dafny.ISequence dtor_info { get; } DAST._ITraitType dtor_traitType { get; } DAST._IType dtor_baseType { get; } DAST._INewtypeRange dtor_range { get; } @@ -2532,8 +2699,8 @@ public static DAST._IResolvedTypeBase Default() { public static _IResolvedTypeBase create_Class() { return new ResolvedTypeBase_Class(); } - public static _IResolvedTypeBase create_Datatype(Dafny.ISequence variances) { - return new ResolvedTypeBase_Datatype(variances); + public static _IResolvedTypeBase create_Datatype(DAST._IEqualitySupport equalitySupport, Dafny.ISequence info) { + return new ResolvedTypeBase_Datatype(equalitySupport, info); } public static _IResolvedTypeBase create_Trait(DAST._ITraitType traitType) { return new ResolvedTypeBase_Trait(traitType); @@ -2549,10 +2716,16 @@ public static _IResolvedTypeBase create_Newtype(DAST._IType baseType, DAST._INew public bool is_Trait { get { return this is ResolvedTypeBase_Trait; } } public bool is_SynonymType { get { return this is ResolvedTypeBase_SynonymType; } } public bool is_Newtype { get { return this is ResolvedTypeBase_Newtype; } } - public Dafny.ISequence dtor_variances { + public DAST._IEqualitySupport dtor_equalitySupport { get { var d = this; - return ((ResolvedTypeBase_Datatype)d)._variances; + return ((ResolvedTypeBase_Datatype)d)._equalitySupport; + } + } + public Dafny.ISequence dtor_info { + get { + var d = this; + return ((ResolvedTypeBase_Datatype)d)._info; } } public DAST._ITraitType dtor_traitType { @@ -2604,28 +2777,33 @@ public override string ToString() { } } public class ResolvedTypeBase_Datatype : ResolvedTypeBase { - public readonly Dafny.ISequence _variances; - public ResolvedTypeBase_Datatype(Dafny.ISequence variances) : base() { - this._variances = variances; + public readonly DAST._IEqualitySupport _equalitySupport; + public readonly Dafny.ISequence _info; + public ResolvedTypeBase_Datatype(DAST._IEqualitySupport equalitySupport, Dafny.ISequence info) : base() { + this._equalitySupport = equalitySupport; + this._info = info; } public override _IResolvedTypeBase DowncastClone() { if (this is _IResolvedTypeBase dt) { return dt; } - return new ResolvedTypeBase_Datatype(_variances); + return new ResolvedTypeBase_Datatype(_equalitySupport, _info); } public override bool Equals(object other) { var oth = other as DAST.ResolvedTypeBase_Datatype; - return oth != null && object.Equals(this._variances, oth._variances); + return oth != null && object.Equals(this._equalitySupport, oth._equalitySupport) && object.Equals(this._info, oth._info); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 1; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._variances)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._equalitySupport)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._info)); return (int) hash; } public override string ToString() { string s = "DAST.ResolvedTypeBase.Datatype"; s += "("; - s += Dafny.Helpers.ToString(this._variances); + s += Dafny.Helpers.ToString(this._equalitySupport); + s += ", "; + s += Dafny.Helpers.ToString(this._info); s += ")"; return s; } @@ -3171,6 +3349,7 @@ public interface _IDatatype { Dafny.ISequence dtor_ctors { get; } Dafny.ISequence dtor_body { get; } bool dtor_isCo { get; } + DAST._IEqualitySupport dtor_equalitySupport { get; } Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_superTraitTypes { get; } Dafny.ISequence dtor_superTraitNegativeTypes { get; } @@ -3184,10 +3363,11 @@ public class Datatype : _IDatatype { public readonly Dafny.ISequence _ctors; public readonly Dafny.ISequence _body; public readonly bool _isCo; + public readonly DAST._IEqualitySupport _equalitySupport; public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _superTraitTypes; public readonly Dafny.ISequence _superTraitNegativeTypes; - public Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { + public Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { this._name = name; this._docString = docString; this._enclosingModule = enclosingModule; @@ -3195,17 +3375,18 @@ public Datatype(Dafny.ISequence name, Dafny.ISequence do this._ctors = ctors; this._body = body; this._isCo = isCo; + this._equalitySupport = equalitySupport; this._attributes = attributes; this._superTraitTypes = superTraitTypes; this._superTraitNegativeTypes = superTraitNegativeTypes; } public _IDatatype DowncastClone() { if (this is _IDatatype dt) { return dt; } - return new Datatype(_name, _docString, _enclosingModule, _typeParams, _ctors, _body, _isCo, _attributes, _superTraitTypes, _superTraitNegativeTypes); + return new Datatype(_name, _docString, _enclosingModule, _typeParams, _ctors, _body, _isCo, _equalitySupport, _attributes, _superTraitTypes, _superTraitNegativeTypes); } public override bool Equals(object other) { var oth = other as DAST.Datatype; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._ctors, oth._ctors) && object.Equals(this._body, oth._body) && this._isCo == oth._isCo && object.Equals(this._attributes, oth._attributes) && object.Equals(this._superTraitTypes, oth._superTraitTypes) && object.Equals(this._superTraitNegativeTypes, oth._superTraitNegativeTypes); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._enclosingModule, oth._enclosingModule) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._ctors, oth._ctors) && object.Equals(this._body, oth._body) && this._isCo == oth._isCo && object.Equals(this._equalitySupport, oth._equalitySupport) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._superTraitTypes, oth._superTraitTypes) && object.Equals(this._superTraitNegativeTypes, oth._superTraitNegativeTypes); } public override int GetHashCode() { ulong hash = 5381; @@ -3217,6 +3398,7 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._ctors)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._body)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._isCo)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._equalitySupport)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._superTraitTypes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._superTraitNegativeTypes)); @@ -3239,6 +3421,8 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._isCo); s += ", "; + s += Dafny.Helpers.ToString(this._equalitySupport); + s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ", "; s += Dafny.Helpers.ToString(this._superTraitTypes); @@ -3247,7 +3431,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly DAST._IDatatype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, false, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly DAST._IDatatype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, false, DAST.EqualitySupport.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static DAST._IDatatype Default() { return theDefault; } @@ -3255,11 +3439,11 @@ public static DAST._IDatatype Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IDatatype create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { - return new Datatype(name, docString, enclosingModule, typeParams, ctors, body, isCo, attributes, superTraitTypes, superTraitNegativeTypes); + public static _IDatatype create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { + return new Datatype(name, docString, enclosingModule, typeParams, ctors, body, isCo, equalitySupport, attributes, superTraitTypes, superTraitNegativeTypes); } - public static _IDatatype create_Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { - return create(name, docString, enclosingModule, typeParams, ctors, body, isCo, attributes, superTraitTypes, superTraitNegativeTypes); + public static _IDatatype create_Datatype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence enclosingModule, Dafny.ISequence typeParams, Dafny.ISequence ctors, Dafny.ISequence body, bool isCo, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence superTraitTypes, Dafny.ISequence superTraitNegativeTypes) { + return create(name, docString, enclosingModule, typeParams, ctors, body, isCo, equalitySupport, attributes, superTraitTypes, superTraitNegativeTypes); } public bool is_Datatype { get { return true; } } public Dafny.ISequence dtor_name { @@ -3297,6 +3481,11 @@ public bool dtor_isCo { return this._isCo; } } + public DAST._IEqualitySupport dtor_equalitySupport { + get { + return this._equalitySupport; + } + } public Dafny.ISequence dtor_attributes { get { return this._attributes; diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 87cdd6596c5..a8b60ba045f 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -891,60 +891,113 @@ public bool TypeIsEq(DAST._IType t, Dafny.ISet> type } { if (_source0.is_UserDefined) { - return true; + DAST._IResolvedType resolved1 = _source0.dtor_resolved; + DAST._IResolvedTypeBase kind1 = resolved1.dtor_kind; + if (kind1.is_Class) { + return true; + } + } + } + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved2 = _source0.dtor_resolved; + DAST._IResolvedTypeBase kind2 = resolved2.dtor_kind; + if (kind2.is_Trait) { + DAST._ITraitType traitType0 = kind2.dtor_traitType; + if (traitType0.is_GeneralTrait) { + return false; + } + } + } + } + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved3 = _source0.dtor_resolved; + DAST._IResolvedTypeBase kind3 = resolved3.dtor_kind; + if (kind3.is_Trait) { + DAST._ITraitType traitType1 = kind3.dtor_traitType; + if (traitType1.is_ObjectTrait) { + return true; + } + } + } + } + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved4 = _source0.dtor_resolved; + DAST._IResolvedTypeBase kind4 = resolved4.dtor_kind; + if (kind4.is_Newtype) { + DAST._IType _1_tpe = kind4.dtor_baseType; + return (this).TypeIsEq(_1_tpe, typeParametersSupportingEquality); + } + } + } + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved5 = _source0.dtor_resolved; + Dafny.ISequence _2_typeParams = resolved5.dtor_typeArgs; + DAST._IResolvedTypeBase kind5 = resolved5.dtor_kind; + if (kind5.is_Datatype) { + DAST._IEqualitySupport _3_equalitySupport = kind5.dtor_equalitySupport; + Dafny.ISequence _4_tps = kind5.dtor_info; + return (!((_3_equalitySupport).is_Never)) && (((_3_equalitySupport).is_Always) || ((((_3_equalitySupport).is_ConsultTypeArguments) && ((new BigInteger((_4_tps).Count)) == (new BigInteger((_2_typeParams).Count)))) && (Dafny.Helpers.Id, Dafny.ISequence, Dafny.ISet>, bool>>((_5_tps, _6_typeParams, _7_typeParametersSupportingEquality) => Dafny.Helpers.Quantifier(Dafny.Helpers.IntegerRange(BigInteger.Zero, new BigInteger((_5_tps).Count)), true, (((_forall_var_0) => { + BigInteger _8_i = (BigInteger)_forall_var_0; + return !(((_8_i).Sign != -1) && ((_8_i) < (new BigInteger((_5_tps).Count)))) || (!(((_5_tps).Select(_8_i)).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype) || ((this).TypeIsEq((_6_typeParams).Select(_8_i), _7_typeParametersSupportingEquality))); + }))))(_4_tps, _2_typeParams, typeParametersSupportingEquality)))); + } } } { if (_source0.is_Tuple) { - Dafny.ISequence _1_ts = _source0.dtor_Tuple_a0; - return Dafny.Helpers.Id, Dafny.ISet>, bool>>((_2_ts, _3_typeParametersSupportingEquality) => Dafny.Helpers.Quantifier((_2_ts).UniqueElements, true, (((_forall_var_0) => { - DAST._IType _4_t = (DAST._IType)_forall_var_0; - return !((_2_ts).Contains(_4_t)) || ((this).TypeIsEq(_4_t, _3_typeParametersSupportingEquality)); - }))))(_1_ts, typeParametersSupportingEquality); + Dafny.ISequence _9_ts = _source0.dtor_Tuple_a0; + return Dafny.Helpers.Id, Dafny.ISet>, bool>>((_10_ts, _11_typeParametersSupportingEquality) => Dafny.Helpers.Quantifier((_10_ts).UniqueElements, true, (((_forall_var_1) => { + DAST._IType _12_t = (DAST._IType)_forall_var_1; + return !((_10_ts).Contains(_12_t)) || ((this).TypeIsEq(_12_t, _11_typeParametersSupportingEquality)); + }))))(_9_ts, typeParametersSupportingEquality); } } { if (_source0.is_Array) { - DAST._IType _5_t = _source0.dtor_element; + DAST._IType _13_t = _source0.dtor_element; return true; } } { if (_source0.is_Seq) { - DAST._IType _6_t = _source0.dtor_element; - return (this).TypeIsEq(_6_t, typeParametersSupportingEquality); + DAST._IType _14_t = _source0.dtor_element; + return (this).TypeIsEq(_14_t, typeParametersSupportingEquality); } } { if (_source0.is_Set) { - DAST._IType _7_t = _source0.dtor_element; + DAST._IType _15_t = _source0.dtor_element; return true; } } { if (_source0.is_Multiset) { - DAST._IType _8_t = _source0.dtor_element; + DAST._IType _16_t = _source0.dtor_element; return true; } } { if (_source0.is_Map) { - DAST._IType _9_k = _source0.dtor_key; - DAST._IType _10_v = _source0.dtor_value; - return (this).TypeIsEq(_10_v, typeParametersSupportingEquality); + DAST._IType _17_k = _source0.dtor_key; + DAST._IType _18_v = _source0.dtor_value; + return (this).TypeIsEq(_18_v, typeParametersSupportingEquality); } } { if (_source0.is_SetBuilder) { - DAST._IType _11_t = _source0.dtor_element; + DAST._IType _19_t = _source0.dtor_element; return true; } } { if (_source0.is_MapBuilder) { - DAST._IType _12_k = _source0.dtor_key; - DAST._IType _13_v = _source0.dtor_value; - return (this).TypeIsEq(_13_v, typeParametersSupportingEquality); + DAST._IType _20_k = _source0.dtor_key; + DAST._IType _21_v = _source0.dtor_value; + return (this).TypeIsEq(_21_v, typeParametersSupportingEquality); } } { @@ -964,14 +1017,35 @@ public bool TypeIsEq(DAST._IType t, Dafny.ISet> type } { if (_source0.is_TypeArg) { - Dafny.ISequence _14_i = _source0.dtor_TypeArg_a0; - return (typeParametersSupportingEquality).Contains(_14_i); + Dafny.ISequence _22_i = _source0.dtor_TypeArg_a0; + return (typeParametersSupportingEquality).Contains(_22_i); } } { return true; } } + public Std.Wrappers._IOption>> Combine(Dafny.ISequence>>> s) + { + Std.Wrappers._IOption>> _hresult = Std.Wrappers.Option>>.Default(); + if ((new BigInteger((s).Count)).Sign == 0) { + _hresult = Std.Wrappers.Option>>.create_Some(Dafny.Set>.FromElements()); + return _hresult; + } + Dafny.ISet> _0_result; + _0_result = Dafny.Set>.FromElements(); + BigInteger _hi0 = new BigInteger((s).Count); + for (BigInteger _1_i = BigInteger.Zero; _1_i < _hi0; _1_i++) { + if (((s).Select(_1_i)).is_None) { + _hresult = Std.Wrappers.Option>>.create_None(); + return _hresult; + } + _0_result = Dafny.Set>.Union(_0_result, ((s).Select(_1_i)).dtor_value); + } + _hresult = Std.Wrappers.Option>>.create_Some(_0_result); + return _hresult; + return _hresult; + } public bool DatatypeIsEq(DAST._IDatatype c, Dafny.ISet> typeParametersSupportingEquality) { return (!((c).dtor_isCo)) && (Dafny.Helpers.Id>, bool>>((_0_c, _1_typeParametersSupportingEquality) => Dafny.Helpers.Quantifier(((_0_c).dtor_ctors).UniqueElements, true, (((_forall_var_0) => { @@ -1019,9 +1093,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _5_extern = _out4; Dafny.ISequence _6_ctors; _6_ctors = Dafny.Sequence.FromElements(); - Dafny.ISequence _7_variances; - _7_variances = Std.Collections.Seq.__default.Map(((System.Func)((_8_typeParamDecl) => { - return (_8_typeParamDecl).dtor_variance; + Dafny.ISequence _7_typeParamInfos; + _7_typeParamInfos = Std.Collections.Seq.__default.Map(((System.Func)((_8_typeParamDecl) => { + return (_8_typeParamDecl).dtor_info; })), (c).dtor_typeParams); Dafny.ISequence _9_singletonConstructors; _9_singletonConstructors = Dafny.Sequence.FromElements(); @@ -1091,7 +1165,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) Dafny.IMap>,Dafny.ISequence> _26_traitBodies; Dafny.ISequence _out6; Dafny.IMap>,Dafny.ISequence> _out7; - (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_24_selfPath, _1_typeParamsSeq, DAST.ResolvedTypeBase.create_Datatype(_7_variances), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _1_typeParamsSeq, out _out6, out _out7); + (this).GenClassImplBody((c).dtor_body, false, DAST.Type.create_UserDefined(DAST.ResolvedType.create(_24_selfPath, _1_typeParamsSeq, DAST.ResolvedTypeBase.create_Datatype((c).dtor_equalitySupport, _7_typeParamInfos), (c).dtor_attributes, Dafny.Sequence>.FromElements(), Dafny.Sequence.FromElements())), _1_typeParamsSeq, out _out6, out _out7); _25_implBodyRaw = _out6; _26_traitBodies = _out7; Dafny.ISequence _27_implBody; @@ -1204,14 +1278,14 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _out11 = (this).GenType(_57_typeArg, Defs.GenTypeContext.@default()); _59_rTypeArg = _out11; _54_types = Dafny.Sequence.Concat(_54_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_59_rTypeArg)))); - if (((_55_typeI) < (new BigInteger((_7_variances).Count))) && (((_7_variances).Select(_55_typeI)).is_Nonvariant)) { + if (((_55_typeI) < (new BigInteger((_7_typeParamInfos).Count))) && ((((_7_typeParamInfos).Select(_55_typeI)).dtor_variance).is_Nonvariant)) { _48_coerceTypes = Dafny.Sequence.Concat(_48_coerceTypes, Dafny.Sequence.FromElements(_59_rTypeArg)); goto continue_2_0; } DAST._ITypeArgDecl _60_coerceTypeParam; DAST._ITypeArgDecl _61_dt__update__tmp_h0 = _56_typeParam; Dafny.ISequence _62_dt__update_hname_h0 = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), Std.Strings.__default.OfNat(_55_typeI)); - _60_coerceTypeParam = DAST.TypeArgDecl.create(_62_dt__update_hname_h0, (_61_dt__update__tmp_h0).dtor_bounds, (_61_dt__update__tmp_h0).dtor_variance); + _60_coerceTypeParam = DAST.TypeArgDecl.create(_62_dt__update_hname_h0, (_61_dt__update__tmp_h0).dtor_bounds, (_61_dt__update__tmp_h0).dtor_info); DAST._IType _63_coerceTypeArg; RAST._ITypeParamDecl _64_rCoerceTypeParamDecl; DAST._IType _out12; @@ -1251,11 +1325,11 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } return Dafny.Set>.FromCollection(_coll1); }))())(c); - bool _71_cIsEq; - _71_cIsEq = (this).DatatypeIsEq(c, _68_typeParametersSupportingEquality); + bool _71_cIsAlwaysEq; + _71_cIsAlwaysEq = (this).DatatypeIsEq(c, _68_typeParametersSupportingEquality); RAST._IType _72_datatypeType; _72_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, ((_71_cIsEq) ? (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(PartialEq, Clone)]"))) : (Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")))), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _72_datatypeType, _27_implBody))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _72_datatypeType, _27_implBody))); if ((new BigInteger(((c).dtor_superTraitTypes).Count)).Sign == 1) { RAST._IType _73_fullType; if (_0_isRcWrapped) { @@ -1333,152 +1407,178 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _89_hashImplBodyCases = Dafny.Sequence.FromElements(); Dafny.ISequence _90_coerceImplBodyCases; _90_coerceImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _91_partialEqImplBodyCases; + _91_partialEqImplBodyCases = Dafny.Sequence.FromElements(); BigInteger _hi9 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _91_i = BigInteger.Zero; _91_i < _hi9; _91_i++) { - DAST._IDatatypeCtor _92_ctor; - _92_ctor = ((c).dtor_ctors).Select(_91_i); - Dafny.ISequence _93_ctorMatch; - _93_ctorMatch = Defs.__default.escapeName((_92_ctor).dtor_name); - Dafny.ISequence _94_modulePrefix; + for (BigInteger _92_i = BigInteger.Zero; _92_i < _hi9; _92_i++) { + DAST._IDatatypeCtor _93_ctor; + _93_ctor = ((c).dtor_ctors).Select(_92_i); + Dafny.ISequence _94_ctorMatch; + _94_ctorMatch = Defs.__default.escapeName((_93_ctor).dtor_name); + Dafny.ISequence _95_modulePrefix; if (((((c).dtor_enclosingModule))).Equals(Dafny.Sequence.UnicodeFromString("_module"))) { - _94_modulePrefix = Dafny.Sequence.UnicodeFromString(""); + _95_modulePrefix = Dafny.Sequence.UnicodeFromString(""); } else { - _94_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); - } - Dafny.ISequence _95_ctorName; - _95_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_92_ctor).dtor_name)); - if (((new BigInteger((_95_ctorName).Count)) >= (new BigInteger(13))) && (((_95_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { - _95_ctorName = Dafny.Sequence.UnicodeFromString(""); - } - RAST._IExpr _96_printRhs; - _96_printRhs = (this).writeStr(Dafny.Sequence.Concat(_95_ctorName, (((_92_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); - RAST._IExpr _97_hashRhs; - _97_hashRhs = (this).InitEmptyExpr(); - Dafny.ISequence _98_coerceRhsArgs; - _98_coerceRhsArgs = Dafny.Sequence.FromElements(); - bool _99_isNumeric; - _99_isNumeric = false; - Dafny.ISequence _100_ctorMatchInner; - _100_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); - BigInteger _hi10 = new BigInteger(((_92_ctor).dtor_args).Count); - for (BigInteger _101_j = BigInteger.Zero; _101_j < _hi10; _101_j++) { - DAST._IDatatypeDtor _102_dtor; - _102_dtor = ((_92_ctor).dtor_args).Select(_101_j); - Dafny.ISequence _103_patternName; - _103_patternName = Defs.__default.escapeVar(((_102_dtor).dtor_formal).dtor_name); - DAST._IType _104_formalType; - _104_formalType = ((_102_dtor).dtor_formal).dtor_typ; - if (((_101_j).Sign == 0) && ((_103_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _99_isNumeric = true; - } - if (_99_isNumeric) { - _103_patternName = Std.Wrappers.Option>.GetOr((_102_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_101_j))); - } - if ((_104_formalType).is_Arrow) { - _97_hashRhs = (_97_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + _95_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); + } + Dafny.ISequence _96_ctorName; + _96_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_95_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_93_ctor).dtor_name)); + if (((new BigInteger((_96_ctorName).Count)) >= (new BigInteger(13))) && (((_96_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { + _96_ctorName = Dafny.Sequence.UnicodeFromString(""); + } + RAST._IExpr _97_printRhs; + _97_printRhs = (this).writeStr(Dafny.Sequence.Concat(_96_ctorName, (((_93_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); + RAST._IExpr _98_hashRhs; + _98_hashRhs = (this).InitEmptyExpr(); + RAST._IExpr _99_partialEqRhs; + _99_partialEqRhs = RAST.Expr.create_LiteralBool(true); + Dafny.ISequence _100_coerceRhsArgs; + _100_coerceRhsArgs = Dafny.Sequence.FromElements(); + bool _101_isNumeric; + _101_isNumeric = false; + Dafny.ISequence _102_ctorMatchInner; + _102_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); + Dafny.ISequence _103_ctorMatchInner2; + _103_ctorMatchInner2 = Dafny.Sequence.UnicodeFromString(""); + BigInteger _hi10 = new BigInteger(((_93_ctor).dtor_args).Count); + for (BigInteger _104_j = BigInteger.Zero; _104_j < _hi10; _104_j++) { + DAST._IDatatypeDtor _105_dtor; + _105_dtor = ((_93_ctor).dtor_args).Select(_104_j); + Dafny.ISequence _106_patternName; + _106_patternName = Defs.__default.escapeVar(((_105_dtor).dtor_formal).dtor_name); + DAST._IType _107_formalType; + _107_formalType = ((_105_dtor).dtor_formal).dtor_typ; + if (((_104_j).Sign == 0) && ((_106_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _101_isNumeric = true; + } + if (_101_isNumeric) { + _106_patternName = Std.Wrappers.Option>.GetOr((_105_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_104_j))); + } + if ((_107_formalType).is_Arrow) { + _98_hashRhs = (_98_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); } else { - _97_hashRhs = (_97_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_103_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); + _98_hashRhs = (_98_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_106_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); } - _100_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_100_ctorMatchInner, _103_patternName), Dafny.Sequence.UnicodeFromString(", ")); - if ((_101_j).Sign == 1) { - _96_printRhs = (_96_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); + _102_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_102_ctorMatchInner, _106_patternName), Dafny.Sequence.UnicodeFromString(", ")); + _103_ctorMatchInner2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_103_ctorMatchInner2, _106_patternName), Dafny.Sequence.UnicodeFromString(": ")), Dafny.Sequence.UnicodeFromString("_2_")), _106_patternName), Dafny.Sequence.UnicodeFromString(", ")); + if ((_107_formalType).is_Arrow) { + _99_partialEqRhs = (_99_partialEqRhs).And(RAST.Expr.create_LiteralBool(false)); + } else { + _99_partialEqRhs = (_99_partialEqRhs).And((RAST.Expr.create_Identifier(_106_patternName)).Equals(RAST.Expr.create_Identifier(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_2_"), _106_patternName)))); } - _96_printRhs = (_96_printRhs).Then((((_104_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_103_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); - RAST._IExpr _105_coerceRhsArg = RAST.Expr.Default(); - RAST._IType _106_formalTpe; + if ((_104_j).Sign == 1) { + _97_printRhs = (_97_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); + } + _97_printRhs = (_97_printRhs).Then((((_107_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_106_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); + RAST._IExpr _108_coerceRhsArg = RAST.Expr.Default(); + RAST._IType _109_formalTpe; RAST._IType _out21; - _out21 = (this).GenType(_104_formalType, Defs.GenTypeContext.@default()); - _106_formalTpe = _out21; - DAST._IType _107_newFormalType; - _107_newFormalType = (_104_formalType).Replace(_51_coerceMap); - RAST._IType _108_newFormalTpe; - _108_newFormalTpe = (_106_formalTpe).ReplaceMap(_52_rCoerceMap); - Std.Wrappers._IResult,RAST._IExpr>>> _109_upcastConverter; - _109_upcastConverter = (this).UpcastConversionLambda(_104_formalType, _106_formalTpe, _107_newFormalType, _108_newFormalTpe, _53_coerceMapToArg); - if ((_109_upcastConverter).is_Success) { - RAST._IExpr _110_coercionFunction; - _110_coercionFunction = (_109_upcastConverter).dtor_value; - _105_coerceRhsArg = (_110_coercionFunction).Apply1(RAST.Expr.create_Identifier(_103_patternName)); + _out21 = (this).GenType(_107_formalType, Defs.GenTypeContext.@default()); + _109_formalTpe = _out21; + DAST._IType _110_newFormalType; + _110_newFormalType = (_107_formalType).Replace(_51_coerceMap); + RAST._IType _111_newFormalTpe; + _111_newFormalTpe = (_109_formalTpe).ReplaceMap(_52_rCoerceMap); + Std.Wrappers._IResult,RAST._IExpr>>> _112_upcastConverter; + _112_upcastConverter = (this).UpcastConversionLambda(_107_formalType, _109_formalTpe, _110_newFormalType, _111_newFormalTpe, _53_coerceMapToArg); + if ((_112_upcastConverter).is_Success) { + RAST._IExpr _113_coercionFunction; + _113_coercionFunction = (_112_upcastConverter).dtor_value; + _108_coerceRhsArg = (_113_coercionFunction).Apply1(RAST.Expr.create_Identifier(_106_patternName)); } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_101_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); - _105_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); - } - _98_coerceRhsArgs = Dafny.Sequence.Concat(_98_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_103_patternName, _105_coerceRhsArg))); - } - RAST._IExpr _111_coerceRhs; - _111_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_92_ctor).dtor_name)), _98_coerceRhsArgs); - if (_99_isNumeric) { - _93_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _100_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_104_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); + _108_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); + } + _100_coerceRhsArgs = Dafny.Sequence.Concat(_100_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_106_patternName, _108_coerceRhsArg))); + } + RAST._IExpr _114_coerceRhs; + _114_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_93_ctor).dtor_name)), _100_coerceRhsArgs); + Dafny.ISequence _115_pattern = Dafny.Sequence.Empty; + Dafny.ISequence _116_pattern2 = Dafny.Sequence.Empty; + if (_101_isNumeric) { + _115_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _102_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + _116_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _103_ctorMatchInner2), Dafny.Sequence.UnicodeFromString(")")); } else { - _93_ctorMatch = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _100_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + _115_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _102_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + _116_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _103_ctorMatchInner2), Dafny.Sequence.UnicodeFromString("}")); } - if ((_92_ctor).dtor_hasAnyArgs) { - _96_printRhs = (_96_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); + if ((_93_ctor).dtor_hasAnyArgs) { + _97_printRhs = (_97_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); } - _96_printRhs = (_96_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); - _88_printImplBodyCases = Dafny.Sequence.Concat(_88_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _93_ctorMatch), RAST.Expr.create_Block(_96_printRhs)))); - _89_hashImplBodyCases = Dafny.Sequence.Concat(_89_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _93_ctorMatch), RAST.Expr.create_Block(_97_hashRhs)))); - _90_coerceImplBodyCases = Dafny.Sequence.Concat(_90_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _93_ctorMatch), RAST.Expr.create_Block(_111_coerceRhs)))); + _97_printRhs = (_97_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); + _88_printImplBodyCases = Dafny.Sequence.Concat(_88_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _115_pattern), RAST.Expr.create_Block(_97_printRhs)))); + _89_hashImplBodyCases = Dafny.Sequence.Concat(_89_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _115_pattern), RAST.Expr.create_Block(_98_hashRhs)))); + _91_partialEqImplBodyCases = Dafny.Sequence.Concat(_91_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _115_pattern), Dafny.Sequence.UnicodeFromString(", ")), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _116_pattern2), Dafny.Sequence.UnicodeFromString(")")), RAST.Expr.create_Block(_99_partialEqRhs)))); + _90_coerceImplBodyCases = Dafny.Sequence.Concat(_90_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _94_ctorMatch), RAST.Expr.create_Block(_114_coerceRhs)))); } + _91_partialEqImplBodyCases = Dafny.Sequence.Concat(_91_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.UnicodeFromString("_"), RAST.Expr.create_Block(RAST.Expr.create_LiteralBool(false))))); if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { - Dafny.ISequence _112_extraCases; - _112_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); - _88_printImplBodyCases = Dafny.Sequence.Concat(_88_printImplBodyCases, _112_extraCases); - _89_hashImplBodyCases = Dafny.Sequence.Concat(_89_hashImplBodyCases, _112_extraCases); - _90_coerceImplBodyCases = Dafny.Sequence.Concat(_90_coerceImplBodyCases, _112_extraCases); - } - Dafny.ISequence _113_defaultConstrainedTypeParams; - _113_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - Dafny.ISequence _114_rTypeParamsDeclsWithEq; - _114_rTypeParamsDeclsWithEq = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Eq)); - Dafny.ISequence _115_rTypeParamsDeclsWithHash; - _115_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - RAST._IExpr _116_printImplBody; - _116_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _88_printImplBodyCases); - RAST._IExpr _117_hashImplBody; - _117_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _89_hashImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams, _116_printImplBody))); + Dafny.ISequence _117_extraCases; + _117_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + _88_printImplBodyCases = Dafny.Sequence.Concat(_88_printImplBodyCases, _117_extraCases); + _89_hashImplBodyCases = Dafny.Sequence.Concat(_89_hashImplBodyCases, _117_extraCases); + _90_coerceImplBodyCases = Dafny.Sequence.Concat(_90_coerceImplBodyCases, _117_extraCases); + } + Dafny.ISequence _118_defaultConstrainedTypeParams; + _118_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + Dafny.ISequence _119_rTypeParamsDeclsWithHash; + _119_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); + RAST._IExpr _120_printImplBody; + _120_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _88_printImplBodyCases); + RAST._IExpr _121_hashImplBody; + _121_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _89_hashImplBodyCases); + RAST._IExpr _122_eqImplBody; + _122_eqImplBody = RAST.Expr.create_Match(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))), _91_partialEqImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams, _120_printImplBody))); if ((new BigInteger((_49_rCoerceTypeParams).Count)).Sign == 1) { - RAST._IExpr _118_coerceImplBody; - _118_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _90_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _72_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _118_coerceImplBody))); + RAST._IExpr _123_coerceImplBody; + _123_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _90_coerceImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _72_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _123_coerceImplBody))); } if ((new BigInteger((_9_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { - RAST._IType _119_instantiationType; + RAST._IType _124_instantiationType; if (_0_isRcWrapped) { - _119_instantiationType = RAST.__default.Rc(_72_datatypeType); + _124_instantiationType = RAST.__default.Rc(_72_datatypeType); } else { - _119_instantiationType = _72_datatypeType; + _124_instantiationType = _72_datatypeType; } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _72_datatypeType, _119_instantiationType, _9_singletonConstructors))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _72_datatypeType, _124_instantiationType, _9_singletonConstructors))); } - if (_71_cIsEq) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_114_rTypeParamsDeclsWithEq, RAST.__default.Eq, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), Dafny.Sequence.FromElements())))); + if ((((c).dtor_equalitySupport).is_Always) || (((c).dtor_equalitySupport).is_ConsultTypeArguments)) { + Dafny.ISequence _125_rTypeParamsDeclsWithEq; + _125_rTypeParamsDeclsWithEq = _3_rTypeParamsDecls; + if (((c).dtor_equalitySupport).is_ConsultTypeArguments) { + BigInteger _hi11 = new BigInteger((_3_rTypeParamsDecls).Count); + for (BigInteger _126_i = BigInteger.Zero; _126_i < _hi11; _126_i++) { + if (((((c).dtor_typeParams).Select(_126_i)).dtor_info).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype) { + _125_rTypeParamsDeclsWithEq = Dafny.Sequence.Update(_125_rTypeParamsDeclsWithEq, _126_i, ((_125_rTypeParamsDeclsWithEq).Select(_126_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Eq, RAST.__default.Hash))); + } + } + } + s = Dafny.Sequence.Concat(s, Defs.__default.EqImpl(_125_rTypeParamsDeclsWithEq, _72_datatypeType, _2_rTypeParams, _122_eqImplBody)); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_115_rTypeParamsDeclsWithHash, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams), _117_hashImplBody))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_119_rTypeParamsDeclsWithHash, _72_datatypeType, _121_hashImplBody))); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - RAST._IExpr _120_structName; - _120_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _121_structAssignments; - _121_structAssignments = Dafny.Sequence.FromElements(); - BigInteger _hi11 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); - for (BigInteger _122_i = BigInteger.Zero; _122_i < _hi11; _122_i++) { - DAST._IDatatypeDtor _123_dtor; - _123_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_122_i); - _121_structAssignments = Dafny.Sequence.Concat(_121_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_123_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); - } - RAST._IType _124_fullType; - _124_fullType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); - if ((false) && (_71_cIsEq)) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _124_fullType, _120_structName, _121_structAssignments))); - } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _124_fullType))); - } - Dafny.ISequence _125_superTraitImplementations; + RAST._IExpr _127_structName; + _127_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _128_structAssignments; + _128_structAssignments = Dafny.Sequence.FromElements(); + BigInteger _hi12 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); + for (BigInteger _129_i = BigInteger.Zero; _129_i < _hi12; _129_i++) { + DAST._IDatatypeDtor _130_dtor; + _130_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_129_i); + _128_structAssignments = Dafny.Sequence.Concat(_128_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_130_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); + } + if ((false) && (_71_cIsAlwaysEq)) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _72_datatypeType, _127_structName, _128_structAssignments))); + } + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _72_datatypeType))); + } + Dafny.ISequence _131_superTraitImplementations; Dafny.ISequence _out22; - _out22 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, _71_cIsEq, Dafny.Sequence.UnicodeFromString("datatype")); - _125_superTraitImplementations = _out22; - s = Dafny.Sequence.Concat(s, _125_superTraitImplementations); + _out22 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, _71_cIsAlwaysEq, Dafny.Sequence.UnicodeFromString("datatype")); + _131_superTraitImplementations = _out22; + s = Dafny.Sequence.Concat(s, _131_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -2179,15 +2279,15 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e after_match1: ; _32_env = Defs.Environment.create(Dafny.Sequence>.Concat(_34_preAssignNames, _1_paramNames), Dafny.Map, RAST._IType>.Merge(_35_preAssignTypes, _2_paramTypes), Dafny.Set>.FromElements()); RAST._IExpr _50_body; - Dafny.ISet> _51___v24; - Defs._IEnvironment _52___v25; + Dafny.ISet> _51___v50; + Defs._IEnvironment _52___v51; RAST._IExpr _out6; Dafny.ISet> _out7; Defs._IEnvironment _out8; (this).GenStmts((m).dtor_body, _8_selfIdent, _32_env, true, _36_earlyReturn, out _out6, out _out7, out _out8); _50_body = _out6; - _51___v24 = _out7; - _52___v25 = _out8; + _51___v50 = _out7; + _52___v51 = _out8; _31_fBody = Std.Wrappers.Option.create_Some((_33_preBody).Then(_50_body)); } else { _32_env = Defs.Environment.create(_1_paramNames, _2_paramTypes, Dafny.Set>.FromElements()); @@ -2480,14 +2580,14 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Defs._ISelfInfo BigInteger _hi0 = new BigInteger((_12_indices).Count); for (BigInteger _18_i = BigInteger.Zero; _18_i < _hi0; _18_i++) { RAST._IExpr _19_idx; - Defs._IOwnership _20___v33; + Defs._IOwnership _20___v59; Dafny.ISet> _21_recIdentsIdx; RAST._IExpr _out6; Defs._IOwnership _out7; Dafny.ISet> _out8; (this).GenExpr((_12_indices).Select(_18_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out6, out _out7, out _out8); _19_idx = _out6; - _20___v33 = _out7; + _20___v59 = _out7; _21_recIdentsIdx = _out8; Dafny.ISequence _22_varName; _22_varName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("__idx"), Std.Strings.__default.OfNat(_18_i)); @@ -2695,15 +2795,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _5_isAssignedVar = Defs.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { RAST._IExpr _6_rhs; - Defs._IOwnership _7___v47; - Dafny.ISet> _8___v48; + Defs._IOwnership _7___v73; + Dafny.ISet> _8___v74; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr(DAST.Expression.create_InitializationValue(((_2_field).dtor_formal).dtor_typ), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); _6_rhs = _out1; - _7___v47 = _out2; - _8___v48 = _out3; + _7___v73 = _out2; + _8___v74 = _out3; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); Dafny.ISequence _9_update__if__uninit; if ((_2_field).dtor_isConstant) { @@ -2798,14 +2898,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _22_expression = _source0.dtor_value; { RAST._IExpr _23_exprGen; - Defs._IOwnership _24___v49; + Defs._IOwnership _24___v75; Dafny.ISet> _25_exprIdents; RAST._IExpr _out12; Defs._IOwnership _out13; Dafny.ISet> _out14; (this).GenExpr(_22_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out12, out _out13, out _out14); _23_exprGen = _out12; - _24___v49 = _out13; + _24___v75 = _out13; _25_exprIdents = _out14; if ((_21_lhs).is_Ident) { Dafny.ISequence _26_rustId; @@ -2855,14 +2955,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _36_elsDafny = _source0.dtor_els; { RAST._IExpr _37_cond; - Defs._IOwnership _38___v50; + Defs._IOwnership _38___v76; Dafny.ISet> _39_recIdents; RAST._IExpr _out19; Defs._IOwnership _out20; Dafny.ISet> _out21; (this).GenExpr(_34_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out19, out _out20, out _out21); _37_cond = _out19; - _38___v50 = _out20; + _38___v76 = _out20; _39_recIdents = _out21; Dafny.ISequence _40_condString; _40_condString = (_37_cond)._ToString(Defs.__default.IND); @@ -2923,14 +3023,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _53_body = _source0.dtor_body; { RAST._IExpr _54_cond; - Defs._IOwnership _55___v51; + Defs._IOwnership _55___v77; Dafny.ISet> _56_recIdents; RAST._IExpr _out31; Defs._IOwnership _out32; Dafny.ISet> _out33; (this).GenExpr(_52_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out31, out _out32, out _out33); _54_cond = _out31; - _55___v51 = _out32; + _55___v77 = _out32; _56_recIdents = _out33; readIdents = _56_recIdents; RAST._IExpr _57_bodyExpr; @@ -2958,14 +3058,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _63_body = _source0.dtor_body; { RAST._IExpr _64_over; - Defs._IOwnership _65___v52; + Defs._IOwnership _65___v78; Dafny.ISet> _66_recIdents; RAST._IExpr _out37; Defs._IOwnership _out38; Dafny.ISet> _out39; (this).GenExpr(_62_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out37, out _out38, out _out39); _64_over = _out37; - _65___v52 = _out38; + _65___v78 = _out38; _66_recIdents = _out39; if (((_62_overExpr).is_MapBoundedPool) || ((_62_overExpr).is_SetBoundedPool)) { _64_over = ((_64_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); @@ -3029,15 +3129,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _75_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { RAST._IExpr _76_selfClone; - Defs._IOwnership _77___v53; - Dafny.ISet> _78___v54; + Defs._IOwnership _77___v79; + Dafny.ISet> _78___v80; RAST._IExpr _out44; Defs._IOwnership _out45; Dafny.ISet> _out46; (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out44, out _out45, out _out46); _76_selfClone = _out44; - _77___v53 = _out45; - _78___v54 = _out46; + _77___v79 = _out45; + _78___v80 = _out46; generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_76_selfClone))); if (((_75_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { _75_oldEnv = (_75_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); @@ -3054,15 +3154,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv goto continue_4_0; } RAST._IExpr _82_paramInit; - Defs._IOwnership _83___v55; - Dafny.ISet> _84___v56; + Defs._IOwnership _83___v81; + Dafny.ISet> _84___v82; RAST._IExpr _out47; Defs._IOwnership _out48; Dafny.ISet> _out49; (this).GenIdent(_81_param, selfIdent, _75_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out47, out _out48, out _out49); _82_paramInit = _out47; - _83___v55 = _out48; - _84___v56 = _out49; + _83___v81 = _out48; + _84___v82 = _out49; Dafny.ISequence _85_recVar; _85_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_80_paramI)); generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _85_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_82_paramInit))); @@ -3154,14 +3254,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _102_exprDafny = _source0.dtor_expr; { RAST._IExpr _103_expr; - Defs._IOwnership _104___v57; + Defs._IOwnership _104___v83; Dafny.ISet> _105_recIdents; RAST._IExpr _out55; Defs._IOwnership _out56; Dafny.ISet> _out57; (this).GenExpr(_102_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out55, out _out56, out _out57); _103_expr = _out55; - _104___v57 = _out56; + _104___v83 = _out56; _105_recIdents = _out57; readIdents = _105_recIdents; if (isLast) { @@ -3191,15 +3291,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv BigInteger _hi3 = new BigInteger((_106_rustIdents).Count); for (BigInteger _108_i = BigInteger.Zero; _108_i < _hi3; _108_i++) { RAST._IExpr _109_rIdent; - Defs._IOwnership _110___v58; - Dafny.ISet> _111___v59; + Defs._IOwnership _110___v84; + Dafny.ISet> _111___v85; RAST._IExpr _out58; Defs._IOwnership _out59; Dafny.ISet> _out60; (this).GenIdent((_106_rustIdents).Select(_108_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out58, out _out59, out _out60); _109_rIdent = _out58; - _110___v58 = _out59; - _111___v59 = _out60; + _110___v84 = _out59; + _111___v85 = _out60; _107_tupleArgs = Dafny.Sequence.Concat(_107_tupleArgs, Dafny.Sequence.FromElements(_109_rIdent)); } if ((new BigInteger((_107_tupleArgs).Count)) == (BigInteger.One)) { @@ -3305,9 +3405,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. DAST._IExpression _source0 = e; { if (_source0.is_Literal) { - DAST._ILiteral _h620 = _source0.dtor_Literal_a0; - if (_h620.is_BoolLiteral) { - bool _0_b = _h620.dtor_BoolLiteral_a0; + DAST._ILiteral _h630 = _source0.dtor_Literal_a0; + if (_h630.is_BoolLiteral) { + bool _0_b = _h630.dtor_BoolLiteral_a0; { RAST._IExpr _out0; Defs._IOwnership _out1; @@ -3323,10 +3423,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h621 = _source0.dtor_Literal_a0; - if (_h621.is_IntLiteral) { - Dafny.ISequence _1_i = _h621.dtor_IntLiteral_a0; - DAST._IType _2_t = _h621.dtor_IntLiteral_a1; + DAST._ILiteral _h631 = _source0.dtor_Literal_a0; + if (_h631.is_IntLiteral) { + Dafny.ISequence _1_i = _h631.dtor_IntLiteral_a0; + DAST._IType _2_t = _h631.dtor_IntLiteral_a1; { DAST._IType _source1 = _2_t; { @@ -3369,11 +3469,11 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h622 = _source0.dtor_Literal_a0; - if (_h622.is_DecLiteral) { - Dafny.ISequence _5_n = _h622.dtor_DecLiteral_a0; - Dafny.ISequence _6_d = _h622.dtor_DecLiteral_a1; - DAST._IType _7_t = _h622.dtor_DecLiteral_a2; + DAST._ILiteral _h632 = _source0.dtor_Literal_a0; + if (_h632.is_DecLiteral) { + Dafny.ISequence _5_n = _h632.dtor_DecLiteral_a0; + Dafny.ISequence _6_d = _h632.dtor_DecLiteral_a1; + DAST._IType _7_t = _h632.dtor_DecLiteral_a2; { DAST._IType _source2 = _7_t; { @@ -3412,10 +3512,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h623 = _source0.dtor_Literal_a0; - if (_h623.is_StringLiteral) { - Dafny.ISequence _10_l = _h623.dtor_StringLiteral_a0; - bool _11_verbatim = _h623.dtor_verbatim; + DAST._ILiteral _h633 = _source0.dtor_Literal_a0; + if (_h633.is_StringLiteral) { + Dafny.ISequence _10_l = _h633.dtor_StringLiteral_a0; + bool _11_verbatim = _h633.dtor_verbatim; { r = (((RAST.__default.dafny__runtime).MSel((this).string__of)).AsExpr()).Apply1(RAST.Expr.create_LiteralString(_10_l, false, _11_verbatim)); RAST._IExpr _out8; @@ -3432,9 +3532,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h624 = _source0.dtor_Literal_a0; - if (_h624.is_CharLiteralUTF16) { - BigInteger _12_c = _h624.dtor_CharLiteralUTF16_a0; + DAST._ILiteral _h634 = _source0.dtor_Literal_a0; + if (_h634.is_CharLiteralUTF16) { + BigInteger _12_c = _h634.dtor_CharLiteralUTF16_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(_12_c)); r = RAST.Expr.create_TypeAscription(r, RAST.Type.create_U16()); @@ -3453,9 +3553,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h625 = _source0.dtor_Literal_a0; - if (_h625.is_CharLiteral) { - Dafny.Rune _13_c = _h625.dtor_CharLiteral_a0; + DAST._ILiteral _h635 = _source0.dtor_Literal_a0; + if (_h635.is_CharLiteral) { + Dafny.Rune _13_c = _h635.dtor_CharLiteral_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(new BigInteger((_13_c).Value))); if (!(((this).charType).is_UTF32)) { @@ -3477,8 +3577,8 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } } { - DAST._ILiteral _h626 = _source0.dtor_Literal_a0; - DAST._IType _14_tpe = _h626.dtor_Null_a0; + DAST._ILiteral _h636 = _source0.dtor_Literal_a0; + DAST._IType _14_tpe = _h636.dtor_Null_a0; { RAST._IType _15_tpeGen; RAST._IType _out14; @@ -3595,24 +3695,24 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ _10_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); } RAST._IExpr _11_left; - Defs._IOwnership _12___v60; + Defs._IOwnership _12___v86; Dafny.ISet> _13_recIdentsL; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(_4_lExpr, selfIdent, env, _9_expectedLeftOwnership, out _out0, out _out1, out _out2); _11_left = _out0; - _12___v60 = _out1; + _12___v86 = _out1; _13_recIdentsL = _out2; RAST._IExpr _14_right; - Defs._IOwnership _15___v61; + Defs._IOwnership _15___v87; Dafny.ISet> _16_recIdentsR; RAST._IExpr _out3; Defs._IOwnership _out4; Dafny.ISet> _out5; (this).GenExpr(_5_rExpr, selfIdent, env, _10_expectedRightOwnership, out _out3, out _out4, out _out5); _14_right = _out3; - _15___v61 = _out4; + _15___v87 = _out4; _16_recIdentsR = _out5; DAST._IBinOp _source0 = _0_op; { @@ -4311,7 +4411,7 @@ public bool SameTypesButDifferentTypeParameters(DAST._IType fromType, RAST._ITyp } } else if ((this).SameTypesButDifferentTypeParameters(fromType, fromTpe, toType, toTpe)) { Dafny.ISequence _6_indices = ((((fromType).is_UserDefined) && ((((fromType).dtor_resolved).dtor_kind).is_Datatype)) ? (Std.Collections.Seq.__default.Filter(Dafny.Helpers.Id>>((_7_fromTpe, _8_fromType) => ((System.Func)((_9_i) => { - return ((((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((_7_fromTpe).dtor_arguments).Count)))) ? (!(((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((((_8_fromType).dtor_resolved).dtor_kind).dtor_variances).Count)))) || (!((((((_8_fromType).dtor_resolved).dtor_kind).dtor_variances).Select(_9_i)).is_Nonvariant))) : (false)); + return ((((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((_7_fromTpe).dtor_arguments).Count)))) ? (!(((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((((_8_fromType).dtor_resolved).dtor_kind).dtor_info).Count)))) || (!(((((((_8_fromType).dtor_resolved).dtor_kind).dtor_info).Select(_9_i)).dtor_variance).is_Nonvariant))) : (false)); })))(fromTpe, fromType), ((System.Func>) (() => { BigInteger dim14 = new BigInteger(((fromTpe).dtor_arguments).Count); var arr14 = new BigInteger[Dafny.Helpers.ToIntChecked(dim14, "array size exceeds memory limit")]; @@ -4750,14 +4850,14 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v74; + Defs._IOwnership _5___v100; Dafny.ISet> _6_argIdents; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); _4_argExpr = _out1; - _5___v74 = _out2; + _5___v100 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -4955,14 +5055,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi1 = new BigInteger((_9_values).Count); for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13___v84; + Defs._IOwnership _13___v110; Dafny.ISet> _14_recIdents; RAST._IExpr _out16; Defs._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); _12_recursiveGen = _out16; - _13___v84 = _out17; + _13___v110 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -5011,14 +5111,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi3 = new BigInteger((_17_args).Count); for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { RAST._IExpr _23_recursiveGen; - Defs._IOwnership _24___v85; + Defs._IOwnership _24___v111; Dafny.ISet> _25_recIdents; RAST._IExpr _out23; Defs._IOwnership _out24; Dafny.ISet> _out25; (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); _23_recursiveGen = _out23; - _24___v85 = _out24; + _24___v111 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -5056,14 +5156,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi4 = new BigInteger((_26_dims).Count); for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { RAST._IExpr _31_recursiveGen; - Defs._IOwnership _32___v86; + Defs._IOwnership _32___v112; Dafny.ISet> _33_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr((_26_dims).Select(_30_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _31_recursiveGen = _out30; - _32___v86 = _out31; + _32___v112 = _out31; _33_recIdents = _out32; _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); @@ -5090,14 +5190,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _35_underlying = _source0.dtor_value; { RAST._IExpr _36_recursiveGen; - Defs._IOwnership _37___v87; + Defs._IOwnership _37___v113; Dafny.ISet> _38_recIdents; RAST._IExpr _out35; Defs._IOwnership _out36; Dafny.ISet> _out37; (this).GenExpr(_35_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out35, out _out36, out _out37); _36_recursiveGen = _out35; - _37___v87 = _out36; + _37___v113 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -5120,14 +5220,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out40 = (this).GenType(_40_typ, Defs.GenTypeContext.@default()); _41_tpe = _out40; RAST._IExpr _42_recursiveGen; - Defs._IOwnership _43___v88; + Defs._IOwnership _43___v114; Dafny.ISet> _44_recIdents; RAST._IExpr _out41; Defs._IOwnership _out42; Dafny.ISet> _out43; (this).GenExpr(_39_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); _42_recursiveGen = _out41; - _43___v88 = _out42; + _43___v114 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -5193,14 +5293,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; if (_50_isCo) { RAST._IExpr _59_recursiveGen; - Defs._IOwnership _60___v89; + Defs._IOwnership _60___v115; Dafny.ISet> _61_recIdents; RAST._IExpr _out50; Defs._IOwnership _out51; Dafny.ISet> _out52; (this).GenExpr(_58_value, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); _59_recursiveGen = _out50; - _60___v89 = _out51; + _60___v115 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -5223,14 +5323,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _64_wasAssigned))); } else { RAST._IExpr _65_recursiveGen; - Defs._IOwnership _66___v90; + Defs._IOwnership _66___v116; Dafny.ISet> _67_recIdents; RAST._IExpr _out53; Defs._IOwnership _out54; Dafny.ISet> _out55; (this).GenExpr(_58_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out53, out _out54, out _out55); _65_recursiveGen = _out53; - _66___v90 = _out54; + _66___v116 = _out54; _67_recIdents = _out55; _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _65_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); @@ -5270,24 +5370,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _69_expr = _source0.dtor_elem; { RAST._IExpr _70_recursiveGen; - Defs._IOwnership _71___v94; + Defs._IOwnership _71___v120; Dafny.ISet> _72_recIdents; RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; (this).GenExpr(_69_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); _70_recursiveGen = _out61; - _71___v94 = _out62; + _71___v120 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v95; + Defs._IOwnership _74___v121; Dafny.ISet> _75_lengthIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_68_length, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); _73_lengthGen = _out64; - _74___v95 = _out65; + _74___v121 = _out65; _75_lengthIdents = _out66; r = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("_initializer"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_70_recursiveGen)); RAST._IExpr _76_range; @@ -5326,14 +5426,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _82_args = Dafny.Sequence.FromElements(); while ((_81_i) < (new BigInteger((_78_exprs).Count))) { RAST._IExpr _83_recursiveGen; - Defs._IOwnership _84___v96; + Defs._IOwnership _84___v122; Dafny.ISet> _85_recIdents; RAST._IExpr _out70; Defs._IOwnership _out71; Dafny.ISet> _out72; (this).GenExpr((_78_exprs).Select(_81_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out70, out _out71, out _out72); _83_recursiveGen = _out70; - _84___v96 = _out71; + _84___v122 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -5364,14 +5464,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _88_i = BigInteger.Zero; while ((_88_i) < (new BigInteger((_86_exprs).Count))) { RAST._IExpr _89_recursiveGen; - Defs._IOwnership _90___v97; + Defs._IOwnership _90___v123; Dafny.ISet> _91_recIdents; RAST._IExpr _out75; Defs._IOwnership _out76; Dafny.ISet> _out77; (this).GenExpr((_86_exprs).Select(_88_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out75, out _out76, out _out77); _89_recursiveGen = _out75; - _90___v97 = _out76; + _90___v123 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -5399,14 +5499,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _94_i = BigInteger.Zero; while ((_94_i) < (new BigInteger((_92_exprs).Count))) { RAST._IExpr _95_recursiveGen; - Defs._IOwnership _96___v98; + Defs._IOwnership _96___v124; Dafny.ISet> _97_recIdents; RAST._IExpr _out80; Defs._IOwnership _out81; Dafny.ISet> _out82; (this).GenExpr((_92_exprs).Select(_94_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out80, out _out81, out _out82); _95_recursiveGen = _out80; - _96___v98 = _out81; + _96___v124 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -5428,14 +5528,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _98_expr = _source0.dtor_ToMultiset_a0; { RAST._IExpr _99_recursiveGen; - Defs._IOwnership _100___v99; + Defs._IOwnership _100___v125; Dafny.ISet> _101_recIdents; RAST._IExpr _out85; Defs._IOwnership _out86; Dafny.ISet> _out87; (this).GenExpr(_98_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out85, out _out86, out _out87); _99_recursiveGen = _out85; - _100___v99 = _out86; + _100___v125 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -5460,24 +5560,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _104_i = BigInteger.Zero; while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v100; + Defs._IOwnership _106___v126; Dafny.ISet> _107_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); _105_recursiveGenKey = _out90; - _106___v100 = _out91; + _106___v126 = _out91; _107_recIdentsKey = _out92; RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v101; + Defs._IOwnership _109___v127; Dafny.ISet> _110_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); _108_recursiveGenValue = _out93; - _109___v101 = _out94; + _109___v127 = _out94; _110_recIdentsValue = _out95; _103_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_103_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_105_recursiveGenKey, _108_recursiveGenValue))); readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _107_recIdentsKey), _110_recIdentsValue); @@ -5512,14 +5612,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _116_value = _source0.dtor_value; { RAST._IExpr _117_exprR; - Defs._IOwnership _118___v102; + Defs._IOwnership _118___v128; Dafny.ISet> _119_exprIdents; RAST._IExpr _out98; Defs._IOwnership _out99; Dafny.ISet> _out100; (this).GenExpr(_114_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out98, out _out99, out _out100); _117_exprR = _out98; - _118___v102 = _out99; + _118___v128 = _out99; _119_exprIdents = _out100; RAST._IExpr _120_indexR; Defs._IOwnership _121_indexOwnership; @@ -5560,14 +5660,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _128_value = _source0.dtor_value; { RAST._IExpr _129_exprR; - Defs._IOwnership _130___v103; + Defs._IOwnership _130___v129; Dafny.ISet> _131_exprIdents; RAST._IExpr _out109; Defs._IOwnership _out110; Dafny.ISet> _out111; (this).GenExpr(_126_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out109, out _out110, out _out111); _129_exprR = _out109; - _130___v103 = _out110; + _130___v129 = _out110; _131_exprIdents = _out111; RAST._IExpr _132_indexR; Defs._IOwnership _133_indexOwnership; @@ -5648,14 +5748,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _143_f = _source0.dtor_els; { RAST._IExpr _144_cond; - Defs._IOwnership _145___v104; + Defs._IOwnership _145___v130; Dafny.ISet> _146_recIdentsCond; RAST._IExpr _out126; Defs._IOwnership _out127; Dafny.ISet> _out128; (this).GenExpr(_141_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out126, out _out127, out _out128); _144_cond = _out126; - _145___v104 = _out127; + _145___v130 = _out127; _146_recIdentsCond = _out128; RAST._IExpr _147_fExpr; Defs._IOwnership _148_fOwned; @@ -5668,14 +5768,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _148_fOwned = _out130; _149_recIdentsF = _out131; RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v105; + Defs._IOwnership _151___v131; Dafny.ISet> _152_recIdentsT; RAST._IExpr _out132; Defs._IOwnership _out133; Dafny.ISet> _out134; (this).GenExpr(_142_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); _150_tExpr = _out132; - _151___v105 = _out133; + _151___v131 = _out133; _152_recIdentsT = _out134; r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); RAST._IExpr _out135; @@ -5697,14 +5797,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; { RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v106; + Defs._IOwnership _156___v132; Dafny.ISet> _157_recIdents; RAST._IExpr _out137; Defs._IOwnership _out138; Dafny.ISet> _out139; (this).GenExpr(_153_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out137, out _out138, out _out139); _155_recursiveGen = _out137; - _156___v106 = _out138; + _156___v132 = _out138; _157_recIdents = _out139; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); RAST._IExpr _out140; @@ -5727,14 +5827,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; { RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v107; + Defs._IOwnership _161___v133; Dafny.ISet> _162_recIdents; RAST._IExpr _out142; Defs._IOwnership _out143; Dafny.ISet> _out144; (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out142, out _out143, out _out144); _160_recursiveGen = _out142; - _161___v107 = _out143; + _161___v133 = _out143; _162_recIdents = _out144; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); RAST._IExpr _out145; @@ -5799,14 +5899,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _171_native = _source0.dtor_native; { RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v112; + Defs._IOwnership _173___v138; Dafny.ISet> _174_recIdents; RAST._IExpr _out155; Defs._IOwnership _out156; Dafny.ISet> _out157; (this).GenExpr(_168_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out155, out _out156, out _out157); _172_recursiveGen = _out155; - _173___v112 = _out156; + _173___v138 = _out156; _174_recIdents = _out157; RAST._IType _175_arrayType; RAST._IType _out158; @@ -5848,14 +5948,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _177_expr = _source0.dtor_expr; { RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v113; + Defs._IOwnership _179___v139; Dafny.ISet> _180_recIdents; RAST._IExpr _out162; Defs._IOwnership _out163; Dafny.ISet> _out164; (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); _178_recursiveGen = _out162; - _179___v113 = _out163; + _179___v139 = _out163; _180_recIdents = _out164; readIdents = _180_recIdents; r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); @@ -5874,14 +5974,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _181_expr = _source0.dtor_expr; { RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v114; + Defs._IOwnership _183___v140; Dafny.ISet> _184_recIdents; RAST._IExpr _out167; Defs._IOwnership _out168; Dafny.ISet> _out169; (this).GenExpr(_181_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); _182_recursiveGen = _out167; - _183___v114 = _out168; + _183___v140 = _out168; _184_recIdents = _out169; readIdents = _184_recIdents; r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); @@ -5900,14 +6000,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _185_expr = _source0.dtor_expr; { RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v115; + Defs._IOwnership _187___v141; Dafny.ISet> _188_recIdents; RAST._IExpr _out172; Defs._IOwnership _out173; Dafny.ISet> _out174; (this).GenExpr(_185_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out172, out _out173, out _out174); _186_recursiveGen = _out172; - _187___v115 = _out173; + _187___v141 = _out173; _188_recIdents = _out174; readIdents = _188_recIdents; r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); @@ -5979,15 +6079,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _209_name = _let_tmp_rhs1.dtor__0; RAST._IType _210_ty = _let_tmp_rhs1.dtor__1; RAST._IExpr _211_rIdent; - Defs._IOwnership _212___v116; - Dafny.ISet> _213___v117; + Defs._IOwnership _212___v142; + Dafny.ISet> _213___v143; RAST._IExpr _out181; Defs._IOwnership _out182; Dafny.ISet> _out183; (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((!(_193_isConstant)) && ((_210_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); _211_rIdent = _out181; - _212___v116 = _out182; - _213___v117 = _out183; + _212___v142 = _out182; + _213___v143 = _out183; _207_onExprArgs = Dafny.Sequence.Concat(_207_onExprArgs, Dafny.Sequence.FromElements(_211_rIdent)); } _206_body = (_206_body).Apply(_207_onExprArgs); @@ -6305,14 +6405,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _260_l = _source5.dtor_value; { RAST._IExpr _261_lExpr; - Defs._IOwnership _262___v120; + Defs._IOwnership _262___v146; Dafny.ISet> _263_recIdentsL; RAST._IExpr _out222; Defs._IOwnership _out223; Dafny.ISet> _out224; (this).GenExpr(_260_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out222, out _out223, out _out224); _261_lExpr = _out222; - _262___v120 = _out223; + _262___v146 = _out223; _263_recIdentsL = _out224; _259_arguments = Dafny.Sequence.Concat(_259_arguments, Dafny.Sequence.FromElements(_261_lExpr)); readIdents = Dafny.Set>.Union(readIdents, _263_recIdentsL); @@ -6329,14 +6429,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _264_h = _source6.dtor_value; { RAST._IExpr _265_hExpr; - Defs._IOwnership _266___v121; + Defs._IOwnership _266___v147; Dafny.ISet> _267_recIdentsH; RAST._IExpr _out225; Defs._IOwnership _out226; Dafny.ISet> _out227; (this).GenExpr(_264_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out225, out _out226, out _out227); _265_hExpr = _out225; - _266___v121 = _out226; + _266___v147 = _out226; _267_recIdentsH = _out227; _259_arguments = Dafny.Sequence.Concat(_259_arguments, Dafny.Sequence.FromElements(_265_hExpr)); readIdents = Dafny.Set>.Union(readIdents, _267_recIdentsH); @@ -6466,14 +6566,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _289_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_285_paramNames, _286_paramTypesMap, Dafny.Set>.FromElements())); RAST._IExpr _290_recursiveGen; Dafny.ISet> _291_recIdents; - Defs._IEnvironment _292___v123; + Defs._IEnvironment _292___v149; RAST._IExpr _out240; Dafny.ISet> _out241; Defs._IEnvironment _out242; (this).GenStmts(_283_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _289_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out240, out _out241, out _out242); _290_recursiveGen = _out240; _291_recIdents = _out241; - _292___v123 = _out242; + _292___v149 = _out242; readIdents = Dafny.Set>.FromElements(); _291_recIdents = Dafny.Set>.Difference(_291_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_293_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); @@ -6499,15 +6599,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir after__ASSIGN_SUCH_THAT_1: ; if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_296_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { RAST._IExpr _297_selfCloned; - Defs._IOwnership _298___v124; - Dafny.ISet> _299___v125; + Defs._IOwnership _298___v150; + Dafny.ISet> _299___v151; RAST._IExpr _out243; Defs._IOwnership _out244; Dafny.ISet> _out245; (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out243, out _out244, out _out245); _297_selfCloned = _out243; - _298___v124 = _out244; - _299___v125 = _out245; + _298___v150 = _out244; + _299___v151 = _out245; _295_allReadCloned = (_295_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_297_selfCloned))); } else if (!((_285_paramNames).Contains(_296_next))) { RAST._IExpr _300_copy; @@ -6571,14 +6671,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out250 = (this).GenType((((_302_values).Select(_313_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); _314_typeGen = _out250; RAST._IExpr _315_valueGen; - Defs._IOwnership _316___v126; + Defs._IOwnership _316___v152; Dafny.ISet> _317_recIdents; RAST._IExpr _out251; Defs._IOwnership _out252; Dafny.ISet> _out253; (this).GenExpr(((_302_values).Select(_313_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out251, out _out252, out _out253); _315_valueGen = _out251; - _316___v126 = _out252; + _316___v152 = _out252; _317_recIdents = _out253; r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_302_values).Select(_313_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_314_typeGen), Std.Wrappers.Option.create_Some(_315_valueGen))); readIdents = Dafny.Set>.Union(readIdents, _317_recIdents); @@ -6615,14 +6715,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _325_iifeBody = _source0.dtor_iifeBody; { RAST._IExpr _326_valueGen; - Defs._IOwnership _327___v127; + Defs._IOwnership _327___v153; Dafny.ISet> _328_recIdents; RAST._IExpr _out259; Defs._IOwnership _out260; Dafny.ISet> _out261; (this).GenExpr(_324_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out259, out _out260, out _out261); _326_valueGen = _out259; - _327___v127 = _out260; + _327___v153 = _out260; _328_recIdents = _out261; readIdents = _328_recIdents; RAST._IType _329_valueTypeGen; @@ -6632,14 +6732,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _330_iifeVar; _330_iifeVar = Defs.__default.escapeVar(_322_name); RAST._IExpr _331_bodyGen; - Defs._IOwnership _332___v128; + Defs._IOwnership _332___v154; Dafny.ISet> _333_bodyIdents; RAST._IExpr _out263; Defs._IOwnership _out264; Dafny.ISet> _out265; (this).GenExpr(_325_iifeBody, selfIdent, (env).AddAssigned(_330_iifeVar, _329_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out263, out _out264, out _out265); _331_bodyGen = _out263; - _332___v128 = _out264; + _332___v154 = _out264; _333_bodyIdents = _out265; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_333_bodyIdents, Dafny.Set>.FromElements(_330_iifeVar))); r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _330_iifeVar, Std.Wrappers.Option.create_Some(_329_valueTypeGen), Std.Wrappers.Option.create_Some(_326_valueGen))).Then(_331_bodyGen)); @@ -6659,14 +6759,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _335_args = _source0.dtor_args; { RAST._IExpr _336_funcExpr; - Defs._IOwnership _337___v129; + Defs._IOwnership _337___v155; Dafny.ISet> _338_recIdents; RAST._IExpr _out268; Defs._IOwnership _out269; Dafny.ISet> _out270; (this).GenExpr(_334_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out268, out _out269, out _out270); _336_funcExpr = _out268; - _337___v129 = _out269; + _337___v155 = _out269; _338_recIdents = _out270; readIdents = _338_recIdents; Dafny.ISequence _339_rArgs; @@ -6704,14 +6804,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _346_variant = _source0.dtor_variant; { RAST._IExpr _347_exprGen; - Defs._IOwnership _348___v130; + Defs._IOwnership _348___v156; Dafny.ISet> _349_recIdents; RAST._IExpr _out276; Defs._IOwnership _out277; Dafny.ISet> _out278; (this).GenExpr(_344_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out276, out _out277, out _out278); _347_exprGen = _out276; - _348___v130 = _out277; + _348___v156 = _out277; _349_recIdents = _out278; RAST._IExpr _350_variantExprPath; RAST._IExpr _out279; @@ -6846,14 +6946,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _368_of = _source0.dtor_of; { RAST._IExpr _369_exprGen; - Defs._IOwnership _370___v131; + Defs._IOwnership _370___v157; Dafny.ISet> _371_recIdents; RAST._IExpr _out300; Defs._IOwnership _out301; Dafny.ISet> _out302; (this).GenExpr(_368_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out300, out _out301, out _out302); _369_exprGen = _out300; - _370___v131 = _out301; + _370___v157 = _out301; _371_recIdents = _out302; r = ((_369_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out303; @@ -6873,14 +6973,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _373_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _374_exprGen; - Defs._IOwnership _375___v132; + Defs._IOwnership _375___v158; Dafny.ISet> _376_recIdents; RAST._IExpr _out305; Defs._IOwnership _out306; Dafny.ISet> _out307; (this).GenExpr(_372_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out305, out _out306, out _out307); _374_exprGen = _out305; - _375___v132 = _out306; + _375___v158 = _out306; _376_recIdents = _out307; r = ((_374_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_373_includeDuplicates)) { @@ -6903,14 +7003,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _378_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _379_exprGen; - Defs._IOwnership _380___v133; + Defs._IOwnership _380___v159; Dafny.ISet> _381_recIdents; RAST._IExpr _out310; Defs._IOwnership _out311; Dafny.ISet> _out312; (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out310, out _out311, out _out312); _379_exprGen = _out310; - _380___v133 = _out311; + _380___v159 = _out311; _381_recIdents = _out312; r = ((_379_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_378_includeDuplicates)) { @@ -6932,14 +7032,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _382_of = _source0.dtor_of; { RAST._IExpr _383_exprGen; - Defs._IOwnership _384___v134; + Defs._IOwnership _384___v160; Dafny.ISet> _385_recIdents; RAST._IExpr _out315; Defs._IOwnership _out316; Dafny.ISet> _out317; (this).GenExpr(_382_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out315, out _out316, out _out317); _383_exprGen = _out315; - _384___v134 = _out316; + _384___v160 = _out316; _385_recIdents = _out317; r = ((((_383_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); readIdents = _385_recIdents; @@ -6957,14 +7057,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _386_of = _source0.dtor_of; { RAST._IExpr _387_exprGen; - Defs._IOwnership _388___v135; + Defs._IOwnership _388___v161; Dafny.ISet> _389_recIdents; RAST._IExpr _out320; Defs._IOwnership _out321; Dafny.ISet> _out322; (this).GenExpr(_386_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out320, out _out321, out _out322); _387_exprGen = _out320; - _388___v135 = _out321; + _388___v161 = _out321; _389_recIdents = _out322; r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_387_exprGen); readIdents = _389_recIdents; @@ -6985,24 +7085,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _393_up = _source0.dtor_up; { RAST._IExpr _394_lo; - Defs._IOwnership _395___v136; + Defs._IOwnership _395___v162; Dafny.ISet> _396_recIdentsLo; RAST._IExpr _out325; Defs._IOwnership _out326; Dafny.ISet> _out327; (this).GenExpr(_391_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out325, out _out326, out _out327); _394_lo = _out325; - _395___v136 = _out326; + _395___v162 = _out326; _396_recIdentsLo = _out327; RAST._IExpr _397_hi; - Defs._IOwnership _398___v137; + Defs._IOwnership _398___v163; Dafny.ISet> _399_recIdentsHi; RAST._IExpr _out328; Defs._IOwnership _out329; Dafny.ISet> _out330; (this).GenExpr(_392_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out328, out _out329, out _out330); _397_hi = _out328; - _398___v137 = _out329; + _398___v163 = _out329; _399_recIdentsHi = _out330; if (_393_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_394_lo, _397_hi)); @@ -7033,14 +7133,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _402_up = _source0.dtor_up; { RAST._IExpr _403_start; - Defs._IOwnership _404___v138; + Defs._IOwnership _404___v164; Dafny.ISet> _405_recIdentStart; RAST._IExpr _out334; Defs._IOwnership _out335; Dafny.ISet> _out336; (this).GenExpr(_401_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); _403_start = _out334; - _404___v138 = _out335; + _404___v164 = _out335; _405_recIdentStart = _out336; if (_402_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_403_start); @@ -7114,14 +7214,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out346 = (this).GenType(_412_elemType, Defs.GenTypeContext.@default()); _416_tpe = _out346; RAST._IExpr _417_collectionGen; - Defs._IOwnership _418___v139; + Defs._IOwnership _418___v165; Dafny.ISet> _419_recIdents; RAST._IExpr _out347; Defs._IOwnership _out348; Dafny.ISet> _out349; (this).GenExpr(_413_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out347, out _out348, out _out349); _417_collectionGen = _out347; - _418___v139 = _out348; + _418___v165 = _out348; _419_recIdents = _out349; Dafny.ISequence _420_extraAttributes; _420_extraAttributes = Dafny.Sequence.FromElements(); @@ -7144,14 +7244,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _428_dt__update_hparams_h0 = _422_newFormals; _426_newLambda = DAST.Expression.create_Lambda(_428_dt__update_hparams_h0, (_427_dt__update__tmp_h1).dtor_retType, (_427_dt__update__tmp_h1).dtor_body); RAST._IExpr _429_lambdaGen; - Defs._IOwnership _430___v140; + Defs._IOwnership _430___v166; Dafny.ISet> _431_recLambdaIdents; RAST._IExpr _out350; Defs._IOwnership _out351; Dafny.ISet> _out352; (this).GenExpr(_426_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out350, out _out351, out _out352); _429_lambdaGen = _out350; - _430___v140 = _out351; + _430___v166 = _out351; _431_recLambdaIdents = _out352; Dafny.ISequence _432_fn; if (_414_is__forall) { @@ -7258,15 +7358,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v141; - Dafny.ISet> _2___v142; + Defs._IOwnership _1___v167; + Dafny.ISet> _2___v168; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v141 = _out1; - _2___v142 = _out2; + _1___v167 = _out1; + _2___v168 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index af5997844e7..6e9fba65060 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -518,6 +518,10 @@ public static RAST._IModDecl PrintImpl(Dafny.ISequence rTy { return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, RAST.__default.DafnyPrint, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_formatter"), RAST.Type.create_BorrowedMut((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("fmt"))).MSel(Dafny.Sequence.UnicodeFromString("Formatter"))).AsType())), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("_in_seq"), RAST.Type.create_Bool())), Std.Wrappers.Option.create_Some(RAST.__default.RawType(Dafny.Sequence.UnicodeFromString("std::fmt::Result"))), Std.Wrappers.Option.create_Some(printImplBody)))))); } + public static Dafny.ISequence EqImpl(Dafny.ISequence rTypeParamsDeclsWithEq, RAST._IType datatypeType, Dafny.ISequence rTypeParams, RAST._IExpr eqImplBody) + { + return Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithEq, RAST.__default.PartialEq, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(eqImplBody)))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithEq, RAST.__default.Eq, datatypeType, Dafny.Sequence.FromElements()))); + } public static RAST._IModDecl CoerceImpl(Dafny.ISequence rTypeParamsDecls, Dafny.ISequence datatypeName, RAST._IType datatypeType, Dafny.ISequence rCoerceTypeParams, Dafny.ISequence coerceArguments, Dafny.ISequence coerceTypes, RAST._IExpr coerceImplBody) { return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Given type parameter conversions, returns a lambda to convert this structure"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("coerce"), rCoerceTypeParams, coerceArguments, Std.Wrappers.Option.create_Some(RAST.__default.Rc(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(datatypeType), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes))))), Std.Wrappers.Option.create_Some(RAST.__default.RcNew(RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("this"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes)), coerceImplBody)))))))); diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index 26a5134071a..59dfe46aec9 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -302,6 +302,9 @@ public static RAST._IType Eq { get { public static RAST._IType Hash { get { return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hash"))).MSel(Dafny.Sequence.UnicodeFromString("Hash"))).AsType(); } } + public static RAST._IType PartialEq { get { + return (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("cmp"))).MSel(Dafny.Sequence.UnicodeFromString("PartialEq"))).AsType(); + } } public static RAST._IType DafnyInt { get { return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt"))).AsType(); } } @@ -6269,6 +6272,8 @@ public interface _IExpr { _System._ITuple2, Dafny.ISequence> RightParentheses(RAST._IExpr right); Std.Wrappers._IOption> RightMostIdentifier(); Dafny.ISequence _ToString(Dafny.ISequence ind); + RAST._IExpr And(RAST._IExpr rhs2); + RAST._IExpr Equals(RAST._IExpr rhs2); RAST._IExpr Then(RAST._IExpr rhs2); RAST._IExpr Sel(Dafny.ISequence name); RAST._IExpr FSel(Dafny.ISequence name); @@ -7655,6 +7660,16 @@ public bool RightRequiresParentheses(RAST._IExpr right) { return RAST.__default.AddIndent((_128_r).dtor_content, ind); } } + public RAST._IExpr And(RAST._IExpr rhs2) { + if (object.Equals(this, RAST.Expr.create_LiteralBool(true))) { + return rhs2; + } else { + return RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("&&"), this, rhs2, DAST.Format.BinaryOpFormat.create_NoFormat()); + } + } + public RAST._IExpr Equals(RAST._IExpr rhs2) { + return RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=="), this, rhs2, DAST.Format.BinaryOpFormat.create_NoFormat()); + } public RAST._IExpr Then(RAST._IExpr rhs2) { if ((this).is_StmtExpr) { return RAST.Expr.create_StmtExpr((this).dtor_stmt, ((this).dtor_rhs).Then(rhs2)); diff --git a/Source/DafnyCore/Resolver/ModuleResolver.cs b/Source/DafnyCore/Resolver/ModuleResolver.cs index 077c6f7c03a..7bda533ed64 100644 --- a/Source/DafnyCore/Resolver/ModuleResolver.cs +++ b/Source/DafnyCore/Resolver/ModuleResolver.cs @@ -2890,26 +2890,8 @@ void MarkSCCAsNotSupportingEquality() { } foreach (var ctor in dt.Ctors) { foreach (var arg in ctor.Formals) { - var typeArg = arg.Type.AsTypeParameter; - if (typeArg != null) { - typeArg.NecessaryForEqualitySupportOfSurroundingInductiveDatatype = true; - thingsChanged = true; - } else { - var otherDt = arg.Type.AsIndDatatype; - if (otherDt != null && otherDt.EqualitySupport == IndDatatypeDecl.ES.ConsultTypeArguments) { // datatype is in a different SCC - var otherUdt = (UserDefinedType)arg.Type.NormalizeExpand(); - var i = 0; - foreach (var otherTp in otherDt.TypeArgs) { - if (otherTp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype) { - var tp = otherUdt.TypeArgs[i].AsTypeParameter; - if (tp != null) { - tp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype = true; - thingsChanged = true; - } - } - } - } - } + var type = arg.Type; + DetermineEqualitySupportType(type, ref thingsChanged); } } } @@ -2949,6 +2931,32 @@ void MarkSCCAsNotSupportingEquality() { } } + private static void DetermineEqualitySupportType(Type type, ref bool thingsChanged) + { + if (type.AsTypeParameter is {} typeArg) { + typeArg.NecessaryForEqualitySupportOfSurroundingInductiveDatatype = true; + thingsChanged = true; + } else if (type.AsMapType is {} typeMap) { + DetermineEqualitySupportType(typeMap.Range, ref thingsChanged); + } else if (type.AsIndDatatype is {} otherDt) { + if (otherDt.EqualitySupport == IndDatatypeDecl.ES.ConsultTypeArguments) { // datatype is in a different SCC + var otherUdt = (UserDefinedType)type.NormalizeExpand(); + var i = 0; + foreach (var otherTp in otherDt.TypeArgs) { + if (otherTp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype) { + var tp = otherUdt.TypeArgs[i].AsTypeParameter; + if (tp != null) { + tp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype = true; + thingsChanged = true; + } + } + + i++; + } + } + } + } + /// /// Check to see if the attribute is one that is supported by Dafny. What check performed here is, /// unfortunately, just an approximation, since the usage rules of a particular attribute is checked From 4256cced3710fbe16864e32943c851fe7be1bdc7 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Wed, 11 Dec 2024 09:47:08 +0000 Subject: [PATCH 25/69] More fixes --- Source/DafnyCore/Backends/Dafny/AST.dfy | 35 ++ .../Backends/Rust/Dafny-compiler-rust.dfy | 11 +- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 99 ++++ Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 459 +++++++++--------- .../DafnyCompilerRustUtils.cs | 12 +- .../FactorPathsOptimization.cs | 12 +- Source/DafnyCore/GeneratedFromDafny/RAST.cs | 24 +- Source/DafnyCore/Resolver/ModuleResolver.cs | 29 +- .../comp/rust/small/03-methodnamed.dfy.expect | 2 + .../comp/rust/small/04-mismatched.dfy.expect | 2 + .../comp/rust/small/05-coerce.dfy.expect | 2 + .../rust/small/10-type-parameter-equality.dfy | 51 ++ 12 files changed, 465 insertions(+), 273 deletions(-) create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 29032d7e246..1d8a70e8a26 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -203,6 +203,41 @@ module {:extern "DAST"} DAST { case _ => false } } + + function RemoveSynonyms(): Type { + match this { + case UserDefined(ResolvedType(path, typeArgs, typeKind, attributes, properMethods, extendedTypes)) => + match typeKind { + case SynonymType(typ) => + typ.RemoveSynonyms() + case _ => + var newtypeArgs := seq(|typeArgs|, i requires 0 <= i < |typeArgs| => typeArgs[i].RemoveSynonyms()); + UserDefined(ResolvedType(path, newtypeArgs, typeKind, attributes, properMethods, extendedTypes)) + } + case Tuple(arguments) => + Type.Tuple(Std.Collections.Seq.Map( + t requires t in arguments => t.RemoveSynonyms(), arguments)) + case Array(element, dims) => + Type.Array(element.RemoveSynonyms(), dims) + case Seq(element) => + Type.Seq(element.RemoveSynonyms()) + case Set(element) => + Type.Set(element.RemoveSynonyms()) + case Multiset(element) => + Type.Multiset(element.RemoveSynonyms()) + case Map(key, value) => + Type.Map(key.RemoveSynonyms(), value.RemoveSynonyms()) + case SetBuilder(element) => + Type.SetBuilder(element.RemoveSynonyms()) + case MapBuilder(key, value) => + Type.MapBuilder(key.RemoveSynonyms(), value.RemoveSynonyms()) + case Arrow(args: seq, result: Type) => + Type.Arrow(Std.Collections.Seq.Map( + t requires t in args => t.RemoveSynonyms(), args), result.RemoveSynonyms()) + case Primitive(_) | Passthrough(_) | Object() | TypeArg(_) => + this + } + } } datatype Variance = diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 79deda552c8..f2741f49777 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -2891,18 +2891,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { decreases fromTpe, toTpe // We unwrap newtypes { r := expr; + // For conversion purpose, synonyms are not desired + var fromTpe := fromTpe.RemoveSynonyms(); + var toTpe := toTpe.RemoveSynonyms(); if fromTpe == toTpe { r, resultingOwnership := FromOwnership(r, exprOwnership, expectedOwnership); return; } - if fromTpe.UserDefined? && fromTpe.resolved.kind.SynonymType? { - r, resultingOwnership := GenExprConvertTo(expr, exprOwnership, fromTpe.resolved.kind.baseType, toTpe, env, expectedOwnership); - return; - } - if toTpe.UserDefined? && toTpe.resolved.kind.SynonymType? { - r, resultingOwnership := GenExprConvertTo(expr, exprOwnership, fromTpe, toTpe.resolved.kind.baseType, env, expectedOwnership); - return; - } if NeedsUnwrappingConversion(fromTpe) { // From type is a newtype but it's not a primitive one. r := UnwrapNewtype(r, exprOwnership, fromTpe); diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 6c1772d92bd..fd8af9e3485 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -576,6 +576,7 @@ public interface _IType { bool IsDatatype(); DAST._IType GetDatatypeType(); bool Extends(DAST._IType other); + DAST._IType RemoveSynonyms(); } public abstract class Type : _IType { public Type() { @@ -964,6 +965,104 @@ public bool Extends(DAST._IType other) { return false; } } + public DAST._IType RemoveSynonyms() { + DAST._IType _source0 = this; + { + if (_source0.is_UserDefined) { + DAST._IResolvedType resolved0 = _source0.dtor_resolved; + Dafny.ISequence> _0_path = resolved0.dtor_path; + Dafny.ISequence _1_typeArgs = resolved0.dtor_typeArgs; + DAST._IResolvedTypeBase _2_typeKind = resolved0.dtor_kind; + Dafny.ISequence _3_attributes = resolved0.dtor_attributes; + Dafny.ISequence> _4_properMethods = resolved0.dtor_properMethods; + Dafny.ISequence _5_extendedTypes = resolved0.dtor_extendedTypes; + DAST._IResolvedTypeBase _source1 = _2_typeKind; + { + if (_source1.is_SynonymType) { + DAST._IType _6_typ = _source1.dtor_baseType; + return (_6_typ).RemoveSynonyms(); + } + } + { + Dafny.ISequence _7_newtypeArgs = ((System.Func>) (() => { + BigInteger dim10 = new BigInteger((_1_typeArgs).Count); + var arr10 = new DAST._IType[Dafny.Helpers.ToIntChecked(dim10, "array size exceeds memory limit")]; + for (int i10 = 0; i10 < dim10; i10++) { + var _8_i = (BigInteger) i10; + arr10[(int)(_8_i)] = ((_1_typeArgs).Select(_8_i)).RemoveSynonyms(); + } + return Dafny.Sequence.FromArray(arr10); + }))(); + return DAST.Type.create_UserDefined(DAST.ResolvedType.create(_0_path, _7_newtypeArgs, _2_typeKind, _3_attributes, _4_properMethods, _5_extendedTypes)); + } + } + } + { + if (_source0.is_Tuple) { + Dafny.ISequence _9_arguments = _source0.dtor_Tuple_a0; + return DAST.Type.create_Tuple(Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Func>>((_10_arguments) => ((System.Func)((_11_t) => { + return (_11_t).RemoveSynonyms(); +})))(_9_arguments), _9_arguments)); + } + } + { + if (_source0.is_Array) { + DAST._IType _12_element = _source0.dtor_element; + BigInteger _13_dims = _source0.dtor_dims; + return DAST.Type.create_Array((_12_element).RemoveSynonyms(), _13_dims); + } + } + { + if (_source0.is_Seq) { + DAST._IType _14_element = _source0.dtor_element; + return DAST.Type.create_Seq((_14_element).RemoveSynonyms()); + } + } + { + if (_source0.is_Set) { + DAST._IType _15_element = _source0.dtor_element; + return DAST.Type.create_Set((_15_element).RemoveSynonyms()); + } + } + { + if (_source0.is_Multiset) { + DAST._IType _16_element = _source0.dtor_element; + return DAST.Type.create_Multiset((_16_element).RemoveSynonyms()); + } + } + { + if (_source0.is_Map) { + DAST._IType _17_key = _source0.dtor_key; + DAST._IType _18_value = _source0.dtor_value; + return DAST.Type.create_Map((_17_key).RemoveSynonyms(), (_18_value).RemoveSynonyms()); + } + } + { + if (_source0.is_SetBuilder) { + DAST._IType _19_element = _source0.dtor_element; + return DAST.Type.create_SetBuilder((_19_element).RemoveSynonyms()); + } + } + { + if (_source0.is_MapBuilder) { + DAST._IType _20_key = _source0.dtor_key; + DAST._IType _21_value = _source0.dtor_value; + return DAST.Type.create_MapBuilder((_20_key).RemoveSynonyms(), (_21_value).RemoveSynonyms()); + } + } + { + if (_source0.is_Arrow) { + Dafny.ISequence _22_args = _source0.dtor_args; + DAST._IType _23_result = _source0.dtor_result; + return DAST.Type.create_Arrow(Std.Collections.Seq.__default.Map(Dafny.Helpers.Id, Func>>((_24_args) => ((System.Func)((_25_t) => { + return (_25_t).RemoveSynonyms(); +})))(_22_args), _22_args), (_23_result).RemoveSynonyms()); + } + } + { + return this; + } + } } public class Type_UserDefined : Type { public readonly DAST._IResolvedType _resolved; diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index a8b60ba045f..d73240a47fd 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -1521,43 +1521,44 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } Dafny.ISequence _118_defaultConstrainedTypeParams; _118_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - Dafny.ISequence _119_rTypeParamsDeclsWithHash; - _119_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - RAST._IExpr _120_printImplBody; - _120_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _88_printImplBodyCases); - RAST._IExpr _121_hashImplBody; - _121_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _89_hashImplBodyCases); - RAST._IExpr _122_eqImplBody; - _122_eqImplBody = RAST.Expr.create_Match(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))), _91_partialEqImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams, _120_printImplBody))); + RAST._IExpr _119_printImplBody; + _119_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _88_printImplBodyCases); + RAST._IExpr _120_hashImplBody; + _120_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _89_hashImplBodyCases); + RAST._IExpr _121_eqImplBody; + _121_eqImplBody = RAST.Expr.create_Match(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))), _91_partialEqImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams, _119_printImplBody))); if ((new BigInteger((_49_rCoerceTypeParams).Count)).Sign == 1) { - RAST._IExpr _123_coerceImplBody; - _123_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _90_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _72_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _123_coerceImplBody))); + RAST._IExpr _122_coerceImplBody; + _122_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _90_coerceImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _72_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _122_coerceImplBody))); } if ((new BigInteger((_9_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { - RAST._IType _124_instantiationType; + RAST._IType _123_instantiationType; if (_0_isRcWrapped) { - _124_instantiationType = RAST.__default.Rc(_72_datatypeType); + _123_instantiationType = RAST.__default.Rc(_72_datatypeType); } else { - _124_instantiationType = _72_datatypeType; + _123_instantiationType = _72_datatypeType; } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _72_datatypeType, _124_instantiationType, _9_singletonConstructors))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _72_datatypeType, _123_instantiationType, _9_singletonConstructors))); } if ((((c).dtor_equalitySupport).is_Always) || (((c).dtor_equalitySupport).is_ConsultTypeArguments)) { - Dafny.ISequence _125_rTypeParamsDeclsWithEq; - _125_rTypeParamsDeclsWithEq = _3_rTypeParamsDecls; + Dafny.ISequence _124_rTypeParamsDeclsWithEq; + _124_rTypeParamsDeclsWithEq = _3_rTypeParamsDecls; + Dafny.ISequence _125_rTypeParamsDeclsWithHash; + _125_rTypeParamsDeclsWithHash = _3_rTypeParamsDecls; if (((c).dtor_equalitySupport).is_ConsultTypeArguments) { BigInteger _hi11 = new BigInteger((_3_rTypeParamsDecls).Count); for (BigInteger _126_i = BigInteger.Zero; _126_i < _hi11; _126_i++) { if (((((c).dtor_typeParams).Select(_126_i)).dtor_info).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype) { - _125_rTypeParamsDeclsWithEq = Dafny.Sequence.Update(_125_rTypeParamsDeclsWithEq, _126_i, ((_125_rTypeParamsDeclsWithEq).Select(_126_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Eq, RAST.__default.Hash))); + _124_rTypeParamsDeclsWithEq = Dafny.Sequence.Update(_124_rTypeParamsDeclsWithEq, _126_i, ((_124_rTypeParamsDeclsWithEq).Select(_126_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Eq, RAST.__default.Hash))); + _125_rTypeParamsDeclsWithHash = Dafny.Sequence.Update(_125_rTypeParamsDeclsWithHash, _126_i, ((_125_rTypeParamsDeclsWithHash).Select(_126_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Hash))); } } } - s = Dafny.Sequence.Concat(s, Defs.__default.EqImpl(_125_rTypeParamsDeclsWithEq, _72_datatypeType, _2_rTypeParams, _122_eqImplBody)); + s = Dafny.Sequence.Concat(s, Defs.__default.EqImpl(_124_rTypeParamsDeclsWithEq, _72_datatypeType, _2_rTypeParams, _121_eqImplBody)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_125_rTypeParamsDeclsWithHash, _72_datatypeType, _120_hashImplBody))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_119_rTypeParamsDeclsWithHash, _72_datatypeType, _121_hashImplBody))); if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { RAST._IExpr _127_structName; _127_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); @@ -3405,9 +3406,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. DAST._IExpression _source0 = e; { if (_source0.is_Literal) { - DAST._ILiteral _h630 = _source0.dtor_Literal_a0; - if (_h630.is_BoolLiteral) { - bool _0_b = _h630.dtor_BoolLiteral_a0; + DAST._ILiteral _h670 = _source0.dtor_Literal_a0; + if (_h670.is_BoolLiteral) { + bool _0_b = _h670.dtor_BoolLiteral_a0; { RAST._IExpr _out0; Defs._IOwnership _out1; @@ -3423,10 +3424,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h631 = _source0.dtor_Literal_a0; - if (_h631.is_IntLiteral) { - Dafny.ISequence _1_i = _h631.dtor_IntLiteral_a0; - DAST._IType _2_t = _h631.dtor_IntLiteral_a1; + DAST._ILiteral _h671 = _source0.dtor_Literal_a0; + if (_h671.is_IntLiteral) { + Dafny.ISequence _1_i = _h671.dtor_IntLiteral_a0; + DAST._IType _2_t = _h671.dtor_IntLiteral_a1; { DAST._IType _source1 = _2_t; { @@ -3469,11 +3470,11 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h632 = _source0.dtor_Literal_a0; - if (_h632.is_DecLiteral) { - Dafny.ISequence _5_n = _h632.dtor_DecLiteral_a0; - Dafny.ISequence _6_d = _h632.dtor_DecLiteral_a1; - DAST._IType _7_t = _h632.dtor_DecLiteral_a2; + DAST._ILiteral _h672 = _source0.dtor_Literal_a0; + if (_h672.is_DecLiteral) { + Dafny.ISequence _5_n = _h672.dtor_DecLiteral_a0; + Dafny.ISequence _6_d = _h672.dtor_DecLiteral_a1; + DAST._IType _7_t = _h672.dtor_DecLiteral_a2; { DAST._IType _source2 = _7_t; { @@ -3512,10 +3513,10 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h633 = _source0.dtor_Literal_a0; - if (_h633.is_StringLiteral) { - Dafny.ISequence _10_l = _h633.dtor_StringLiteral_a0; - bool _11_verbatim = _h633.dtor_verbatim; + DAST._ILiteral _h673 = _source0.dtor_Literal_a0; + if (_h673.is_StringLiteral) { + Dafny.ISequence _10_l = _h673.dtor_StringLiteral_a0; + bool _11_verbatim = _h673.dtor_verbatim; { r = (((RAST.__default.dafny__runtime).MSel((this).string__of)).AsExpr()).Apply1(RAST.Expr.create_LiteralString(_10_l, false, _11_verbatim)); RAST._IExpr _out8; @@ -3532,9 +3533,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h634 = _source0.dtor_Literal_a0; - if (_h634.is_CharLiteralUTF16) { - BigInteger _12_c = _h634.dtor_CharLiteralUTF16_a0; + DAST._ILiteral _h674 = _source0.dtor_Literal_a0; + if (_h674.is_CharLiteralUTF16) { + BigInteger _12_c = _h674.dtor_CharLiteralUTF16_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(_12_c)); r = RAST.Expr.create_TypeAscription(r, RAST.Type.create_U16()); @@ -3553,9 +3554,9 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } { if (_source0.is_Literal) { - DAST._ILiteral _h635 = _source0.dtor_Literal_a0; - if (_h635.is_CharLiteral) { - Dafny.Rune _13_c = _h635.dtor_CharLiteral_a0; + DAST._ILiteral _h675 = _source0.dtor_Literal_a0; + if (_h675.is_CharLiteral) { + Dafny.Rune _13_c = _h675.dtor_CharLiteral_a0; { r = RAST.Expr.create_LiteralInt(Std.Strings.__default.OfNat(new BigInteger((_13_c).Value))); if (!(((this).charType).is_UTF32)) { @@ -3577,8 +3578,8 @@ public void GenExprLiteral(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs. } } { - DAST._ILiteral _h636 = _source0.dtor_Literal_a0; - DAST._IType _14_tpe = _h636.dtor_Null_a0; + DAST._ILiteral _h676 = _source0.dtor_Literal_a0; + DAST._IType _14_tpe = _h676.dtor_Null_a0; { RAST._IType _15_tpeGen; RAST._IType _out14; @@ -4026,7 +4027,11 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D r = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); r = expr; - if (object.Equals(fromTpe, toTpe)) { + DAST._IType _0_fromTpe; + _0_fromTpe = (fromTpe).RemoveSynonyms(); + DAST._IType _1_toTpe; + _1_toTpe = (toTpe).RemoveSynonyms(); + if (object.Equals(_0_fromTpe, _1_toTpe)) { RAST._IExpr _out0; Defs._IOwnership _out1; (this).FromOwnership(r, exprOwnership, expectedOwnership, out _out0, out _out1); @@ -4034,75 +4039,59 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D resultingOwnership = _out1; return ; } - if (((fromTpe).is_UserDefined) && ((((fromTpe).dtor_resolved).dtor_kind).is_SynonymType)) { + if (Defs.__default.NeedsUnwrappingConversion(_0_fromTpe)) { RAST._IExpr _out2; - Defs._IOwnership _out3; - (this).GenExprConvertTo(expr, exprOwnership, (((fromTpe).dtor_resolved).dtor_kind).dtor_baseType, toTpe, env, expectedOwnership, out _out2, out _out3); + _out2 = (this).UnwrapNewtype(r, exprOwnership, _0_fromTpe); r = _out2; - resultingOwnership = _out3; - return ; - } - if (((toTpe).is_UserDefined) && ((((toTpe).dtor_resolved).dtor_kind).is_SynonymType)) { - RAST._IExpr _out4; - Defs._IOwnership _out5; - (this).GenExprConvertTo(expr, exprOwnership, fromTpe, (((toTpe).dtor_resolved).dtor_kind).dtor_baseType, env, expectedOwnership, out _out4, out _out5); - r = _out4; - resultingOwnership = _out5; + RAST._IExpr _out3; + Defs._IOwnership _out4; + (this).GenExprConvertTo(r, exprOwnership, (((_0_fromTpe).dtor_resolved).dtor_kind).dtor_baseType, _1_toTpe, env, expectedOwnership, out _out3, out _out4); + r = _out3; + resultingOwnership = _out4; return ; } - if (Defs.__default.NeedsUnwrappingConversion(fromTpe)) { - RAST._IExpr _out6; - _out6 = (this).UnwrapNewtype(r, exprOwnership, fromTpe); - r = _out6; + if (Defs.__default.NeedsUnwrappingConversion(_1_toTpe)) { + DAST._IResolvedTypeBase _2_toKind; + _2_toKind = ((_1_toTpe).dtor_resolved).dtor_kind; + RAST._IExpr _out5; + Defs._IOwnership _out6; + (this).GenExprConvertTo(r, exprOwnership, _0_fromTpe, (_2_toKind).dtor_baseType, env, expectedOwnership, out _out5, out _out6); + r = _out5; + resultingOwnership = _out6; RAST._IExpr _out7; - Defs._IOwnership _out8; - (this).GenExprConvertTo(r, exprOwnership, (((fromTpe).dtor_resolved).dtor_kind).dtor_baseType, toTpe, env, expectedOwnership, out _out7, out _out8); + _out7 = (this).WrapWithNewtype(r, resultingOwnership, _1_toTpe); r = _out7; - resultingOwnership = _out8; - return ; - } - if (Defs.__default.NeedsUnwrappingConversion(toTpe)) { - DAST._IResolvedTypeBase _0_toKind; - _0_toKind = ((toTpe).dtor_resolved).dtor_kind; - RAST._IExpr _out9; - Defs._IOwnership _out10; - (this).GenExprConvertTo(r, exprOwnership, fromTpe, (_0_toKind).dtor_baseType, env, expectedOwnership, out _out9, out _out10); - r = _out9; - resultingOwnership = _out10; - RAST._IExpr _out11; - _out11 = (this).WrapWithNewtype(r, resultingOwnership, toTpe); - r = _out11; - RAST._IExpr _out12; - Defs._IOwnership _out13; - (this).FromOwnership(r, resultingOwnership, expectedOwnership, out _out12, out _out13); - r = _out12; - resultingOwnership = _out13; + RAST._IExpr _out8; + Defs._IOwnership _out9; + (this).FromOwnership(r, resultingOwnership, expectedOwnership, out _out8, out _out9); + r = _out8; + resultingOwnership = _out9; return ; } - Std.Wrappers._IOption _1_unwrappedFromType; - _1_unwrappedFromType = Defs.__default.GetUnwrappedBoundedRustType(fromTpe); - Std.Wrappers._IOption _2_unwrappedToType; - _2_unwrappedToType = Defs.__default.GetUnwrappedBoundedRustType(toTpe); - if ((_2_unwrappedToType).is_Some) { - RAST._IType _3_boundedToType; - _3_boundedToType = (_2_unwrappedToType).dtor_value; - if ((_1_unwrappedFromType).is_Some) { - RAST._IExpr _out14; - _out14 = (this).UnwrapNewtype(r, exprOwnership, fromTpe); - r = _out14; - Defs._IOwnership _4_inOwnership; - _4_inOwnership = exprOwnership; - if (!object.Equals((_1_unwrappedFromType).dtor_value, (_2_unwrappedToType).dtor_value)) { - RAST._IType _5_asType; - _5_asType = _3_boundedToType; - if (object.Equals(_4_inOwnership, Defs.Ownership.create_OwnershipBorrowed())) { + Std.Wrappers._IOption _3_unwrappedFromType; + _3_unwrappedFromType = Defs.__default.GetUnwrappedBoundedRustType(_0_fromTpe); + Std.Wrappers._IOption _4_unwrappedToType; + _4_unwrappedToType = Defs.__default.GetUnwrappedBoundedRustType(_1_toTpe); + if ((_4_unwrappedToType).is_Some) { + RAST._IType _5_boundedToType; + _5_boundedToType = (_4_unwrappedToType).dtor_value; + if ((_3_unwrappedFromType).is_Some) { + RAST._IExpr _out10; + _out10 = (this).UnwrapNewtype(r, exprOwnership, _0_fromTpe); + r = _out10; + Defs._IOwnership _6_inOwnership; + _6_inOwnership = exprOwnership; + if (!object.Equals((_3_unwrappedFromType).dtor_value, (_4_unwrappedToType).dtor_value)) { + RAST._IType _7_asType; + _7_asType = _5_boundedToType; + if (object.Equals(_6_inOwnership, Defs.Ownership.create_OwnershipBorrowed())) { RAST._IExpr _source0 = r; { if (_source0.is_UnaryOp) { Dafny.ISequence op10 = _source0.dtor_op1; if (object.Equals(op10, Dafny.Sequence.UnicodeFromString("&"))) { - RAST._IExpr _6_underlying = _source0.dtor_underlying; - r = _6_underlying; + RAST._IExpr _8_underlying = _source0.dtor_underlying; + r = _8_underlying; goto after_match0; } } @@ -4112,101 +4101,101 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D } after_match0: ; } - r = RAST.Expr.create_TypeAscription(r, _5_asType); - _4_inOwnership = Defs.Ownership.create_OwnershipOwned(); - } - RAST._IExpr _out15; - _out15 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); - r = _out15; - RAST._IExpr _out16; - Defs._IOwnership _out17; - (this).FromOwnership(r, _4_inOwnership, expectedOwnership, out _out16, out _out17); - r = _out16; - resultingOwnership = _out17; + r = RAST.Expr.create_TypeAscription(r, _7_asType); + _6_inOwnership = Defs.Ownership.create_OwnershipOwned(); + } + RAST._IExpr _out11; + _out11 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), _1_toTpe); + r = _out11; + RAST._IExpr _out12; + Defs._IOwnership _out13; + (this).FromOwnership(r, _6_inOwnership, expectedOwnership, out _out12, out _out13); + r = _out12; + resultingOwnership = _out13; return ; } - if ((fromTpe).IsPrimitiveInt()) { + if ((_0_fromTpe).IsPrimitiveInt()) { if (object.Equals(exprOwnership, Defs.Ownership.create_OwnershipBorrowed())) { r = (r).Clone(); } - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("truncate!"))).AsExpr()).Apply(Dafny.Sequence.FromElements(r, RAST.Expr.create_ExprFromType(_3_boundedToType))); - RAST._IExpr _out18; - _out18 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); - r = _out18; - RAST._IExpr _out19; - Defs._IOwnership _out20; - (this).FromOwned(r, expectedOwnership, out _out19, out _out20); - r = _out19; - resultingOwnership = _out20; + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("truncate!"))).AsExpr()).Apply(Dafny.Sequence.FromElements(r, RAST.Expr.create_ExprFromType(_5_boundedToType))); + RAST._IExpr _out14; + _out14 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), _1_toTpe); + r = _out14; + RAST._IExpr _out15; + Defs._IOwnership _out16; + (this).FromOwned(r, expectedOwnership, out _out15, out _out16); + r = _out15; + resultingOwnership = _out16; return ; } - if (object.Equals(fromTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { - r = RAST.Expr.create_TypeAscription((r).Sel(Dafny.Sequence.UnicodeFromString("0")), _3_boundedToType); - RAST._IExpr _out21; - _out21 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); - r = _out21; - RAST._IExpr _out22; - Defs._IOwnership _out23; - (this).FromOwned(r, expectedOwnership, out _out22, out _out23); - r = _out22; - resultingOwnership = _out23; + if (object.Equals(_0_fromTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { + r = RAST.Expr.create_TypeAscription((r).Sel(Dafny.Sequence.UnicodeFromString("0")), _5_boundedToType); + RAST._IExpr _out17; + _out17 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), _1_toTpe); + r = _out17; + RAST._IExpr _out18; + Defs._IOwnership _out19; + (this).FromOwned(r, expectedOwnership, out _out18, out _out19); + r = _out18; + resultingOwnership = _out19; return ; } - RAST._IType _7_fromTpeRust; - RAST._IType _out24; - _out24 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); - _7_fromTpeRust = _out24; - RAST._IExpr _out25; - _out25 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), (_7_fromTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_3_boundedToType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - r = _out25; - RAST._IExpr _out26; - Defs._IOwnership _out27; - (this).FromOwned(r, expectedOwnership, out _out26, out _out27); - r = _out26; - resultingOwnership = _out27; + RAST._IType _9_fromTpeRust; + RAST._IType _out20; + _out20 = (this).GenType(_0_fromTpe, Defs.GenTypeContext.@default()); + _9_fromTpeRust = _out20; + RAST._IExpr _out21; + _out21 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), (_9_fromTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_5_boundedToType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + r = _out21; + RAST._IExpr _out22; + Defs._IOwnership _out23; + (this).FromOwned(r, expectedOwnership, out _out22, out _out23); + r = _out22; + resultingOwnership = _out23; return ; } - if ((_1_unwrappedFromType).is_Some) { - if (!((((fromTpe).dtor_resolved).dtor_kind).dtor_erase)) { + if ((_3_unwrappedFromType).is_Some) { + if (!((((_0_fromTpe).dtor_resolved).dtor_kind).dtor_erase)) { r = (r).Sel(Dafny.Sequence.UnicodeFromString("0")); } - if (object.Equals(toTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { + if (object.Equals(_1_toTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { + RAST._IExpr _out24; + Defs._IOwnership _out25; + (this).FromOwnership((((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsExpr()).Apply1(RAST.Expr.create_TypeAscription(r, (this).DafnyCharUnderlying)), exprOwnership, expectedOwnership, out _out24, out _out25); + r = _out24; + resultingOwnership = _out25; + return ; + } + if ((_1_toTpe).IsPrimitiveInt()) { + RAST._IExpr _out26; + Defs._IOwnership _out27; + (this).FromOwnership(r, exprOwnership, Defs.Ownership.create_OwnershipOwned(), out _out26, out _out27); + r = _out26; + resultingOwnership = _out27; + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(r); RAST._IExpr _out28; Defs._IOwnership _out29; - (this).FromOwnership((((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsExpr()).Apply1(RAST.Expr.create_TypeAscription(r, (this).DafnyCharUnderlying)), exprOwnership, expectedOwnership, out _out28, out _out29); + (this).FromOwned(r, expectedOwnership, out _out28, out _out29); r = _out28; resultingOwnership = _out29; return ; } - if ((toTpe).IsPrimitiveInt()) { - RAST._IExpr _out30; - Defs._IOwnership _out31; - (this).FromOwnership(r, exprOwnership, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31); - r = _out30; - resultingOwnership = _out31; - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(r); - RAST._IExpr _out32; - Defs._IOwnership _out33; - (this).FromOwned(r, expectedOwnership, out _out32, out _out33); - r = _out32; - resultingOwnership = _out33; - return ; - } - RAST._IType _8_toTpeRust; - RAST._IType _out34; - _out34 = (this).GenType(toTpe, Defs.GenTypeContext.@default()); - _8_toTpeRust = _out34; - RAST._IExpr _out35; - _out35 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), ((_1_unwrappedFromType).dtor_value)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_8_toTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - r = _out35; - RAST._IExpr _out36; - Defs._IOwnership _out37; - (this).FromOwned(r, expectedOwnership, out _out36, out _out37); - r = _out36; - resultingOwnership = _out37; + RAST._IType _10_toTpeRust; + RAST._IType _out30; + _out30 = (this).GenType(_1_toTpe, Defs.GenTypeContext.@default()); + _10_toTpeRust = _out30; + RAST._IExpr _out31; + _out31 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), ((_3_unwrappedFromType).dtor_value)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_10_toTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + r = _out31; + RAST._IExpr _out32; + Defs._IOwnership _out33; + (this).FromOwned(r, expectedOwnership, out _out32, out _out33); + r = _out32; + resultingOwnership = _out33; return ; } - _System._ITuple2 _source1 = _System.Tuple2.create(fromTpe, toTpe); + _System._ITuple2 _source1 = _System.Tuple2.create(_0_fromTpe, _1_toTpe); { DAST._IType _00 = _source1.dtor__0; if (_00.is_Primitive) { @@ -4218,11 +4207,11 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D if (_h71.is_Real) { { r = RAST.__default.RcNew(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("BigRational"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("from_integer"))).Apply1(r)); - RAST._IExpr _out38; - Defs._IOwnership _out39; - (this).FromOwned(r, expectedOwnership, out _out38, out _out39); - r = _out38; - resultingOwnership = _out39; + RAST._IExpr _out34; + Defs._IOwnership _out35; + (this).FromOwned(r, expectedOwnership, out _out34, out _out35); + r = _out34; + resultingOwnership = _out35; } goto after_match1; } @@ -4241,11 +4230,11 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D if (_h73.is_Int) { { r = (((RAST.__default.dafny__runtime).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("dafny_rational_to_int"))).Apply1(r); - RAST._IExpr _out40; - Defs._IOwnership _out41; - (this).FromOwned(r, expectedOwnership, out _out40, out _out41); - r = _out40; - resultingOwnership = _out41; + RAST._IExpr _out36; + Defs._IOwnership _out37; + (this).FromOwned(r, expectedOwnership, out _out36, out _out37); + r = _out36; + resultingOwnership = _out37; } goto after_match1; } @@ -4263,29 +4252,29 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D DAST._IPrimitive _h75 = _12.dtor_Primitive_a0; if (_h75.is_Char) { { - RAST._IType _9_rhsType; - RAST._IType _out42; - _out42 = (this).GenType(toTpe, Defs.GenTypeContext.@default()); - _9_rhsType = _out42; - RAST._IType _10_uType; + RAST._IType _11_rhsType; + RAST._IType _out38; + _out38 = (this).GenType(_1_toTpe, Defs.GenTypeContext.@default()); + _11_rhsType = _out38; + RAST._IType _12_uType; if (((this).charType).is_UTF32) { - _10_uType = RAST.Type.create_U32(); + _12_uType = RAST.Type.create_U32(); } else { - _10_uType = RAST.Type.create_U16(); + _12_uType = RAST.Type.create_U16(); } if (!object.Equals(exprOwnership, Defs.Ownership.create_OwnershipOwned())) { r = (r).Clone(); } - r = ((((RAST.Expr.create_TraitCast(_10_uType, ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("NumCast"))).AsType())).FSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(r)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0(); + r = ((((RAST.Expr.create_TraitCast(_12_uType, ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("NumCast"))).AsType())).FSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(r)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0(); if (((this).charType).is_UTF32) { r = ((((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("char"))).FSel(Dafny.Sequence.UnicodeFromString("from_u32"))).Apply1(r)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0(); } r = (((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsExpr()).Apply1(r); - RAST._IExpr _out43; - Defs._IOwnership _out44; - (this).FromOwned(r, expectedOwnership, out _out43, out _out44); - r = _out43; - resultingOwnership = _out44; + RAST._IExpr _out39; + Defs._IOwnership _out40; + (this).FromOwned(r, expectedOwnership, out _out39, out _out40); + r = _out39; + resultingOwnership = _out40; } goto after_match1; } @@ -4303,16 +4292,16 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D DAST._IPrimitive _h77 = _13.dtor_Primitive_a0; if (_h77.is_Int) { { - RAST._IType _11_rhsType; - RAST._IType _out45; - _out45 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); - _11_rhsType = _out45; + RAST._IType _13_rhsType; + RAST._IType _out41; + _out41 = (this).GenType(_0_fromTpe, Defs.GenTypeContext.@default()); + _13_rhsType = _out41; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1((r).Sel(Dafny.Sequence.UnicodeFromString("0"))); - RAST._IExpr _out46; - Defs._IOwnership _out47; - (this).FromOwned(r, expectedOwnership, out _out46, out _out47); - r = _out46; - resultingOwnership = _out47; + RAST._IExpr _out42; + Defs._IOwnership _out43; + (this).FromOwned(r, expectedOwnership, out _out42, out _out43); + r = _out42; + resultingOwnership = _out43; } goto after_match1; } @@ -4322,11 +4311,11 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D } { { - RAST._IExpr _out48; - Defs._IOwnership _out49; - (this).GenExprConvertOther(expr, exprOwnership, fromTpe, toTpe, env, expectedOwnership, out _out48, out _out49); - r = _out48; - resultingOwnership = _out49; + RAST._IExpr _out44; + Defs._IOwnership _out45; + (this).GenExprConvertOther(expr, exprOwnership, _0_fromTpe, _1_toTpe, env, expectedOwnership, out _out44, out _out45); + r = _out44; + resultingOwnership = _out45; } } after_match1: ; @@ -4413,43 +4402,43 @@ public bool SameTypesButDifferentTypeParameters(DAST._IType fromType, RAST._ITyp Dafny.ISequence _6_indices = ((((fromType).is_UserDefined) && ((((fromType).dtor_resolved).dtor_kind).is_Datatype)) ? (Std.Collections.Seq.__default.Filter(Dafny.Helpers.Id>>((_7_fromTpe, _8_fromType) => ((System.Func)((_9_i) => { return ((((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((_7_fromTpe).dtor_arguments).Count)))) ? (!(((_9_i).Sign != -1) && ((_9_i) < (new BigInteger(((((_8_fromType).dtor_resolved).dtor_kind).dtor_info).Count)))) || (!(((((((_8_fromType).dtor_resolved).dtor_kind).dtor_info).Select(_9_i)).dtor_variance).is_Nonvariant))) : (false)); })))(fromTpe, fromType), ((System.Func>) (() => { - BigInteger dim14 = new BigInteger(((fromTpe).dtor_arguments).Count); - var arr14 = new BigInteger[Dafny.Helpers.ToIntChecked(dim14, "array size exceeds memory limit")]; - for (int i14 = 0; i14 < dim14; i14++) { - var _10_i = (BigInteger) i14; - arr14[(int)(_10_i)] = _10_i; - } - return Dafny.Sequence.FromArray(arr14); - }))())) : (((System.Func>) (() => { BigInteger dim15 = new BigInteger(((fromTpe).dtor_arguments).Count); var arr15 = new BigInteger[Dafny.Helpers.ToIntChecked(dim15, "array size exceeds memory limit")]; for (int i15 = 0; i15 < dim15; i15++) { - var _11_i = (BigInteger) i15; - arr15[(int)(_11_i)] = _11_i; + var _10_i = (BigInteger) i15; + arr15[(int)(_10_i)] = _10_i; } return Dafny.Sequence.FromArray(arr15); + }))())) : (((System.Func>) (() => { + BigInteger dim16 = new BigInteger(((fromTpe).dtor_arguments).Count); + var arr16 = new BigInteger[Dafny.Helpers.ToIntChecked(dim16, "array size exceeds memory limit")]; + for (int i16 = 0; i16 < dim16; i16++) { + var _11_i = (BigInteger) i16; + arr16[(int)(_11_i)] = _11_i; + } + return Dafny.Sequence.FromArray(arr16); }))())); Std.Wrappers._IResult, _System._ITuple5,RAST._IExpr>>> _12_valueOrError1 = (this).SeqResultToResultSeq,RAST._IExpr>>>(((System.Func,RAST._IExpr>>>>>) (() => { - BigInteger dim16 = new BigInteger((_6_indices).Count); - var arr16 = new Std.Wrappers._IResult,RAST._IExpr>>>[Dafny.Helpers.ToIntChecked(dim16, "array size exceeds memory limit")]; - for (int i16 = 0; i16 < dim16; i16++) { - var _13_j = (BigInteger) i16; - arr16[(int)(_13_j)] = Dafny.Helpers.Let,RAST._IExpr>>>>((_6_indices).Select(_13_j), _pat_let27_0 => Dafny.Helpers.Let,RAST._IExpr>>>>(_pat_let27_0, _14_i => (this).UpcastConversionLambda((((_pat_let_tv0).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv1).dtor_arguments).Select(_14_i), (((_pat_let_tv2).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv3).dtor_arguments).Select(_14_i), _pat_let_tv4))); + BigInteger dim17 = new BigInteger((_6_indices).Count); + var arr17 = new Std.Wrappers._IResult,RAST._IExpr>>>[Dafny.Helpers.ToIntChecked(dim17, "array size exceeds memory limit")]; + for (int i17 = 0; i17 < dim17; i17++) { + var _13_j = (BigInteger) i17; + arr17[(int)(_13_j)] = Dafny.Helpers.Let,RAST._IExpr>>>>((_6_indices).Select(_13_j), _pat_let27_0 => Dafny.Helpers.Let,RAST._IExpr>>>>(_pat_let27_0, _14_i => (this).UpcastConversionLambda((((_pat_let_tv0).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv1).dtor_arguments).Select(_14_i), (((_pat_let_tv2).dtor_resolved).dtor_typeArgs).Select(_14_i), ((_pat_let_tv3).dtor_arguments).Select(_14_i), _pat_let_tv4))); } - return Dafny.Sequence,RAST._IExpr>>>>.FromArray(arr16); + return Dafny.Sequence,RAST._IExpr>>>>.FromArray(arr17); }))()); if ((_12_valueOrError1).IsFailure()) { return (_12_valueOrError1).PropagateFailure(); } else { Dafny.ISequence _15_lambdas = (_12_valueOrError1).Extract(); return Std.Wrappers.Result,RAST._IExpr>>>.create_Success((((RAST.Expr.create_ExprFromType((fromTpe).dtor_baseName)).ApplyType(((System.Func>) (() => { - BigInteger dim17 = new BigInteger(((fromTpe).dtor_arguments).Count); - var arr17 = new RAST._IType[Dafny.Helpers.ToIntChecked(dim17, "array size exceeds memory limit")]; - for (int i17 = 0; i17 < dim17; i17++) { - var _16_i = (BigInteger) i17; - arr17[(int)(_16_i)] = ((fromTpe).dtor_arguments).Select(_16_i); + BigInteger dim18 = new BigInteger(((fromTpe).dtor_arguments).Count); + var arr18 = new RAST._IType[Dafny.Helpers.ToIntChecked(dim18, "array size exceeds memory limit")]; + for (int i18 = 0; i18 < dim18; i18++) { + var _16_i = (BigInteger) i18; + arr18[(int)(_16_i)] = ((fromTpe).dtor_arguments).Select(_16_i); } - return Dafny.Sequence.FromArray(arr17); + return Dafny.Sequence.FromArray(arr18); }))())).FSel(Dafny.Sequence.UnicodeFromString("coerce"))).Apply(_15_lambdas)); } } else if (((((fromTpe).IsBuiltinCollection()) && ((toTpe).IsBuiltinCollection())) && ((this).IsBuiltinCollection(fromType))) && ((this).IsBuiltinCollection(toType))) { diff --git a/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs b/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs index 061db1db0df..aea446e0c0b 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs @@ -254,13 +254,13 @@ public RAST._IMod ToRust() { })), ((this).dtor_submodules).dtor_keys); RAST._IMod _2_dt__update__tmp_h0 = (this).dtor_existingMod; Dafny.ISequence _3_dt__update_hbody_h0 = Dafny.Sequence.Concat(((this).dtor_existingMod).dtor_body, ((System.Func>) (() => { - BigInteger dim13 = new BigInteger((_0_keysWithContent).Count); - var arr13 = new RAST._IModDecl[Dafny.Helpers.ToIntChecked(dim13, "array size exceeds memory limit")]; - for (int i13 = 0; i13 < dim13; i13++) { - var _4_i = (BigInteger) i13; - arr13[(int)(_4_i)] = Dafny.Helpers.Let, RAST._IModDecl>((_0_keysWithContent).Select(_4_i), _pat_let23_0 => Dafny.Helpers.Let, RAST._IModDecl>(_pat_let23_0, _5_moduleName => Dafny.Helpers.Let((Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select(((this).dtor_submodules).dtor_values,_5_moduleName)).ToRust(), _pat_let24_0 => Dafny.Helpers.Let(_pat_let24_0, _6_submodule => RAST.ModDecl.create_ModDecl(_6_submodule))))); + BigInteger dim14 = new BigInteger((_0_keysWithContent).Count); + var arr14 = new RAST._IModDecl[Dafny.Helpers.ToIntChecked(dim14, "array size exceeds memory limit")]; + for (int i14 = 0; i14 < dim14; i14++) { + var _4_i = (BigInteger) i14; + arr14[(int)(_4_i)] = Dafny.Helpers.Let, RAST._IModDecl>((_0_keysWithContent).Select(_4_i), _pat_let23_0 => Dafny.Helpers.Let, RAST._IModDecl>(_pat_let23_0, _5_moduleName => Dafny.Helpers.Let((Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select(((this).dtor_submodules).dtor_values,_5_moduleName)).ToRust(), _pat_let24_0 => Dafny.Helpers.Let(_pat_let24_0, _6_submodule => RAST.ModDecl.create_ModDecl(_6_submodule))))); } - return Dafny.Sequence.FromArray(arr13); + return Dafny.Sequence.FromArray(arr14); }))()); return RAST.Mod.create_Mod((_2_dt__update__tmp_h0).dtor_docString, (_2_dt__update__tmp_h0).dtor_attributes, (_2_dt__update__tmp_h0).dtor_name, _3_dt__update_hbody_h0); } diff --git a/Source/DafnyCore/GeneratedFromDafny/FactorPathsOptimization.cs b/Source/DafnyCore/GeneratedFromDafny/FactorPathsOptimization.cs index 2308d3c7675..4aec8e55f6b 100644 --- a/Source/DafnyCore/GeneratedFromDafny/FactorPathsOptimization.cs +++ b/Source/DafnyCore/GeneratedFromDafny/FactorPathsOptimization.cs @@ -328,13 +328,13 @@ public FactorPathsOptimization._IMapping Add(Dafny.ISequence k, RAST return ((_1_finalReplacement).Contains(_3_key)) && (!object.Equals(Dafny.Map, RAST._IPath>.Select(_1_finalReplacement,_3_key), _2_SelfPath)); })))(finalReplacement, SelfPath), (this).dtor_keys); return ((System.Func>) (() => { - BigInteger dim12 = new BigInteger((_0_toUse).Count); - var arr12 = new RAST._IModDecl[Dafny.Helpers.ToIntChecked(dim12, "array size exceeds memory limit")]; - for (int i12 = 0; i12 < dim12; i12++) { - var _4_i = (BigInteger) i12; - arr12[(int)(_4_i)] = RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (Dafny.Map, RAST._IPath>.Select(finalReplacement,(_0_toUse).Select(_4_i))).MSel((_0_toUse).Select(_4_i)))); + BigInteger dim13 = new BigInteger((_0_toUse).Count); + var arr13 = new RAST._IModDecl[Dafny.Helpers.ToIntChecked(dim13, "array size exceeds memory limit")]; + for (int i13 = 0; i13 < dim13; i13++) { + var _4_i = (BigInteger) i13; + arr13[(int)(_4_i)] = RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (Dafny.Map, RAST._IPath>.Select(finalReplacement,(_0_toUse).Select(_4_i))).MSel((_0_toUse).Select(_4_i)))); } - return Dafny.Sequence.FromArray(arr12); + return Dafny.Sequence.FromArray(arr13); }))(); } } diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index 59dfe46aec9..58e2aa62102 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -85,13 +85,13 @@ public static RAST._IType SystemTupleType(Dafny.ISequence elements) public static RAST._IExpr SystemTuple(Dafny.ISequence elements) { Dafny.ISequence _0_size = Std.Strings.__default.OfNat(new BigInteger((elements).Count)); return RAST.Expr.create_StructBuild(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("_System"))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Tuple"), _0_size))).MSel(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_T"), _0_size))).AsExpr(), ((System.Func>) (() => { - BigInteger dim10 = new BigInteger((elements).Count); - var arr10 = new RAST._IAssignIdentifier[Dafny.Helpers.ToIntChecked(dim10, "array size exceeds memory limit")]; - for (int i10 = 0; i10 < dim10; i10++) { - var _1_i = (BigInteger) i10; - arr10[(int)(_1_i)] = RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), Std.Strings.__default.OfNat(_1_i)), (elements).Select(_1_i)); + BigInteger dim11 = new BigInteger((elements).Count); + var arr11 = new RAST._IAssignIdentifier[Dafny.Helpers.ToIntChecked(dim11, "array size exceeds memory limit")]; + for (int i11 = 0; i11 < dim11; i11++) { + var _1_i = (BigInteger) i11; + arr11[(int)(_1_i)] = RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), Std.Strings.__default.OfNat(_1_i)), (elements).Select(_1_i)); } - return Dafny.Sequence.FromArray(arr10); + return Dafny.Sequence.FromArray(arr11); }))()); } public static RAST._IType MaybeUninitType(RAST._IType underlying) { @@ -2289,13 +2289,13 @@ public Dafny.ISequence dtor_types { public abstract _IFields DowncastClone(); public RAST._IFields ToNamelessFields() { return RAST.Fields.create_NamelessFields(((System.Func>) (() => { - BigInteger dim11 = new BigInteger(((this).dtor_fields).Count); - var arr11 = new RAST._INamelessField[Dafny.Helpers.ToIntChecked(dim11, "array size exceeds memory limit")]; - for (int i11 = 0; i11 < dim11; i11++) { - var _0_i = (BigInteger) i11; - arr11[(int)(_0_i)] = (((this).dtor_fields).Select(_0_i)).ToNamelessField(); + BigInteger dim12 = new BigInteger(((this).dtor_fields).Count); + var arr12 = new RAST._INamelessField[Dafny.Helpers.ToIntChecked(dim12, "array size exceeds memory limit")]; + for (int i12 = 0; i12 < dim12; i12++) { + var _0_i = (BigInteger) i12; + arr12[(int)(_0_i)] = (((this).dtor_fields).Select(_0_i)).ToNamelessField(); } - return Dafny.Sequence.FromArray(arr11); + return Dafny.Sequence.FromArray(arr12); }))()); } public Dafny.ISequence _ToString(Dafny.ISequence ind, bool newLine) diff --git a/Source/DafnyCore/Resolver/ModuleResolver.cs b/Source/DafnyCore/Resolver/ModuleResolver.cs index 7bda533ed64..8404d79af16 100644 --- a/Source/DafnyCore/Resolver/ModuleResolver.cs +++ b/Source/DafnyCore/Resolver/ModuleResolver.cs @@ -2867,12 +2867,7 @@ void MarkSCCAsNotSupportingEquality() { return; // we are done } foreach (var arg in ctor.Formals) { - var anotherIndDt = arg.Type.AsIndDatatype; - if (arg.IsGhost || - (anotherIndDt != null && anotherIndDt.EqualitySupport == IndDatatypeDecl.ES.Never) || - arg.Type.IsCoDatatype || - arg.Type.IsArrowType) { - // arg.Type is known never to support equality + if(arg.IsGhost || SurelyDoesNotSupportEquality(arg.Type)) { MarkSCCAsNotSupportingEquality(); return; // we are done } @@ -2931,6 +2926,26 @@ void MarkSCCAsNotSupportingEquality() { } } + private static bool SurelyDoesNotSupportEquality(Type type) + { + if (type.IsCoDatatype || + type.IsArrowType) { + return true; + } + + if (type.AsIndDatatype is { } anotherIndDt) { + if (anotherIndDt.EqualitySupport == IndDatatypeDecl.ES.Never) { + return true; + } + if(anotherIndDt.EqualitySupport == IndDatatypeDecl.ES.ConsultTypeArguments && + type.NormalizeExpand().TypeArgs.Zip(anotherIndDt.TypeArgs).ToList().Any(t => t.Second.NecessaryForEqualitySupportOfSurroundingInductiveDatatype && SurelyDoesNotSupportEquality(t.First))){ + return true; + } + } + + return false; + } + private static void DetermineEqualitySupportType(Type type, ref bool thingsChanged) { if (type.AsTypeParameter is {} typeArg) { @@ -2938,6 +2953,8 @@ private static void DetermineEqualitySupportType(Type type, ref bool thingsChang thingsChanged = true; } else if (type.AsMapType is {} typeMap) { DetermineEqualitySupportType(typeMap.Range, ref thingsChanged); + } else if (type.AsSeqType is {} typeSeq) { + DetermineEqualitySupportType(typeSeq.Arg, ref thingsChanged); } else if (type.AsIndDatatype is {} otherDt) { if (otherDt.EqualitySupport == IndDatatypeDecl.ES.ConsultTypeArguments) { // datatype is in a different SCC var otherUdt = (UserDefinedType)type.NormalizeExpand(); diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect new file mode 100644 index 00000000000..19e90eca854 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect @@ -0,0 +1,2 @@ +Dafny program verifier finished with 1 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect new file mode 100644 index 00000000000..ec66568c1f0 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect @@ -0,0 +1,2 @@ +Dafny program verifier finished with 2 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect new file mode 100644 index 00000000000..020b23b7235 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect @@ -0,0 +1,2 @@ +Dafny program verifier finished with 3 verified, 0 errors +ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy new file mode 100644 index 00000000000..b78d8dd5d50 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy @@ -0,0 +1,51 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +datatype I_ = I_(t: T, u: U) + +type I = x: I_ | true witness * + +datatype {:rust_rc false} A = A(B: I) + +datatype {:rust_rc false} M_ = M_(m: map) + +type M = x: M_ | true witness * + +trait O {} + +datatype U = U(o: O) + +datatype G = G(m1: map, m2: map, m3: map) + +type F = g: G | true witness * + +datatype V = V(u: U>) + +datatype Phantom = Phantom() + +datatype WithGhost_ = WithGhost(i: int, ghost n: int) + +type WithGhost = x: WithGhost_ | true witness * + +datatype {:rust_rc false} WithGhostWrapper = WithGhostWrapper(r:WithGhost) + +type DoubleWithGhost = t:(WithGhostWrapper,WithGhostWrapper) | true witness * + +datatype {:rust_rc false} DoubleWithGhostWrapper = DoubleWithGhostWrapper( + dwg:DoubleWithGhost +) + +method Test() { +} + +method Main() { + Test>(); + Test>(); + Test>(); + Test>(); + Test, int>>(); + Test>(); + //Test int>>(); + print "ok"; +} \ No newline at end of file From 0f20e728bd4d0ca1a2fd0e93a3677d5e197fa43c Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Wed, 11 Dec 2024 11:13:42 +0000 Subject: [PATCH 26/69] Fixed inherited function call --- .../Backends/Dafny/DafnyCodeGenerator.cs | 7 +++---- .../SinglePassCodeGenerator.cs | 6 ++++++ .../08-not-all-trait-items-implemented.dfy | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index f00ee18b1b7..c5326d69e9d 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -1202,13 +1202,12 @@ private _ICallSignature GetCallSignature(MethodOrFunction method) thisContext = oldThisContext; return parameters; } - - protected override void EmitCallToInheritedFunction(Function f, [CanBeNull] TopLevelDeclWithMembers heir, - ConcreteSyntaxTree wr) { + + protected override ConcreteSyntaxTree StartCall(Function f, ConcreteSyntaxTree wr) { if (wr is BuilderSyntaxTree exprContainer) { var signature = GetCallSignature(f); var callBuilder = exprContainer.Builder.Call(signature); - base.EmitCallToInheritedFunction(f, heir, new BuilderSyntaxTree(callBuilder, this)); + return new BuilderSyntaxTree(callBuilder, this); } else { throw new InvalidOperationException("Cannot call inherited function in this context: " + currentBuilder); } diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index 8c5011bc01f..23cfc11986b 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -2478,6 +2478,10 @@ protected void EmitCallToInheritedConstRHS(ConstantField f, ConcreteSyntaxTree w wr.Write(")"); } + protected virtual ConcreteSyntaxTree StartCall(Function f, ConcreteSyntaxTree wr) { + return wr; + } + /// /// "heir" is the type declaration that inherits the function. Or, it can be "null" to indicate that the function is declared in /// the type itself, in which case the "call to inherited" is actually a call from the dynamically dispatched function to its implementation. @@ -2503,6 +2507,8 @@ protected virtual void EmitCallToInheritedFunction(Function f, [CanBeNull] TopLe // the same signature as in "f.Original.EnclosingClass". wr = EmitCoercionIfNecessary(f.ResultType, f.Original.ResultType, f.tok, wr); + wr = StartCall(f, wr); + var companionName = CompanionMemberIdName(f); var calleeReceiverType = UserDefinedType.FromTopLevelDecl(f.tok, f.EnclosingClass).Subst(thisContext.ParentFormalTypeParametersToActuals); wr.Write("{0}{1}", TypeName_Companion(calleeReceiverType, wr, f.tok, f), StaticClassAccessor); diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy index e9bb4983400..f76f2f7ebee 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy @@ -19,6 +19,27 @@ datatype {:rust_rc false} Pong extends Reversible, SubReversible = Pong { } +trait Singleton { + function id():G +} + + +trait A { + function g():Singleton +} + + +trait F extends A { + function g():Singleton { Zero } +} + +datatype Zero extends Singleton = Zero { + function id(): int { 0 } +} + +datatype C extends F = C { +} + method Main() { var x := Pong; expect x.reverse() is Ping; From e16dce91a0992b85a55d30bbcb99e978d7a46333 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Wed, 11 Dec 2024 16:23:50 +0000 Subject: [PATCH 27/69] Fixed wrongly inferred equality --- Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs | 7 +++++++ .../comp/rust/small/08-not-all-trait-items-implemented.dfy | 4 ++++ .../small/08-not-all-trait-items-implemented.dfy.expect | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs b/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs index 52cef103e65..0cd8a4ec60c 100644 --- a/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs +++ b/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs @@ -49,6 +49,13 @@ private static void InferEqualitySupport(List declarations, ErrorR } } } + + foreach (var parentType in dt.ParentTraits) { + if (InferAndSetEqualitySupport(tp, parentType, reporter)) { + inferredSomething = true; + goto DONE_DT; // break out of the doubly-nested loop + } + } DONE_DT:; } } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy index f76f2f7ebee..f94e3236e69 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy @@ -40,6 +40,10 @@ datatype Zero extends Singleton = Zero { datatype C extends F = C { } +trait RequiresEquality { +} +datatype TraitExtender extends RequiresEquality> = TraitExtender {} + method Main() { var x := Pong; expect x.reverse() is Ping; diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect index fb7d2d153ca..32b63f1961a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect @@ -1,2 +1,2 @@ -Dafny program verifier finished with 3 verified, 0 errors +Dafny program verifier finished with 5 verified, 0 errors ping pong \ No newline at end of file From cc8a0b7f3da806b9dec0d19fdeb3c109a568f4df Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 16 Dec 2024 14:30:13 -0600 Subject: [PATCH 28/69] WIP --- Source/DafnyCore/Backends/Dafny/AST.dfy | 8 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 18 +- .../Rust/Dafny-compiler-rust-rast.dfy | 24 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 150 ++-- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 849 +++++++----------- .../comp/rust/small/06-type-bounds.dfy | 22 +- 6 files changed, 456 insertions(+), 615 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 1d8a70e8a26..64593f6c0a7 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -272,13 +272,15 @@ module {:extern "DAST"} DAST { | NativeArrayIndex | BigInt | Bool + | Sequence + | Map | NoRange { predicate CanOverflow() { (U8? || I8? || U16? || I16? || U32? || I32? || U64? || I64? || U128? || I128?) && overflow } predicate HasArithmeticOperations() { - !Bool?// To change when newtypes will have sequences and sets as ranges. + !Bool? && !Map? && !Sequence? } } @@ -379,7 +381,9 @@ module {:extern "DAST"} DAST { docString: string, typeParams: seq, base: Type, range: NewtypeRange, constraint: Option, - witnessStmts: seq, witnessExpr: Option, attributes: seq, + witnessStmts: seq, witnessExpr: Option, + equalitySupport: EqualitySupport, + attributes: seq, classItems: seq) datatype NewtypeConstraint = NewtypeConstraint(variable: Formal, constraintStmts: seq) diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index c5326d69e9d..d54221eec3b 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -392,10 +392,7 @@ private static bool isTpSupported(TypeParameter tp, [CanBeNull] out string why) protected override IClassWriter DeclareDatatype(DatatypeDecl dt, ConcreteSyntaxTree wr) { if (currentBuilder is DatatypeContainer builder) { - List typeParams = new(); - foreach (var tp in dt.TypeArgs) { - typeParams.Add(GenTypeArgDecl(tp)); - } + var typeParams = GenTypeParams(dt.TypeArgs); IEnumerable ctors = from ctor in dt.Ctors @@ -440,6 +437,16 @@ from arg in ctor.Formals } } + private List GenTypeParams(List typePargs) + { + List typeParams = new(); + foreach (var tp in typePargs) { + typeParams.Add(GenTypeArgDecl(tp)); + } + + return typeParams; + } + // Given a list of super traits implemented by a datatype, // find the list of all instantiated traits that the super traits can be downcasted to, // but that are not in the super classes, @@ -501,9 +508,10 @@ protected override IClassWriter DeclareNewtype(NewtypeDecl nt, ConcreteSyntaxTre } else { constraint = (Option)Option.create_None(); } + var typeParams = GenTypeParams(nt.TypeArgs); return new ClassWriter(this, false, builder.Newtype( - nt.GetCompileName(Options), new(), + nt.GetCompileName(Options), typeParams, GenType(nt.BaseType), NativeTypeToNewtypeRange(nt, false), constraint, witnessStmts, witness, ParseAttributes(nt.Attributes), GetDocString(nt))); } else { diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index e9504001787..24b4d0a604c 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -443,11 +443,31 @@ module RAST visibility.ToString() + fn.ToString(ind) } } - datatype Attribute = RawAttribute(content: string) { + datatype Attribute = + | ApplyAttribute(name: string, derived: seq) { + static const DeriveClone := + ApplyAttribute("derive", ["Clone"]) + static const DeriveCloneAndCopy := + ApplyAttribute("derive", ["Clone", "Copy"]) + static const CfgTest := + ApplyAttribute("cfg", ["test"]) + static function Name(name: string): Attribute { + ApplyAttribute(name, []) + } + + function ToString(ind: string): string { + match this { + case ApplyAttribute(name, derived) => + var arguments := if |derived| != 0 then + "("+SeqToString(derived, (derived: string) => derived)+")" + else ""; + "#["+name+arguments+"]" + } + } static function ToStringMultiple(attributes: seq, ind: string): string { SeqToString( attributes, - (attribute: Attribute) => attribute.content + "\n" + ind) + (attribute: Attribute) => attribute.ToString(ind) + "\n" + ind) } } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index f2741f49777..46de5b70bda 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -94,7 +94,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var optExtern: ExternAttribute := ExtractExternMod(mod); var attributes := []; if HasAttribute(mod.attributes, "rust_cfg_test") { - attributes := [R.RawAttribute("#[cfg(test)]")]; + attributes := [R.Attribute.CfgTest]; } var body, allmodules := GenModuleBody(mod, mod.body.value, containingPath + [Ident.Ident(innerName)]); if optExtern.SimpleExtern? { @@ -491,7 +491,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.TopFnDecl( R.TopFn( m.docString, - [R.RawAttribute("#[test]")], R.PUB, + [R.Attribute.Name("test")], R.PUB, R.Fn( fnName, [], [], None, Some(R.Identifier("_default").FSel(fnName).Apply([]))) @@ -773,23 +773,38 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var newtypeName := escapeName(c.name); var resultingType := R.TypeApp(R.TIdentifier(newtypeName), rTypeParams); var attributes: string; + var deriveTraits := ["Clone"]; if IsNewtypeCopy(c.range) { - attributes := "#[derive(Clone, PartialEq, Copy)]"; - } else { - attributes := "#[derive(Clone, PartialEq)]"; + deriveTraits := deriveTraits + ["Copy"]; } s := [ R.StructDecl( R.Struct( c.docString, [ - R.RawAttribute(attributes), - R.RawAttribute("#[repr(transparent)]") + R.ApplyAttribute("derive", deriveTraits), + R.ApplyAttribute("repr", ["transparent"]) ], newtypeName, rTypeParamsDecls, R.NamelessFields([R.NamelessField(R.PUB, wrappedType)]) ))]; + if c.equalitySupport.Always? || c.equalitySupport.ConsultTypeArguments? { + var consultTypeArguments := c.equalitySupport.ConsultTypeArguments?; + var eqImplBody := + R.self.Sel("0").Equals(R.Identifier("other").Sel("0")); + var hashImplBody := + hash_function.Apply([R.self.Sel("0"), R.Identifier("_state")]); + var impls := GenEqHashImpls( + c.typeParams, + rTypeParamsDecls, + rTypeParams, + consultTypeArguments, + resultingType, + eqImplBody, + hashImplBody); + s := s + impls; + } var fnBody; @@ -969,63 +984,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - // Figure out if the type is always extending Eq - predicate TypeIsEq(t: Type, typeParametersSupportingEquality: set) - decreases t - { - match t - case UserDefined(ResolvedType(_, _, SynonymType(tpe), _, _, _)) => TypeIsEq(tpe, typeParametersSupportingEquality) - case UserDefined(ResolvedType(_, _, Class(), _, _, _)) => true - case UserDefined(ResolvedType(_, _, Trait(GeneralTrait), _, _, _)) => false - case UserDefined(ResolvedType(_, _, Trait(ObjectTrait), _, _, _)) => true - case UserDefined(ResolvedType(_, _, Newtype(tpe, _, _), _, _, _)) => TypeIsEq(tpe, typeParametersSupportingEquality) - case UserDefined(ResolvedType(_, typeParams, Datatype(equalitySupport, tps), _, _, _)) => - !equalitySupport.Never? && - (equalitySupport.Always? || - (&& equalitySupport.ConsultTypeArguments? - && |tps| == |typeParams| - && forall i | 0 <= i < |tps| :: - (tps[i].necessaryForEqualitySupportOfSurroundingInductiveDatatype ==> TypeIsEq(typeParams[i], typeParametersSupportingEquality)))) - case Tuple(ts) => forall t <- ts :: TypeIsEq(t, typeParametersSupportingEquality) - case Array(t, _) => true // Reference equality - case Seq(t) => TypeIsEq(t, typeParametersSupportingEquality) - case Set(t) => true - case Multiset(t) => true - case Map(k, v) => TypeIsEq(v, typeParametersSupportingEquality) - case SetBuilder(t) => true // Irrelevant - case MapBuilder(k, v) => TypeIsEq(v, typeParametersSupportingEquality) // Irrelevant - case Arrow(_, _) => false - case Primitive(_) => true - case Passthrough(_) => true // should be Rust primitive types - case TypeArg(i) => i in typeParametersSupportingEquality // i(==) is asserted at the point of use by the verifier - case Object() => true - } - - function Combine(s: seq>>): Option> { - if |s| == 0 then Some({}) else - var idents :- s[|s|-1]; - var remaining_idents :- Combine(s[0..|s|-1]); - Some(idents + remaining_idents) - } by method { - if |s| == 0 { - return Some({}); - } - var result := {}; - for i := 0 to |s| - invariant Some(result) == Combine(s[0..i]) - { - if s[i].None? { - return None; - } - result := result + s[i].value; - } - return Some(result); - } - - predicate DatatypeIsEq(c: Datatype, typeParametersSupportingEquality: set) { - !c.isCo && forall ctor <- c.ctors, arg <- ctor.args :: TypeIsEq(arg.formal.typ, typeParametersSupportingEquality) - } - function write(r: R.Expr, final: bool := false): R.Expr { var result := R.Identifier("write!").Apply([ @@ -1041,6 +999,37 @@ module {:extern "DCOMP"} DafnyToRustCompiler { write(R.LiteralString(s, binary := false, verbatim := false)) } + /** eqImplBody assumes the existence of borrowed "self" and borrowed "other" */ + method GenEqHashImpls( + typeParamsDecls: seq, + rTypeParamsDecls: seq, + rTypeParams: seq, + consultTypeArguments: bool, + datatypeType: R.Type, + eqImplBody: R.Expr, + hashImplBody: R.Expr + ) returns (impls: seq) + requires |typeParamsDecls| == |rTypeParamsDecls| + { + var rTypeParamsDeclsWithEq := rTypeParamsDecls; + var rTypeParamsDeclsWithHash := rTypeParamsDecls; + if consultTypeArguments { + for i := 0 to |rTypeParamsDecls| { + if typeParamsDecls[i].info.necessaryForEqualitySupportOfSurroundingInductiveDatatype { + rTypeParamsDeclsWithEq := rTypeParamsDeclsWithEq[i := rTypeParamsDeclsWithEq[i].AddConstraints([R.Eq, R.Hash])]; + rTypeParamsDeclsWithHash := rTypeParamsDeclsWithHash[i := rTypeParamsDeclsWithHash[i].AddConstraints([R.Hash])]; + } + } + } + impls := EqImpl(rTypeParamsDeclsWithEq, datatypeType, rTypeParams, eqImplBody); + // Implementation of Hash trait + impls := impls + [ + HashImpl( + rTypeParamsDeclsWithHash, + datatypeType, + hashImplBody)]; + } + method GenDatatype(c: Datatype, path: seq) returns (s: seq) modifies this { @@ -1236,9 +1225,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { )]; } } - var typeParametersSupportingEquality: set := - set tp <- c.typeParams | SupportsEquality in tp.bounds :: tp.name; - var cIsAlwaysEq := DatatypeIsEq(c, typeParametersSupportingEquality); + var cIsAlwaysEq := c.equalitySupport.Always?; var datatypeType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); // Derive PartialEq when c supports equality / derive Clone in all cases @@ -1246,7 +1233,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { [R.EnumDecl( R.Enum( c.docString, - [R.RawAttribute("#[derive(Clone)]")], + [R.Attribute.DeriveClone], datatypeName, rTypeParamsDecls, ctors @@ -1471,23 +1458,16 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } if c.equalitySupport.Always? || c.equalitySupport.ConsultTypeArguments? { - var rTypeParamsDeclsWithEq := rTypeParamsDecls; - var rTypeParamsDeclsWithHash := rTypeParamsDecls; - if c.equalitySupport.ConsultTypeArguments? { - for i := 0 to |rTypeParamsDecls| { - if c.typeParams[i].info.necessaryForEqualitySupportOfSurroundingInductiveDatatype { - rTypeParamsDeclsWithEq := rTypeParamsDeclsWithEq[i := rTypeParamsDeclsWithEq[i].AddConstraints([R.Eq, R.Hash])]; - rTypeParamsDeclsWithHash := rTypeParamsDeclsWithHash[i := rTypeParamsDeclsWithHash[i].AddConstraints([R.Hash])]; - } - } - } - s := s + EqImpl(rTypeParamsDeclsWithEq, datatypeType, rTypeParams, eqImplBody); - // Implementation of Hash trait - s := s + [ - HashImpl( - rTypeParamsDeclsWithHash, - datatypeType, - hashImplBody)]; + var consultTypeArguments := c.equalitySupport.ConsultTypeArguments?; + var impls := GenEqHashImpls( + c.typeParams, + rTypeParamsDecls, + rTypeParams, + consultTypeArguments, + datatypeType, + eqImplBody, + hashImplBody); + s := s + impls; } if |c.ctors| > 0 { diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index d73240a47fd..010f8914f2d 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -876,186 +876,6 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc after_match0: ; return s; } - public bool TypeIsEq(DAST._IType t, Dafny.ISet> typeParametersSupportingEquality) - { - DAST._IType _source0 = t; - { - if (_source0.is_UserDefined) { - DAST._IResolvedType resolved0 = _source0.dtor_resolved; - DAST._IResolvedTypeBase kind0 = resolved0.dtor_kind; - if (kind0.is_SynonymType) { - DAST._IType _0_tpe = kind0.dtor_baseType; - return (this).TypeIsEq(_0_tpe, typeParametersSupportingEquality); - } - } - } - { - if (_source0.is_UserDefined) { - DAST._IResolvedType resolved1 = _source0.dtor_resolved; - DAST._IResolvedTypeBase kind1 = resolved1.dtor_kind; - if (kind1.is_Class) { - return true; - } - } - } - { - if (_source0.is_UserDefined) { - DAST._IResolvedType resolved2 = _source0.dtor_resolved; - DAST._IResolvedTypeBase kind2 = resolved2.dtor_kind; - if (kind2.is_Trait) { - DAST._ITraitType traitType0 = kind2.dtor_traitType; - if (traitType0.is_GeneralTrait) { - return false; - } - } - } - } - { - if (_source0.is_UserDefined) { - DAST._IResolvedType resolved3 = _source0.dtor_resolved; - DAST._IResolvedTypeBase kind3 = resolved3.dtor_kind; - if (kind3.is_Trait) { - DAST._ITraitType traitType1 = kind3.dtor_traitType; - if (traitType1.is_ObjectTrait) { - return true; - } - } - } - } - { - if (_source0.is_UserDefined) { - DAST._IResolvedType resolved4 = _source0.dtor_resolved; - DAST._IResolvedTypeBase kind4 = resolved4.dtor_kind; - if (kind4.is_Newtype) { - DAST._IType _1_tpe = kind4.dtor_baseType; - return (this).TypeIsEq(_1_tpe, typeParametersSupportingEquality); - } - } - } - { - if (_source0.is_UserDefined) { - DAST._IResolvedType resolved5 = _source0.dtor_resolved; - Dafny.ISequence _2_typeParams = resolved5.dtor_typeArgs; - DAST._IResolvedTypeBase kind5 = resolved5.dtor_kind; - if (kind5.is_Datatype) { - DAST._IEqualitySupport _3_equalitySupport = kind5.dtor_equalitySupport; - Dafny.ISequence _4_tps = kind5.dtor_info; - return (!((_3_equalitySupport).is_Never)) && (((_3_equalitySupport).is_Always) || ((((_3_equalitySupport).is_ConsultTypeArguments) && ((new BigInteger((_4_tps).Count)) == (new BigInteger((_2_typeParams).Count)))) && (Dafny.Helpers.Id, Dafny.ISequence, Dafny.ISet>, bool>>((_5_tps, _6_typeParams, _7_typeParametersSupportingEquality) => Dafny.Helpers.Quantifier(Dafny.Helpers.IntegerRange(BigInteger.Zero, new BigInteger((_5_tps).Count)), true, (((_forall_var_0) => { - BigInteger _8_i = (BigInteger)_forall_var_0; - return !(((_8_i).Sign != -1) && ((_8_i) < (new BigInteger((_5_tps).Count)))) || (!(((_5_tps).Select(_8_i)).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype) || ((this).TypeIsEq((_6_typeParams).Select(_8_i), _7_typeParametersSupportingEquality))); - }))))(_4_tps, _2_typeParams, typeParametersSupportingEquality)))); - } - } - } - { - if (_source0.is_Tuple) { - Dafny.ISequence _9_ts = _source0.dtor_Tuple_a0; - return Dafny.Helpers.Id, Dafny.ISet>, bool>>((_10_ts, _11_typeParametersSupportingEquality) => Dafny.Helpers.Quantifier((_10_ts).UniqueElements, true, (((_forall_var_1) => { - DAST._IType _12_t = (DAST._IType)_forall_var_1; - return !((_10_ts).Contains(_12_t)) || ((this).TypeIsEq(_12_t, _11_typeParametersSupportingEquality)); - }))))(_9_ts, typeParametersSupportingEquality); - } - } - { - if (_source0.is_Array) { - DAST._IType _13_t = _source0.dtor_element; - return true; - } - } - { - if (_source0.is_Seq) { - DAST._IType _14_t = _source0.dtor_element; - return (this).TypeIsEq(_14_t, typeParametersSupportingEquality); - } - } - { - if (_source0.is_Set) { - DAST._IType _15_t = _source0.dtor_element; - return true; - } - } - { - if (_source0.is_Multiset) { - DAST._IType _16_t = _source0.dtor_element; - return true; - } - } - { - if (_source0.is_Map) { - DAST._IType _17_k = _source0.dtor_key; - DAST._IType _18_v = _source0.dtor_value; - return (this).TypeIsEq(_18_v, typeParametersSupportingEquality); - } - } - { - if (_source0.is_SetBuilder) { - DAST._IType _19_t = _source0.dtor_element; - return true; - } - } - { - if (_source0.is_MapBuilder) { - DAST._IType _20_k = _source0.dtor_key; - DAST._IType _21_v = _source0.dtor_value; - return (this).TypeIsEq(_21_v, typeParametersSupportingEquality); - } - } - { - if (_source0.is_Arrow) { - return false; - } - } - { - if (_source0.is_Primitive) { - return true; - } - } - { - if (_source0.is_Passthrough) { - return true; - } - } - { - if (_source0.is_TypeArg) { - Dafny.ISequence _22_i = _source0.dtor_TypeArg_a0; - return (typeParametersSupportingEquality).Contains(_22_i); - } - } - { - return true; - } - } - public Std.Wrappers._IOption>> Combine(Dafny.ISequence>>> s) - { - Std.Wrappers._IOption>> _hresult = Std.Wrappers.Option>>.Default(); - if ((new BigInteger((s).Count)).Sign == 0) { - _hresult = Std.Wrappers.Option>>.create_Some(Dafny.Set>.FromElements()); - return _hresult; - } - Dafny.ISet> _0_result; - _0_result = Dafny.Set>.FromElements(); - BigInteger _hi0 = new BigInteger((s).Count); - for (BigInteger _1_i = BigInteger.Zero; _1_i < _hi0; _1_i++) { - if (((s).Select(_1_i)).is_None) { - _hresult = Std.Wrappers.Option>>.create_None(); - return _hresult; - } - _0_result = Dafny.Set>.Union(_0_result, ((s).Select(_1_i)).dtor_value); - } - _hresult = Std.Wrappers.Option>>.create_Some(_0_result); - return _hresult; - return _hresult; - } - public bool DatatypeIsEq(DAST._IDatatype c, Dafny.ISet> typeParametersSupportingEquality) - { - return (!((c).dtor_isCo)) && (Dafny.Helpers.Id>, bool>>((_0_c, _1_typeParametersSupportingEquality) => Dafny.Helpers.Quantifier(((_0_c).dtor_ctors).UniqueElements, true, (((_forall_var_0) => { - DAST._IDatatypeCtor _2_ctor = (DAST._IDatatypeCtor)_forall_var_0; - return Dafny.Helpers.Quantifier(((_2_ctor).dtor_args).UniqueElements, true, (((_forall_var_1) => { - DAST._IDatatypeDtor _3_arg = (DAST._IDatatypeDtor)_forall_var_1; - return !((((_0_c).dtor_ctors).Contains(_2_ctor)) && (((_2_ctor).dtor_args).Contains(_3_arg))) || ((this).TypeIsEq(((_3_arg).dtor_formal).dtor_typ, _1_typeParametersSupportingEquality)); - }))); - }))))(c, typeParametersSupportingEquality)); - } public RAST._IExpr write(RAST._IExpr r, bool final) { RAST._IExpr _0_result = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("write!"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), r)); @@ -1314,272 +1134,261 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) })), _54_types))))); } } - Dafny.ISet> _68_typeParametersSupportingEquality; - _68_typeParametersSupportingEquality = Dafny.Helpers.Id>>>((_69_c) => ((System.Func>>)(() => { - var _coll1 = new System.Collections.Generic.List>(); - foreach (DAST._ITypeArgDecl _compr_1 in ((_69_c).dtor_typeParams).CloneAsArray()) { - DAST._ITypeArgDecl _70_tp = (DAST._ITypeArgDecl)_compr_1; - if ((((_69_c).dtor_typeParams).Contains(_70_tp)) && (((_70_tp).dtor_bounds).Contains(DAST.TypeArgBound.create_SupportsEquality()))) { - _coll1.Add((_70_tp).dtor_name); - } - } - return Dafny.Set>.FromCollection(_coll1); - }))())(c); - bool _71_cIsAlwaysEq; - _71_cIsAlwaysEq = (this).DatatypeIsEq(c, _68_typeParametersSupportingEquality); - RAST._IType _72_datatypeType; - _72_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _72_datatypeType, _27_implBody))); + bool _68_cIsAlwaysEq; + _68_cIsAlwaysEq = ((c).dtor_equalitySupport).is_Always; + RAST._IType _69_datatypeType; + _69_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _69_datatypeType, _27_implBody))); if ((new BigInteger(((c).dtor_superTraitTypes).Count)).Sign == 1) { - RAST._IType _73_fullType; + RAST._IType _70_fullType; if (_0_isRcWrapped) { - _73_fullType = RAST.__default.Rc(_72_datatypeType); + _70_fullType = RAST.__default.Rc(_69_datatypeType); } else { - _73_fullType = _72_datatypeType; + _70_fullType = _69_datatypeType; } - Std.Wrappers._IOption _74_downcastDefinitionOpt; - _74_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_3_rTypeParamsDecls, _73_fullType); - if ((_74_downcastDefinitionOpt).is_None) { - RAST._IExpr _75_dummy; + Std.Wrappers._IOption _71_downcastDefinitionOpt; + _71_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_3_rTypeParamsDecls, _70_fullType); + if ((_71_downcastDefinitionOpt).is_None) { + RAST._IExpr _72_dummy; RAST._IExpr _out15; - _out15 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_73_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _75_dummy = _out15; + _out15 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _72_dummy = _out15; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_74_downcastDefinitionOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_71_downcastDefinitionOpt).dtor_value)); } - Std.Wrappers._IOption _76_downcastImplementationsOpt; - _76_downcastImplementationsOpt = Defs.__default.DowncastImplFor(_3_rTypeParamsDecls, _73_fullType); - if ((_76_downcastImplementationsOpt).is_None) { - RAST._IExpr _77_dummy; + Std.Wrappers._IOption _73_downcastImplementationsOpt; + _73_downcastImplementationsOpt = Defs.__default.DowncastImplFor(_3_rTypeParamsDecls, _70_fullType); + if ((_73_downcastImplementationsOpt).is_None) { + RAST._IExpr _74_dummy; RAST._IExpr _out16; - _out16 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation for "), (_73_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _77_dummy = _out16; + _out16 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _74_dummy = _out16; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_76_downcastImplementationsOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_73_downcastImplementationsOpt).dtor_value)); } BigInteger _hi7 = new BigInteger(((c).dtor_superTraitNegativeTypes).Count); - for (BigInteger _78_i = BigInteger.Zero; _78_i < _hi7; _78_i++) { - RAST._IType _79_negativeTraitType; + for (BigInteger _75_i = BigInteger.Zero; _75_i < _hi7; _75_i++) { + RAST._IType _76_negativeTraitType; RAST._IType _out17; - _out17 = (this).GenType(((c).dtor_superTraitNegativeTypes).Select(_78_i), Defs.GenTypeContext.@default()); - _79_negativeTraitType = _out17; - Std.Wrappers._IOption _80_downcastDefinitionOpt; - _80_downcastDefinitionOpt = Defs.__default.DowncastNotImplFor(_3_rTypeParamsDecls, _79_negativeTraitType, _73_fullType); - if ((_80_downcastDefinitionOpt).is_None) { - RAST._IExpr _81_dummy; + _out17 = (this).GenType(((c).dtor_superTraitNegativeTypes).Select(_75_i), Defs.GenTypeContext.@default()); + _76_negativeTraitType = _out17; + Std.Wrappers._IOption _77_downcastDefinitionOpt; + _77_downcastDefinitionOpt = Defs.__default.DowncastNotImplFor(_3_rTypeParamsDecls, _76_negativeTraitType, _70_fullType); + if ((_77_downcastDefinitionOpt).is_None) { + RAST._IExpr _78_dummy; RAST._IExpr _out18; - _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate negative downcast definition for "), (_73_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _81_dummy = _out18; + _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate negative downcast definition for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _78_dummy = _out18; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_80_downcastDefinitionOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_77_downcastDefinitionOpt).dtor_value)); } } BigInteger _hi8 = new BigInteger(((c).dtor_superTraitTypes).Count); - for (BigInteger _82_i = BigInteger.Zero; _82_i < _hi8; _82_i++) { - DAST._IType _83_c; - _83_c = ((c).dtor_superTraitTypes).Select(_82_i); - if ((((_83_c).is_UserDefined) && ((((_83_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_83_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { + for (BigInteger _79_i = BigInteger.Zero; _79_i < _hi8; _79_i++) { + DAST._IType _80_c; + _80_c = ((c).dtor_superTraitTypes).Select(_79_i); + if ((((_80_c).is_UserDefined) && ((((_80_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_80_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { goto continue_3_0; } - RAST._IType _84_cType; + RAST._IType _81_cType; RAST._IType _out19; - _out19 = (this).GenType(_83_c, Defs.GenTypeContext.@default()); - _84_cType = _out19; - bool _85_isImplementing; - _85_isImplementing = true; - Std.Wrappers._IOption _86_downcastImplementationsOpt; - _86_downcastImplementationsOpt = Defs.__default.DowncastImplTraitFor(_3_rTypeParamsDecls, _84_cType, _85_isImplementing, _73_fullType); - if ((_86_downcastImplementationsOpt).is_None) { - RAST._IExpr _87_dummy; + _out19 = (this).GenType(_80_c, Defs.GenTypeContext.@default()); + _81_cType = _out19; + bool _82_isImplementing; + _82_isImplementing = true; + Std.Wrappers._IOption _83_downcastImplementationsOpt; + _83_downcastImplementationsOpt = Defs.__default.DowncastImplTraitFor(_3_rTypeParamsDecls, _81_cType, _82_isImplementing, _70_fullType); + if ((_83_downcastImplementationsOpt).is_None) { + RAST._IExpr _84_dummy; RAST._IExpr _out20; - _out20 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation of "), (_84_cType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" for ")), (_73_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _87_dummy = _out20; + _out20 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation of "), (_81_cType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" for ")), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _84_dummy = _out20; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_86_downcastImplementationsOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_83_downcastImplementationsOpt).dtor_value)); } continue_3_0: ; } after_3_0: ; } - Dafny.ISequence _88_printImplBodyCases; - _88_printImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _89_hashImplBodyCases; - _89_hashImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _90_coerceImplBodyCases; - _90_coerceImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _91_partialEqImplBodyCases; - _91_partialEqImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _85_printImplBodyCases; + _85_printImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _86_hashImplBodyCases; + _86_hashImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _87_coerceImplBodyCases; + _87_coerceImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _88_partialEqImplBodyCases; + _88_partialEqImplBodyCases = Dafny.Sequence.FromElements(); BigInteger _hi9 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _92_i = BigInteger.Zero; _92_i < _hi9; _92_i++) { - DAST._IDatatypeCtor _93_ctor; - _93_ctor = ((c).dtor_ctors).Select(_92_i); - Dafny.ISequence _94_ctorMatch; - _94_ctorMatch = Defs.__default.escapeName((_93_ctor).dtor_name); - Dafny.ISequence _95_modulePrefix; + for (BigInteger _89_i = BigInteger.Zero; _89_i < _hi9; _89_i++) { + DAST._IDatatypeCtor _90_ctor; + _90_ctor = ((c).dtor_ctors).Select(_89_i); + Dafny.ISequence _91_ctorMatch; + _91_ctorMatch = Defs.__default.escapeName((_90_ctor).dtor_name); + Dafny.ISequence _92_modulePrefix; if (((((c).dtor_enclosingModule))).Equals(Dafny.Sequence.UnicodeFromString("_module"))) { - _95_modulePrefix = Dafny.Sequence.UnicodeFromString(""); + _92_modulePrefix = Dafny.Sequence.UnicodeFromString(""); } else { - _95_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); - } - Dafny.ISequence _96_ctorName; - _96_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_95_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_93_ctor).dtor_name)); - if (((new BigInteger((_96_ctorName).Count)) >= (new BigInteger(13))) && (((_96_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { - _96_ctorName = Dafny.Sequence.UnicodeFromString(""); - } - RAST._IExpr _97_printRhs; - _97_printRhs = (this).writeStr(Dafny.Sequence.Concat(_96_ctorName, (((_93_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); - RAST._IExpr _98_hashRhs; - _98_hashRhs = (this).InitEmptyExpr(); - RAST._IExpr _99_partialEqRhs; - _99_partialEqRhs = RAST.Expr.create_LiteralBool(true); - Dafny.ISequence _100_coerceRhsArgs; - _100_coerceRhsArgs = Dafny.Sequence.FromElements(); - bool _101_isNumeric; - _101_isNumeric = false; - Dafny.ISequence _102_ctorMatchInner; - _102_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); - Dafny.ISequence _103_ctorMatchInner2; - _103_ctorMatchInner2 = Dafny.Sequence.UnicodeFromString(""); - BigInteger _hi10 = new BigInteger(((_93_ctor).dtor_args).Count); - for (BigInteger _104_j = BigInteger.Zero; _104_j < _hi10; _104_j++) { - DAST._IDatatypeDtor _105_dtor; - _105_dtor = ((_93_ctor).dtor_args).Select(_104_j); - Dafny.ISequence _106_patternName; - _106_patternName = Defs.__default.escapeVar(((_105_dtor).dtor_formal).dtor_name); - DAST._IType _107_formalType; - _107_formalType = ((_105_dtor).dtor_formal).dtor_typ; - if (((_104_j).Sign == 0) && ((_106_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _101_isNumeric = true; - } - if (_101_isNumeric) { - _106_patternName = Std.Wrappers.Option>.GetOr((_105_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_104_j))); - } - if ((_107_formalType).is_Arrow) { - _98_hashRhs = (_98_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + _92_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); + } + Dafny.ISequence _93_ctorName; + _93_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_92_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_90_ctor).dtor_name)); + if (((new BigInteger((_93_ctorName).Count)) >= (new BigInteger(13))) && (((_93_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { + _93_ctorName = Dafny.Sequence.UnicodeFromString(""); + } + RAST._IExpr _94_printRhs; + _94_printRhs = (this).writeStr(Dafny.Sequence.Concat(_93_ctorName, (((_90_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); + RAST._IExpr _95_hashRhs; + _95_hashRhs = (this).InitEmptyExpr(); + RAST._IExpr _96_partialEqRhs; + _96_partialEqRhs = RAST.Expr.create_LiteralBool(true); + Dafny.ISequence _97_coerceRhsArgs; + _97_coerceRhsArgs = Dafny.Sequence.FromElements(); + bool _98_isNumeric; + _98_isNumeric = false; + Dafny.ISequence _99_ctorMatchInner; + _99_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); + Dafny.ISequence _100_ctorMatchInner2; + _100_ctorMatchInner2 = Dafny.Sequence.UnicodeFromString(""); + BigInteger _hi10 = new BigInteger(((_90_ctor).dtor_args).Count); + for (BigInteger _101_j = BigInteger.Zero; _101_j < _hi10; _101_j++) { + DAST._IDatatypeDtor _102_dtor; + _102_dtor = ((_90_ctor).dtor_args).Select(_101_j); + Dafny.ISequence _103_patternName; + _103_patternName = Defs.__default.escapeVar(((_102_dtor).dtor_formal).dtor_name); + DAST._IType _104_formalType; + _104_formalType = ((_102_dtor).dtor_formal).dtor_typ; + if (((_101_j).Sign == 0) && ((_103_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _98_isNumeric = true; + } + if (_98_isNumeric) { + _103_patternName = Std.Wrappers.Option>.GetOr((_102_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_101_j))); + } + if ((_104_formalType).is_Arrow) { + _95_hashRhs = (_95_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); } else { - _98_hashRhs = (_98_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_106_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); + _95_hashRhs = (_95_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_103_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); } - _102_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_102_ctorMatchInner, _106_patternName), Dafny.Sequence.UnicodeFromString(", ")); - _103_ctorMatchInner2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_103_ctorMatchInner2, _106_patternName), Dafny.Sequence.UnicodeFromString(": ")), Dafny.Sequence.UnicodeFromString("_2_")), _106_patternName), Dafny.Sequence.UnicodeFromString(", ")); - if ((_107_formalType).is_Arrow) { - _99_partialEqRhs = (_99_partialEqRhs).And(RAST.Expr.create_LiteralBool(false)); + _99_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_99_ctorMatchInner, _103_patternName), Dafny.Sequence.UnicodeFromString(", ")); + _100_ctorMatchInner2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_100_ctorMatchInner2, _103_patternName), Dafny.Sequence.UnicodeFromString(": ")), Dafny.Sequence.UnicodeFromString("_2_")), _103_patternName), Dafny.Sequence.UnicodeFromString(", ")); + if ((_104_formalType).is_Arrow) { + _96_partialEqRhs = (_96_partialEqRhs).And(RAST.Expr.create_LiteralBool(false)); } else { - _99_partialEqRhs = (_99_partialEqRhs).And((RAST.Expr.create_Identifier(_106_patternName)).Equals(RAST.Expr.create_Identifier(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_2_"), _106_patternName)))); + _96_partialEqRhs = (_96_partialEqRhs).And((RAST.Expr.create_Identifier(_103_patternName)).Equals(RAST.Expr.create_Identifier(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_2_"), _103_patternName)))); } - if ((_104_j).Sign == 1) { - _97_printRhs = (_97_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); + if ((_101_j).Sign == 1) { + _94_printRhs = (_94_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); } - _97_printRhs = (_97_printRhs).Then((((_107_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_106_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); - RAST._IExpr _108_coerceRhsArg = RAST.Expr.Default(); - RAST._IType _109_formalTpe; + _94_printRhs = (_94_printRhs).Then((((_104_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_103_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); + RAST._IExpr _105_coerceRhsArg = RAST.Expr.Default(); + RAST._IType _106_formalTpe; RAST._IType _out21; - _out21 = (this).GenType(_107_formalType, Defs.GenTypeContext.@default()); - _109_formalTpe = _out21; - DAST._IType _110_newFormalType; - _110_newFormalType = (_107_formalType).Replace(_51_coerceMap); - RAST._IType _111_newFormalTpe; - _111_newFormalTpe = (_109_formalTpe).ReplaceMap(_52_rCoerceMap); - Std.Wrappers._IResult,RAST._IExpr>>> _112_upcastConverter; - _112_upcastConverter = (this).UpcastConversionLambda(_107_formalType, _109_formalTpe, _110_newFormalType, _111_newFormalTpe, _53_coerceMapToArg); - if ((_112_upcastConverter).is_Success) { - RAST._IExpr _113_coercionFunction; - _113_coercionFunction = (_112_upcastConverter).dtor_value; - _108_coerceRhsArg = (_113_coercionFunction).Apply1(RAST.Expr.create_Identifier(_106_patternName)); + _out21 = (this).GenType(_104_formalType, Defs.GenTypeContext.@default()); + _106_formalTpe = _out21; + DAST._IType _107_newFormalType; + _107_newFormalType = (_104_formalType).Replace(_51_coerceMap); + RAST._IType _108_newFormalTpe; + _108_newFormalTpe = (_106_formalTpe).ReplaceMap(_52_rCoerceMap); + Std.Wrappers._IResult,RAST._IExpr>>> _109_upcastConverter; + _109_upcastConverter = (this).UpcastConversionLambda(_104_formalType, _106_formalTpe, _107_newFormalType, _108_newFormalTpe, _53_coerceMapToArg); + if ((_109_upcastConverter).is_Success) { + RAST._IExpr _110_coercionFunction; + _110_coercionFunction = (_109_upcastConverter).dtor_value; + _105_coerceRhsArg = (_110_coercionFunction).Apply1(RAST.Expr.create_Identifier(_103_patternName)); } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_104_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); - _108_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); - } - _100_coerceRhsArgs = Dafny.Sequence.Concat(_100_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_106_patternName, _108_coerceRhsArg))); - } - RAST._IExpr _114_coerceRhs; - _114_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_93_ctor).dtor_name)), _100_coerceRhsArgs); - Dafny.ISequence _115_pattern = Dafny.Sequence.Empty; - Dafny.ISequence _116_pattern2 = Dafny.Sequence.Empty; - if (_101_isNumeric) { - _115_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _102_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); - _116_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _103_ctorMatchInner2), Dafny.Sequence.UnicodeFromString(")")); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_101_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); + _105_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); + } + _97_coerceRhsArgs = Dafny.Sequence.Concat(_97_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_103_patternName, _105_coerceRhsArg))); + } + RAST._IExpr _111_coerceRhs; + _111_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_90_ctor).dtor_name)), _97_coerceRhsArgs); + Dafny.ISequence _112_pattern = Dafny.Sequence.Empty; + Dafny.ISequence _113_pattern2 = Dafny.Sequence.Empty; + if (_98_isNumeric) { + _112_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_91_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _99_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + _113_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_91_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _100_ctorMatchInner2), Dafny.Sequence.UnicodeFromString(")")); } else { - _115_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _102_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); - _116_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _103_ctorMatchInner2), Dafny.Sequence.UnicodeFromString("}")); + _112_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_91_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _99_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + _113_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_91_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _100_ctorMatchInner2), Dafny.Sequence.UnicodeFromString("}")); } - if ((_93_ctor).dtor_hasAnyArgs) { - _97_printRhs = (_97_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); + if ((_90_ctor).dtor_hasAnyArgs) { + _94_printRhs = (_94_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); } - _97_printRhs = (_97_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); - _88_printImplBodyCases = Dafny.Sequence.Concat(_88_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _115_pattern), RAST.Expr.create_Block(_97_printRhs)))); - _89_hashImplBodyCases = Dafny.Sequence.Concat(_89_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _115_pattern), RAST.Expr.create_Block(_98_hashRhs)))); - _91_partialEqImplBodyCases = Dafny.Sequence.Concat(_91_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _115_pattern), Dafny.Sequence.UnicodeFromString(", ")), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _116_pattern2), Dafny.Sequence.UnicodeFromString(")")), RAST.Expr.create_Block(_99_partialEqRhs)))); - _90_coerceImplBodyCases = Dafny.Sequence.Concat(_90_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _94_ctorMatch), RAST.Expr.create_Block(_114_coerceRhs)))); + _94_printRhs = (_94_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); + _85_printImplBodyCases = Dafny.Sequence.Concat(_85_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _112_pattern), RAST.Expr.create_Block(_94_printRhs)))); + _86_hashImplBodyCases = Dafny.Sequence.Concat(_86_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _112_pattern), RAST.Expr.create_Block(_95_hashRhs)))); + _88_partialEqImplBodyCases = Dafny.Sequence.Concat(_88_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _112_pattern), Dafny.Sequence.UnicodeFromString(", ")), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _113_pattern2), Dafny.Sequence.UnicodeFromString(")")), RAST.Expr.create_Block(_96_partialEqRhs)))); + _87_coerceImplBodyCases = Dafny.Sequence.Concat(_87_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _91_ctorMatch), RAST.Expr.create_Block(_111_coerceRhs)))); } - _91_partialEqImplBodyCases = Dafny.Sequence.Concat(_91_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.UnicodeFromString("_"), RAST.Expr.create_Block(RAST.Expr.create_LiteralBool(false))))); + _88_partialEqImplBodyCases = Dafny.Sequence.Concat(_88_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.UnicodeFromString("_"), RAST.Expr.create_Block(RAST.Expr.create_LiteralBool(false))))); if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { - Dafny.ISequence _117_extraCases; - _117_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); - _88_printImplBodyCases = Dafny.Sequence.Concat(_88_printImplBodyCases, _117_extraCases); - _89_hashImplBodyCases = Dafny.Sequence.Concat(_89_hashImplBodyCases, _117_extraCases); - _90_coerceImplBodyCases = Dafny.Sequence.Concat(_90_coerceImplBodyCases, _117_extraCases); - } - Dafny.ISequence _118_defaultConstrainedTypeParams; - _118_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - RAST._IExpr _119_printImplBody; - _119_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _88_printImplBodyCases); - RAST._IExpr _120_hashImplBody; - _120_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _89_hashImplBodyCases); - RAST._IExpr _121_eqImplBody; - _121_eqImplBody = RAST.Expr.create_Match(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))), _91_partialEqImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _72_datatypeType, _2_rTypeParams, _119_printImplBody))); + Dafny.ISequence _114_extraCases; + _114_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + _85_printImplBodyCases = Dafny.Sequence.Concat(_85_printImplBodyCases, _114_extraCases); + _86_hashImplBodyCases = Dafny.Sequence.Concat(_86_hashImplBodyCases, _114_extraCases); + _87_coerceImplBodyCases = Dafny.Sequence.Concat(_87_coerceImplBodyCases, _114_extraCases); + } + Dafny.ISequence _115_defaultConstrainedTypeParams; + _115_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + RAST._IExpr _116_printImplBody; + _116_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _85_printImplBodyCases); + RAST._IExpr _117_hashImplBody; + _117_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _86_hashImplBodyCases); + RAST._IExpr _118_eqImplBody; + _118_eqImplBody = RAST.Expr.create_Match(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))), _88_partialEqImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams, _116_printImplBody))); if ((new BigInteger((_49_rCoerceTypeParams).Count)).Sign == 1) { - RAST._IExpr _122_coerceImplBody; - _122_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _90_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _72_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _122_coerceImplBody))); + RAST._IExpr _119_coerceImplBody; + _119_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _87_coerceImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _69_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _119_coerceImplBody))); } if ((new BigInteger((_9_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { - RAST._IType _123_instantiationType; + RAST._IType _120_instantiationType; if (_0_isRcWrapped) { - _123_instantiationType = RAST.__default.Rc(_72_datatypeType); + _120_instantiationType = RAST.__default.Rc(_69_datatypeType); } else { - _123_instantiationType = _72_datatypeType; + _120_instantiationType = _69_datatypeType; } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _72_datatypeType, _123_instantiationType, _9_singletonConstructors))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _69_datatypeType, _120_instantiationType, _9_singletonConstructors))); } if ((((c).dtor_equalitySupport).is_Always) || (((c).dtor_equalitySupport).is_ConsultTypeArguments)) { - Dafny.ISequence _124_rTypeParamsDeclsWithEq; - _124_rTypeParamsDeclsWithEq = _3_rTypeParamsDecls; - Dafny.ISequence _125_rTypeParamsDeclsWithHash; - _125_rTypeParamsDeclsWithHash = _3_rTypeParamsDecls; + Dafny.ISequence _121_rTypeParamsDeclsWithEq; + _121_rTypeParamsDeclsWithEq = _3_rTypeParamsDecls; + Dafny.ISequence _122_rTypeParamsDeclsWithHash; + _122_rTypeParamsDeclsWithHash = _3_rTypeParamsDecls; if (((c).dtor_equalitySupport).is_ConsultTypeArguments) { BigInteger _hi11 = new BigInteger((_3_rTypeParamsDecls).Count); - for (BigInteger _126_i = BigInteger.Zero; _126_i < _hi11; _126_i++) { - if (((((c).dtor_typeParams).Select(_126_i)).dtor_info).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype) { - _124_rTypeParamsDeclsWithEq = Dafny.Sequence.Update(_124_rTypeParamsDeclsWithEq, _126_i, ((_124_rTypeParamsDeclsWithEq).Select(_126_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Eq, RAST.__default.Hash))); - _125_rTypeParamsDeclsWithHash = Dafny.Sequence.Update(_125_rTypeParamsDeclsWithHash, _126_i, ((_125_rTypeParamsDeclsWithHash).Select(_126_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Hash))); + for (BigInteger _123_i = BigInteger.Zero; _123_i < _hi11; _123_i++) { + if (((((c).dtor_typeParams).Select(_123_i)).dtor_info).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype) { + _121_rTypeParamsDeclsWithEq = Dafny.Sequence.Update(_121_rTypeParamsDeclsWithEq, _123_i, ((_121_rTypeParamsDeclsWithEq).Select(_123_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Eq, RAST.__default.Hash))); + _122_rTypeParamsDeclsWithHash = Dafny.Sequence.Update(_122_rTypeParamsDeclsWithHash, _123_i, ((_122_rTypeParamsDeclsWithHash).Select(_123_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Hash))); } } } - s = Dafny.Sequence.Concat(s, Defs.__default.EqImpl(_124_rTypeParamsDeclsWithEq, _72_datatypeType, _2_rTypeParams, _121_eqImplBody)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_125_rTypeParamsDeclsWithHash, _72_datatypeType, _120_hashImplBody))); + s = Dafny.Sequence.Concat(s, Defs.__default.EqImpl(_121_rTypeParamsDeclsWithEq, _69_datatypeType, _2_rTypeParams, _118_eqImplBody)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_122_rTypeParamsDeclsWithHash, _69_datatypeType, _117_hashImplBody))); } if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - RAST._IExpr _127_structName; - _127_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _128_structAssignments; - _128_structAssignments = Dafny.Sequence.FromElements(); + RAST._IExpr _124_structName; + _124_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _125_structAssignments; + _125_structAssignments = Dafny.Sequence.FromElements(); BigInteger _hi12 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); - for (BigInteger _129_i = BigInteger.Zero; _129_i < _hi12; _129_i++) { - DAST._IDatatypeDtor _130_dtor; - _130_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_129_i); - _128_structAssignments = Dafny.Sequence.Concat(_128_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_130_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); + for (BigInteger _126_i = BigInteger.Zero; _126_i < _hi12; _126_i++) { + DAST._IDatatypeDtor _127_dtor; + _127_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_126_i); + _125_structAssignments = Dafny.Sequence.Concat(_125_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_127_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); } - if ((false) && (_71_cIsAlwaysEq)) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _72_datatypeType, _127_structName, _128_structAssignments))); + if ((false) && (_68_cIsAlwaysEq)) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _69_datatypeType, _124_structName, _125_structAssignments))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _72_datatypeType))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _69_datatypeType))); } - Dafny.ISequence _131_superTraitImplementations; + Dafny.ISequence _128_superTraitImplementations; Dafny.ISequence _out22; - _out22 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, _71_cIsAlwaysEq, Dafny.Sequence.UnicodeFromString("datatype")); - _131_superTraitImplementations = _out22; - s = Dafny.Sequence.Concat(s, _131_superTraitImplementations); + _out22 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, _68_cIsAlwaysEq, Dafny.Sequence.UnicodeFromString("datatype")); + _128_superTraitImplementations = _out22; + s = Dafny.Sequence.Concat(s, _128_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -2280,15 +2089,15 @@ public RAST._IImplMember GenMethod(DAST._IMethod m, bool forTrait, DAST._IType e after_match1: ; _32_env = Defs.Environment.create(Dafny.Sequence>.Concat(_34_preAssignNames, _1_paramNames), Dafny.Map, RAST._IType>.Merge(_35_preAssignTypes, _2_paramTypes), Dafny.Set>.FromElements()); RAST._IExpr _50_body; - Dafny.ISet> _51___v50; - Defs._IEnvironment _52___v51; + Dafny.ISet> _51___v14; + Defs._IEnvironment _52___v15; RAST._IExpr _out6; Dafny.ISet> _out7; Defs._IEnvironment _out8; (this).GenStmts((m).dtor_body, _8_selfIdent, _32_env, true, _36_earlyReturn, out _out6, out _out7, out _out8); _50_body = _out6; - _51___v50 = _out7; - _52___v51 = _out8; + _51___v14 = _out7; + _52___v15 = _out8; _31_fBody = Std.Wrappers.Option.create_Some((_33_preBody).Then(_50_body)); } else { _32_env = Defs.Environment.create(_1_paramNames, _2_paramTypes, Dafny.Set>.FromElements()); @@ -2581,14 +2390,14 @@ public void GenAssignLhs(DAST._IAssignLhs lhs, RAST._IExpr rhs, Defs._ISelfInfo BigInteger _hi0 = new BigInteger((_12_indices).Count); for (BigInteger _18_i = BigInteger.Zero; _18_i < _hi0; _18_i++) { RAST._IExpr _19_idx; - Defs._IOwnership _20___v59; + Defs._IOwnership _20___v23; Dafny.ISet> _21_recIdentsIdx; RAST._IExpr _out6; Defs._IOwnership _out7; Dafny.ISet> _out8; (this).GenExpr((_12_indices).Select(_18_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out6, out _out7, out _out8); _19_idx = _out6; - _20___v59 = _out7; + _20___v23 = _out7; _21_recIdentsIdx = _out8; Dafny.ISequence _22_varName; _22_varName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("__idx"), Std.Strings.__default.OfNat(_18_i)); @@ -2796,15 +2605,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _5_isAssignedVar = Defs.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { RAST._IExpr _6_rhs; - Defs._IOwnership _7___v73; - Dafny.ISet> _8___v74; + Defs._IOwnership _7___v37; + Dafny.ISet> _8___v38; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr(DAST.Expression.create_InitializationValue(((_2_field).dtor_formal).dtor_typ), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); _6_rhs = _out1; - _7___v73 = _out2; - _8___v74 = _out3; + _7___v37 = _out2; + _8___v38 = _out3; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); Dafny.ISequence _9_update__if__uninit; if ((_2_field).dtor_isConstant) { @@ -2899,14 +2708,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _22_expression = _source0.dtor_value; { RAST._IExpr _23_exprGen; - Defs._IOwnership _24___v75; + Defs._IOwnership _24___v39; Dafny.ISet> _25_exprIdents; RAST._IExpr _out12; Defs._IOwnership _out13; Dafny.ISet> _out14; (this).GenExpr(_22_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out12, out _out13, out _out14); _23_exprGen = _out12; - _24___v75 = _out13; + _24___v39 = _out13; _25_exprIdents = _out14; if ((_21_lhs).is_Ident) { Dafny.ISequence _26_rustId; @@ -2956,14 +2765,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _36_elsDafny = _source0.dtor_els; { RAST._IExpr _37_cond; - Defs._IOwnership _38___v76; + Defs._IOwnership _38___v40; Dafny.ISet> _39_recIdents; RAST._IExpr _out19; Defs._IOwnership _out20; Dafny.ISet> _out21; (this).GenExpr(_34_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out19, out _out20, out _out21); _37_cond = _out19; - _38___v76 = _out20; + _38___v40 = _out20; _39_recIdents = _out21; Dafny.ISequence _40_condString; _40_condString = (_37_cond)._ToString(Defs.__default.IND); @@ -3024,14 +2833,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _53_body = _source0.dtor_body; { RAST._IExpr _54_cond; - Defs._IOwnership _55___v77; + Defs._IOwnership _55___v41; Dafny.ISet> _56_recIdents; RAST._IExpr _out31; Defs._IOwnership _out32; Dafny.ISet> _out33; (this).GenExpr(_52_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out31, out _out32, out _out33); _54_cond = _out31; - _55___v77 = _out32; + _55___v41 = _out32; _56_recIdents = _out33; readIdents = _56_recIdents; RAST._IExpr _57_bodyExpr; @@ -3059,14 +2868,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _63_body = _source0.dtor_body; { RAST._IExpr _64_over; - Defs._IOwnership _65___v78; + Defs._IOwnership _65___v42; Dafny.ISet> _66_recIdents; RAST._IExpr _out37; Defs._IOwnership _out38; Dafny.ISet> _out39; (this).GenExpr(_62_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out37, out _out38, out _out39); _64_over = _out37; - _65___v78 = _out38; + _65___v42 = _out38; _66_recIdents = _out39; if (((_62_overExpr).is_MapBoundedPool) || ((_62_overExpr).is_SetBoundedPool)) { _64_over = ((_64_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); @@ -3130,15 +2939,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv _75_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { RAST._IExpr _76_selfClone; - Defs._IOwnership _77___v79; - Dafny.ISet> _78___v80; + Defs._IOwnership _77___v43; + Dafny.ISet> _78___v44; RAST._IExpr _out44; Defs._IOwnership _out45; Dafny.ISet> _out46; (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out44, out _out45, out _out46); _76_selfClone = _out44; - _77___v79 = _out45; - _78___v80 = _out46; + _77___v43 = _out45; + _78___v44 = _out46; generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_76_selfClone))); if (((_75_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { _75_oldEnv = (_75_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); @@ -3155,15 +2964,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv goto continue_4_0; } RAST._IExpr _82_paramInit; - Defs._IOwnership _83___v81; - Dafny.ISet> _84___v82; + Defs._IOwnership _83___v45; + Dafny.ISet> _84___v46; RAST._IExpr _out47; Defs._IOwnership _out48; Dafny.ISet> _out49; (this).GenIdent(_81_param, selfIdent, _75_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out47, out _out48, out _out49); _82_paramInit = _out47; - _83___v81 = _out48; - _84___v82 = _out49; + _83___v45 = _out48; + _84___v46 = _out49; Dafny.ISequence _85_recVar; _85_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_80_paramI)); generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _85_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_82_paramInit))); @@ -3255,14 +3064,14 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv DAST._IExpression _102_exprDafny = _source0.dtor_expr; { RAST._IExpr _103_expr; - Defs._IOwnership _104___v83; + Defs._IOwnership _104___v47; Dafny.ISet> _105_recIdents; RAST._IExpr _out55; Defs._IOwnership _out56; Dafny.ISet> _out57; (this).GenExpr(_102_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out55, out _out56, out _out57); _103_expr = _out55; - _104___v83 = _out56; + _104___v47 = _out56; _105_recIdents = _out57; readIdents = _105_recIdents; if (isLast) { @@ -3292,15 +3101,15 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv BigInteger _hi3 = new BigInteger((_106_rustIdents).Count); for (BigInteger _108_i = BigInteger.Zero; _108_i < _hi3; _108_i++) { RAST._IExpr _109_rIdent; - Defs._IOwnership _110___v84; - Dafny.ISet> _111___v85; + Defs._IOwnership _110___v48; + Dafny.ISet> _111___v49; RAST._IExpr _out58; Defs._IOwnership _out59; Dafny.ISet> _out60; (this).GenIdent((_106_rustIdents).Select(_108_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out58, out _out59, out _out60); _109_rIdent = _out58; - _110___v84 = _out59; - _111___v85 = _out60; + _110___v48 = _out59; + _111___v49 = _out60; _107_tupleArgs = Dafny.Sequence.Concat(_107_tupleArgs, Dafny.Sequence.FromElements(_109_rIdent)); } if ((new BigInteger((_107_tupleArgs).Count)) == (BigInteger.One)) { @@ -3696,24 +3505,24 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ _10_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); } RAST._IExpr _11_left; - Defs._IOwnership _12___v86; + Defs._IOwnership _12___v50; Dafny.ISet> _13_recIdentsL; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(_4_lExpr, selfIdent, env, _9_expectedLeftOwnership, out _out0, out _out1, out _out2); _11_left = _out0; - _12___v86 = _out1; + _12___v50 = _out1; _13_recIdentsL = _out2; RAST._IExpr _14_right; - Defs._IOwnership _15___v87; + Defs._IOwnership _15___v51; Dafny.ISet> _16_recIdentsR; RAST._IExpr _out3; Defs._IOwnership _out4; Dafny.ISet> _out5; (this).GenExpr(_5_rExpr, selfIdent, env, _10_expectedRightOwnership, out _out3, out _out4, out _out5); _14_right = _out3; - _15___v87 = _out4; + _15___v51 = _out4; _16_recIdentsR = _out5; DAST._IBinOp _source0 = _0_op; { @@ -4839,14 +4648,14 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v100; + Defs._IOwnership _5___v64; Dafny.ISet> _6_argIdents; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); _4_argExpr = _out1; - _5___v100 = _out2; + _5___v64 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -5044,14 +4853,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi1 = new BigInteger((_9_values).Count); for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13___v110; + Defs._IOwnership _13___v74; Dafny.ISet> _14_recIdents; RAST._IExpr _out16; Defs._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); _12_recursiveGen = _out16; - _13___v110 = _out17; + _13___v74 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -5100,14 +4909,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi3 = new BigInteger((_17_args).Count); for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { RAST._IExpr _23_recursiveGen; - Defs._IOwnership _24___v111; + Defs._IOwnership _24___v75; Dafny.ISet> _25_recIdents; RAST._IExpr _out23; Defs._IOwnership _out24; Dafny.ISet> _out25; (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); _23_recursiveGen = _out23; - _24___v111 = _out24; + _24___v75 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -5145,14 +4954,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi4 = new BigInteger((_26_dims).Count); for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { RAST._IExpr _31_recursiveGen; - Defs._IOwnership _32___v112; + Defs._IOwnership _32___v76; Dafny.ISet> _33_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr((_26_dims).Select(_30_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _31_recursiveGen = _out30; - _32___v112 = _out31; + _32___v76 = _out31; _33_recIdents = _out32; _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); @@ -5179,14 +4988,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _35_underlying = _source0.dtor_value; { RAST._IExpr _36_recursiveGen; - Defs._IOwnership _37___v113; + Defs._IOwnership _37___v77; Dafny.ISet> _38_recIdents; RAST._IExpr _out35; Defs._IOwnership _out36; Dafny.ISet> _out37; (this).GenExpr(_35_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out35, out _out36, out _out37); _36_recursiveGen = _out35; - _37___v113 = _out36; + _37___v77 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -5209,14 +5018,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out40 = (this).GenType(_40_typ, Defs.GenTypeContext.@default()); _41_tpe = _out40; RAST._IExpr _42_recursiveGen; - Defs._IOwnership _43___v114; + Defs._IOwnership _43___v78; Dafny.ISet> _44_recIdents; RAST._IExpr _out41; Defs._IOwnership _out42; Dafny.ISet> _out43; (this).GenExpr(_39_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); _42_recursiveGen = _out41; - _43___v114 = _out42; + _43___v78 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -5282,14 +5091,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; if (_50_isCo) { RAST._IExpr _59_recursiveGen; - Defs._IOwnership _60___v115; + Defs._IOwnership _60___v79; Dafny.ISet> _61_recIdents; RAST._IExpr _out50; Defs._IOwnership _out51; Dafny.ISet> _out52; (this).GenExpr(_58_value, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); _59_recursiveGen = _out50; - _60___v115 = _out51; + _60___v79 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -5312,14 +5121,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _64_wasAssigned))); } else { RAST._IExpr _65_recursiveGen; - Defs._IOwnership _66___v116; + Defs._IOwnership _66___v80; Dafny.ISet> _67_recIdents; RAST._IExpr _out53; Defs._IOwnership _out54; Dafny.ISet> _out55; (this).GenExpr(_58_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out53, out _out54, out _out55); _65_recursiveGen = _out53; - _66___v116 = _out54; + _66___v80 = _out54; _67_recIdents = _out55; _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _65_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); @@ -5359,24 +5168,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _69_expr = _source0.dtor_elem; { RAST._IExpr _70_recursiveGen; - Defs._IOwnership _71___v120; + Defs._IOwnership _71___v84; Dafny.ISet> _72_recIdents; RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; (this).GenExpr(_69_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); _70_recursiveGen = _out61; - _71___v120 = _out62; + _71___v84 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v121; + Defs._IOwnership _74___v85; Dafny.ISet> _75_lengthIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_68_length, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); _73_lengthGen = _out64; - _74___v121 = _out65; + _74___v85 = _out65; _75_lengthIdents = _out66; r = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("_initializer"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_70_recursiveGen)); RAST._IExpr _76_range; @@ -5415,14 +5224,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _82_args = Dafny.Sequence.FromElements(); while ((_81_i) < (new BigInteger((_78_exprs).Count))) { RAST._IExpr _83_recursiveGen; - Defs._IOwnership _84___v122; + Defs._IOwnership _84___v86; Dafny.ISet> _85_recIdents; RAST._IExpr _out70; Defs._IOwnership _out71; Dafny.ISet> _out72; (this).GenExpr((_78_exprs).Select(_81_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out70, out _out71, out _out72); _83_recursiveGen = _out70; - _84___v122 = _out71; + _84___v86 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -5453,14 +5262,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _88_i = BigInteger.Zero; while ((_88_i) < (new BigInteger((_86_exprs).Count))) { RAST._IExpr _89_recursiveGen; - Defs._IOwnership _90___v123; + Defs._IOwnership _90___v87; Dafny.ISet> _91_recIdents; RAST._IExpr _out75; Defs._IOwnership _out76; Dafny.ISet> _out77; (this).GenExpr((_86_exprs).Select(_88_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out75, out _out76, out _out77); _89_recursiveGen = _out75; - _90___v123 = _out76; + _90___v87 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -5488,14 +5297,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _94_i = BigInteger.Zero; while ((_94_i) < (new BigInteger((_92_exprs).Count))) { RAST._IExpr _95_recursiveGen; - Defs._IOwnership _96___v124; + Defs._IOwnership _96___v88; Dafny.ISet> _97_recIdents; RAST._IExpr _out80; Defs._IOwnership _out81; Dafny.ISet> _out82; (this).GenExpr((_92_exprs).Select(_94_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out80, out _out81, out _out82); _95_recursiveGen = _out80; - _96___v124 = _out81; + _96___v88 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -5517,14 +5326,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _98_expr = _source0.dtor_ToMultiset_a0; { RAST._IExpr _99_recursiveGen; - Defs._IOwnership _100___v125; + Defs._IOwnership _100___v89; Dafny.ISet> _101_recIdents; RAST._IExpr _out85; Defs._IOwnership _out86; Dafny.ISet> _out87; (this).GenExpr(_98_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out85, out _out86, out _out87); _99_recursiveGen = _out85; - _100___v125 = _out86; + _100___v89 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -5549,24 +5358,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _104_i = BigInteger.Zero; while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v126; + Defs._IOwnership _106___v90; Dafny.ISet> _107_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); _105_recursiveGenKey = _out90; - _106___v126 = _out91; + _106___v90 = _out91; _107_recIdentsKey = _out92; RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v127; + Defs._IOwnership _109___v91; Dafny.ISet> _110_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); _108_recursiveGenValue = _out93; - _109___v127 = _out94; + _109___v91 = _out94; _110_recIdentsValue = _out95; _103_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_103_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_105_recursiveGenKey, _108_recursiveGenValue))); readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _107_recIdentsKey), _110_recIdentsValue); @@ -5601,14 +5410,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _116_value = _source0.dtor_value; { RAST._IExpr _117_exprR; - Defs._IOwnership _118___v128; + Defs._IOwnership _118___v92; Dafny.ISet> _119_exprIdents; RAST._IExpr _out98; Defs._IOwnership _out99; Dafny.ISet> _out100; (this).GenExpr(_114_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out98, out _out99, out _out100); _117_exprR = _out98; - _118___v128 = _out99; + _118___v92 = _out99; _119_exprIdents = _out100; RAST._IExpr _120_indexR; Defs._IOwnership _121_indexOwnership; @@ -5649,14 +5458,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _128_value = _source0.dtor_value; { RAST._IExpr _129_exprR; - Defs._IOwnership _130___v129; + Defs._IOwnership _130___v93; Dafny.ISet> _131_exprIdents; RAST._IExpr _out109; Defs._IOwnership _out110; Dafny.ISet> _out111; (this).GenExpr(_126_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out109, out _out110, out _out111); _129_exprR = _out109; - _130___v129 = _out110; + _130___v93 = _out110; _131_exprIdents = _out111; RAST._IExpr _132_indexR; Defs._IOwnership _133_indexOwnership; @@ -5737,14 +5546,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _143_f = _source0.dtor_els; { RAST._IExpr _144_cond; - Defs._IOwnership _145___v130; + Defs._IOwnership _145___v94; Dafny.ISet> _146_recIdentsCond; RAST._IExpr _out126; Defs._IOwnership _out127; Dafny.ISet> _out128; (this).GenExpr(_141_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out126, out _out127, out _out128); _144_cond = _out126; - _145___v130 = _out127; + _145___v94 = _out127; _146_recIdentsCond = _out128; RAST._IExpr _147_fExpr; Defs._IOwnership _148_fOwned; @@ -5757,14 +5566,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _148_fOwned = _out130; _149_recIdentsF = _out131; RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v131; + Defs._IOwnership _151___v95; Dafny.ISet> _152_recIdentsT; RAST._IExpr _out132; Defs._IOwnership _out133; Dafny.ISet> _out134; (this).GenExpr(_142_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); _150_tExpr = _out132; - _151___v131 = _out133; + _151___v95 = _out133; _152_recIdentsT = _out134; r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); RAST._IExpr _out135; @@ -5786,14 +5595,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; { RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v132; + Defs._IOwnership _156___v96; Dafny.ISet> _157_recIdents; RAST._IExpr _out137; Defs._IOwnership _out138; Dafny.ISet> _out139; (this).GenExpr(_153_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out137, out _out138, out _out139); _155_recursiveGen = _out137; - _156___v132 = _out138; + _156___v96 = _out138; _157_recIdents = _out139; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); RAST._IExpr _out140; @@ -5816,14 +5625,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; { RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v133; + Defs._IOwnership _161___v97; Dafny.ISet> _162_recIdents; RAST._IExpr _out142; Defs._IOwnership _out143; Dafny.ISet> _out144; (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out142, out _out143, out _out144); _160_recursiveGen = _out142; - _161___v133 = _out143; + _161___v97 = _out143; _162_recIdents = _out144; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); RAST._IExpr _out145; @@ -5888,14 +5697,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _171_native = _source0.dtor_native; { RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v138; + Defs._IOwnership _173___v102; Dafny.ISet> _174_recIdents; RAST._IExpr _out155; Defs._IOwnership _out156; Dafny.ISet> _out157; (this).GenExpr(_168_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out155, out _out156, out _out157); _172_recursiveGen = _out155; - _173___v138 = _out156; + _173___v102 = _out156; _174_recIdents = _out157; RAST._IType _175_arrayType; RAST._IType _out158; @@ -5937,14 +5746,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _177_expr = _source0.dtor_expr; { RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v139; + Defs._IOwnership _179___v103; Dafny.ISet> _180_recIdents; RAST._IExpr _out162; Defs._IOwnership _out163; Dafny.ISet> _out164; (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); _178_recursiveGen = _out162; - _179___v139 = _out163; + _179___v103 = _out163; _180_recIdents = _out164; readIdents = _180_recIdents; r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); @@ -5963,14 +5772,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _181_expr = _source0.dtor_expr; { RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v140; + Defs._IOwnership _183___v104; Dafny.ISet> _184_recIdents; RAST._IExpr _out167; Defs._IOwnership _out168; Dafny.ISet> _out169; (this).GenExpr(_181_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); _182_recursiveGen = _out167; - _183___v140 = _out168; + _183___v104 = _out168; _184_recIdents = _out169; readIdents = _184_recIdents; r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); @@ -5989,14 +5798,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _185_expr = _source0.dtor_expr; { RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v141; + Defs._IOwnership _187___v105; Dafny.ISet> _188_recIdents; RAST._IExpr _out172; Defs._IOwnership _out173; Dafny.ISet> _out174; (this).GenExpr(_185_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out172, out _out173, out _out174); _186_recursiveGen = _out172; - _187___v141 = _out173; + _187___v105 = _out173; _188_recIdents = _out174; readIdents = _188_recIdents; r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); @@ -6068,15 +5877,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _209_name = _let_tmp_rhs1.dtor__0; RAST._IType _210_ty = _let_tmp_rhs1.dtor__1; RAST._IExpr _211_rIdent; - Defs._IOwnership _212___v142; - Dafny.ISet> _213___v143; + Defs._IOwnership _212___v106; + Dafny.ISet> _213___v107; RAST._IExpr _out181; Defs._IOwnership _out182; Dafny.ISet> _out183; (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((!(_193_isConstant)) && ((_210_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); _211_rIdent = _out181; - _212___v142 = _out182; - _213___v143 = _out183; + _212___v106 = _out182; + _213___v107 = _out183; _207_onExprArgs = Dafny.Sequence.Concat(_207_onExprArgs, Dafny.Sequence.FromElements(_211_rIdent)); } _206_body = (_206_body).Apply(_207_onExprArgs); @@ -6394,14 +6203,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _260_l = _source5.dtor_value; { RAST._IExpr _261_lExpr; - Defs._IOwnership _262___v146; + Defs._IOwnership _262___v110; Dafny.ISet> _263_recIdentsL; RAST._IExpr _out222; Defs._IOwnership _out223; Dafny.ISet> _out224; (this).GenExpr(_260_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out222, out _out223, out _out224); _261_lExpr = _out222; - _262___v146 = _out223; + _262___v110 = _out223; _263_recIdentsL = _out224; _259_arguments = Dafny.Sequence.Concat(_259_arguments, Dafny.Sequence.FromElements(_261_lExpr)); readIdents = Dafny.Set>.Union(readIdents, _263_recIdentsL); @@ -6418,14 +6227,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _264_h = _source6.dtor_value; { RAST._IExpr _265_hExpr; - Defs._IOwnership _266___v147; + Defs._IOwnership _266___v111; Dafny.ISet> _267_recIdentsH; RAST._IExpr _out225; Defs._IOwnership _out226; Dafny.ISet> _out227; (this).GenExpr(_264_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out225, out _out226, out _out227); _265_hExpr = _out225; - _266___v147 = _out226; + _266___v111 = _out226; _267_recIdentsH = _out227; _259_arguments = Dafny.Sequence.Concat(_259_arguments, Dafny.Sequence.FromElements(_265_hExpr)); readIdents = Dafny.Set>.Union(readIdents, _267_recIdentsH); @@ -6555,14 +6364,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _289_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_285_paramNames, _286_paramTypesMap, Dafny.Set>.FromElements())); RAST._IExpr _290_recursiveGen; Dafny.ISet> _291_recIdents; - Defs._IEnvironment _292___v149; + Defs._IEnvironment _292___v113; RAST._IExpr _out240; Dafny.ISet> _out241; Defs._IEnvironment _out242; (this).GenStmts(_283_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _289_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out240, out _out241, out _out242); _290_recursiveGen = _out240; _291_recIdents = _out241; - _292___v149 = _out242; + _292___v113 = _out242; readIdents = Dafny.Set>.FromElements(); _291_recIdents = Dafny.Set>.Difference(_291_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_293_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); @@ -6588,15 +6397,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir after__ASSIGN_SUCH_THAT_1: ; if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_296_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { RAST._IExpr _297_selfCloned; - Defs._IOwnership _298___v150; - Dafny.ISet> _299___v151; + Defs._IOwnership _298___v114; + Dafny.ISet> _299___v115; RAST._IExpr _out243; Defs._IOwnership _out244; Dafny.ISet> _out245; (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out243, out _out244, out _out245); _297_selfCloned = _out243; - _298___v150 = _out244; - _299___v151 = _out245; + _298___v114 = _out244; + _299___v115 = _out245; _295_allReadCloned = (_295_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_297_selfCloned))); } else if (!((_285_paramNames).Contains(_296_next))) { RAST._IExpr _300_copy; @@ -6660,14 +6469,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out250 = (this).GenType((((_302_values).Select(_313_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); _314_typeGen = _out250; RAST._IExpr _315_valueGen; - Defs._IOwnership _316___v152; + Defs._IOwnership _316___v116; Dafny.ISet> _317_recIdents; RAST._IExpr _out251; Defs._IOwnership _out252; Dafny.ISet> _out253; (this).GenExpr(((_302_values).Select(_313_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out251, out _out252, out _out253); _315_valueGen = _out251; - _316___v152 = _out252; + _316___v116 = _out252; _317_recIdents = _out253; r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_302_values).Select(_313_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_314_typeGen), Std.Wrappers.Option.create_Some(_315_valueGen))); readIdents = Dafny.Set>.Union(readIdents, _317_recIdents); @@ -6704,14 +6513,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _325_iifeBody = _source0.dtor_iifeBody; { RAST._IExpr _326_valueGen; - Defs._IOwnership _327___v153; + Defs._IOwnership _327___v117; Dafny.ISet> _328_recIdents; RAST._IExpr _out259; Defs._IOwnership _out260; Dafny.ISet> _out261; (this).GenExpr(_324_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out259, out _out260, out _out261); _326_valueGen = _out259; - _327___v153 = _out260; + _327___v117 = _out260; _328_recIdents = _out261; readIdents = _328_recIdents; RAST._IType _329_valueTypeGen; @@ -6721,14 +6530,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _330_iifeVar; _330_iifeVar = Defs.__default.escapeVar(_322_name); RAST._IExpr _331_bodyGen; - Defs._IOwnership _332___v154; + Defs._IOwnership _332___v118; Dafny.ISet> _333_bodyIdents; RAST._IExpr _out263; Defs._IOwnership _out264; Dafny.ISet> _out265; (this).GenExpr(_325_iifeBody, selfIdent, (env).AddAssigned(_330_iifeVar, _329_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out263, out _out264, out _out265); _331_bodyGen = _out263; - _332___v154 = _out264; + _332___v118 = _out264; _333_bodyIdents = _out265; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_333_bodyIdents, Dafny.Set>.FromElements(_330_iifeVar))); r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _330_iifeVar, Std.Wrappers.Option.create_Some(_329_valueTypeGen), Std.Wrappers.Option.create_Some(_326_valueGen))).Then(_331_bodyGen)); @@ -6748,14 +6557,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _335_args = _source0.dtor_args; { RAST._IExpr _336_funcExpr; - Defs._IOwnership _337___v155; + Defs._IOwnership _337___v119; Dafny.ISet> _338_recIdents; RAST._IExpr _out268; Defs._IOwnership _out269; Dafny.ISet> _out270; (this).GenExpr(_334_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out268, out _out269, out _out270); _336_funcExpr = _out268; - _337___v155 = _out269; + _337___v119 = _out269; _338_recIdents = _out270; readIdents = _338_recIdents; Dafny.ISequence _339_rArgs; @@ -6793,14 +6602,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _346_variant = _source0.dtor_variant; { RAST._IExpr _347_exprGen; - Defs._IOwnership _348___v156; + Defs._IOwnership _348___v120; Dafny.ISet> _349_recIdents; RAST._IExpr _out276; Defs._IOwnership _out277; Dafny.ISet> _out278; (this).GenExpr(_344_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out276, out _out277, out _out278); _347_exprGen = _out276; - _348___v156 = _out277; + _348___v120 = _out277; _349_recIdents = _out278; RAST._IExpr _350_variantExprPath; RAST._IExpr _out279; @@ -6935,14 +6744,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _368_of = _source0.dtor_of; { RAST._IExpr _369_exprGen; - Defs._IOwnership _370___v157; + Defs._IOwnership _370___v121; Dafny.ISet> _371_recIdents; RAST._IExpr _out300; Defs._IOwnership _out301; Dafny.ISet> _out302; (this).GenExpr(_368_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out300, out _out301, out _out302); _369_exprGen = _out300; - _370___v157 = _out301; + _370___v121 = _out301; _371_recIdents = _out302; r = ((_369_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out303; @@ -6962,14 +6771,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _373_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _374_exprGen; - Defs._IOwnership _375___v158; + Defs._IOwnership _375___v122; Dafny.ISet> _376_recIdents; RAST._IExpr _out305; Defs._IOwnership _out306; Dafny.ISet> _out307; (this).GenExpr(_372_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out305, out _out306, out _out307); _374_exprGen = _out305; - _375___v158 = _out306; + _375___v122 = _out306; _376_recIdents = _out307; r = ((_374_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_373_includeDuplicates)) { @@ -6992,14 +6801,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _378_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _379_exprGen; - Defs._IOwnership _380___v159; + Defs._IOwnership _380___v123; Dafny.ISet> _381_recIdents; RAST._IExpr _out310; Defs._IOwnership _out311; Dafny.ISet> _out312; (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out310, out _out311, out _out312); _379_exprGen = _out310; - _380___v159 = _out311; + _380___v123 = _out311; _381_recIdents = _out312; r = ((_379_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_378_includeDuplicates)) { @@ -7021,14 +6830,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _382_of = _source0.dtor_of; { RAST._IExpr _383_exprGen; - Defs._IOwnership _384___v160; + Defs._IOwnership _384___v124; Dafny.ISet> _385_recIdents; RAST._IExpr _out315; Defs._IOwnership _out316; Dafny.ISet> _out317; (this).GenExpr(_382_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out315, out _out316, out _out317); _383_exprGen = _out315; - _384___v160 = _out316; + _384___v124 = _out316; _385_recIdents = _out317; r = ((((_383_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); readIdents = _385_recIdents; @@ -7046,14 +6855,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _386_of = _source0.dtor_of; { RAST._IExpr _387_exprGen; - Defs._IOwnership _388___v161; + Defs._IOwnership _388___v125; Dafny.ISet> _389_recIdents; RAST._IExpr _out320; Defs._IOwnership _out321; Dafny.ISet> _out322; (this).GenExpr(_386_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out320, out _out321, out _out322); _387_exprGen = _out320; - _388___v161 = _out321; + _388___v125 = _out321; _389_recIdents = _out322; r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_387_exprGen); readIdents = _389_recIdents; @@ -7074,24 +6883,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _393_up = _source0.dtor_up; { RAST._IExpr _394_lo; - Defs._IOwnership _395___v162; + Defs._IOwnership _395___v126; Dafny.ISet> _396_recIdentsLo; RAST._IExpr _out325; Defs._IOwnership _out326; Dafny.ISet> _out327; (this).GenExpr(_391_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out325, out _out326, out _out327); _394_lo = _out325; - _395___v162 = _out326; + _395___v126 = _out326; _396_recIdentsLo = _out327; RAST._IExpr _397_hi; - Defs._IOwnership _398___v163; + Defs._IOwnership _398___v127; Dafny.ISet> _399_recIdentsHi; RAST._IExpr _out328; Defs._IOwnership _out329; Dafny.ISet> _out330; (this).GenExpr(_392_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out328, out _out329, out _out330); _397_hi = _out328; - _398___v163 = _out329; + _398___v127 = _out329; _399_recIdentsHi = _out330; if (_393_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_394_lo, _397_hi)); @@ -7122,14 +6931,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _402_up = _source0.dtor_up; { RAST._IExpr _403_start; - Defs._IOwnership _404___v164; + Defs._IOwnership _404___v128; Dafny.ISet> _405_recIdentStart; RAST._IExpr _out334; Defs._IOwnership _out335; Dafny.ISet> _out336; (this).GenExpr(_401_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); _403_start = _out334; - _404___v164 = _out335; + _404___v128 = _out335; _405_recIdentStart = _out336; if (_402_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_403_start); @@ -7203,14 +7012,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out346 = (this).GenType(_412_elemType, Defs.GenTypeContext.@default()); _416_tpe = _out346; RAST._IExpr _417_collectionGen; - Defs._IOwnership _418___v165; + Defs._IOwnership _418___v129; Dafny.ISet> _419_recIdents; RAST._IExpr _out347; Defs._IOwnership _out348; Dafny.ISet> _out349; (this).GenExpr(_413_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out347, out _out348, out _out349); _417_collectionGen = _out347; - _418___v165 = _out348; + _418___v129 = _out348; _419_recIdents = _out349; Dafny.ISequence _420_extraAttributes; _420_extraAttributes = Dafny.Sequence.FromElements(); @@ -7233,14 +7042,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _428_dt__update_hparams_h0 = _422_newFormals; _426_newLambda = DAST.Expression.create_Lambda(_428_dt__update_hparams_h0, (_427_dt__update__tmp_h1).dtor_retType, (_427_dt__update__tmp_h1).dtor_body); RAST._IExpr _429_lambdaGen; - Defs._IOwnership _430___v166; + Defs._IOwnership _430___v130; Dafny.ISet> _431_recLambdaIdents; RAST._IExpr _out350; Defs._IOwnership _out351; Dafny.ISet> _out352; (this).GenExpr(_426_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out350, out _out351, out _out352); _429_lambdaGen = _out350; - _430___v166 = _out351; + _430___v130 = _out351; _431_recLambdaIdents = _out352; Dafny.ISequence _432_fn; if (_414_is__forall) { @@ -7347,15 +7156,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v167; - Dafny.ISet> _2___v168; + Defs._IOwnership _1___v131; + Dafny.ISet> _2___v132; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v167 = _out1; - _2___v168 = _out2; + _1___v131 = _out1; + _2___v132 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy index 39f09d84335..7da139919c9 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --type-system-refresh --general-traits=datatype "%s" > "%t" +// RUN: %baredafny run --target=rs --type-system-refresh --general-traits=datatype --general-newtypes "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait SuperTrait { @@ -18,7 +18,27 @@ datatype TestPrintTwice extends SubSuperTrait = TestPrintTwice { function toString(): string { "hello" } } +datatype NoSupportEquality extends SuperTrait = NoSupportEquality(ghost f: int -> int) { + function toString(): string { "Not a string" } +} + +newtype MapWrapper = x: map | true { + predicate Empty() { + |this| == 0 + } +} + +newtype SeqWrapper = x: seq | true { + predicate Empty() { + |this| == 0 + } +} + method Main() { + expect (map[] as MapWrapper).Empty(); + expect !(map[1 := 2] as MapWrapper).Empty(); + expect ([] as SeqWrapper).Empty(); + expect !([1] as SeqWrapper).Empty(); PrintTwice(TestPrintTwice()); PrintTwice((TestPrintTwice() as SubSuperTrait)); PrintTwice((TestPrintTwice() as SuperTrait)); From 04596a979bfbe27b3d84c05742b1b76ec586f306 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 16 Dec 2024 14:47:37 -0600 Subject: [PATCH 29/69] Applied addendum --- Makefile | 13 ++- Scripts/test-dafny.sh | 38 ++++++++ Scripts/test.sh | 59 ++++++++++++ .../AST/TypeDeclarations/NewtypeDecl.cs | 22 +++-- Source/DafnyCore/AST/Types/UserDefinedType.cs | 8 +- .../CheckTypeCharacteristics_Visitor.cs | 31 +++++- Source/DafnyCore/Resolver/ModuleResolver.cs | 94 ++++++++++--------- .../Resolver/TypeCharacteristicChecker.cs | 4 +- 8 files changed, 207 insertions(+), 62 deletions(-) create mode 100644 Scripts/test-dafny.sh create mode 100644 Scripts/test.sh diff --git a/Makefile b/Makefile index 72082165662..413c6d75a6e 100644 --- a/Makefile +++ b/Makefile @@ -30,17 +30,16 @@ boogie: ${DIR}/boogie/Binaries/Boogie.exe tests: (cd "${DIR}"; dotnet test Source/IntegrationTests) -# make test name= +# make test name= +# make test name= update=true to update the test +# make test name= build=false don't build the solution test: - (cd "${DIR}"; [ -z "${name}" ] && echo "Syntax: make test name=" && exit 1; dotnet test Source/IntegrationTests --filter "DisplayName~${name}") + @DIR="$(DIR)" name="$(name)" update="$(update)" build="$(build)" bash scripts/test.sh # Run Dafny on an integration test case directly in the folder itself. -# make test-run name= action="run ..." +# make test-dafny name= action="run ..." [build=false] test-dafny: - @name="$(name)" DIR="$(DIR)" action="$(action)" bash scripts/test-dafny.sh - -test-dafny-nobuild: - @name="$(name)" DIR="$(DIR)" action="$(action)" NO_BUILD="true" bash scripts/test-dafny.sh + @name="$(name)" DIR="$(DIR)" action="$(action)" NO_BUILD=$$( [ "${build}" = "false" ] && echo "true" || echo "false" ) bash scripts/test-dafny.sh tests-verbose: (cd "${DIR}"; dotnet test --logger "console;verbosity=normal" Source/IntegrationTests ) diff --git a/Scripts/test-dafny.sh b/Scripts/test-dafny.sh new file mode 100644 index 00000000000..cb684eea9aa --- /dev/null +++ b/Scripts/test-dafny.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Check for required environment variables +if [ -z "$DIR" ]; then + echo "Error: DIR environment variable is not set." + exit 1 +fi + +if [ -z "$name" ]; then + echo "Error: name environment variable is not set." + exit 1 +fi + +# Set the default build flag +NO_BUILD=${NO_BUILD:-false} + +# Locate files matching the specified pattern +files=$(cd "${DIR}/Source/IntegrationTests/TestFiles/LitTests/LitTest" && find . -type f -wholename "*$name*" | grep -E '\.dfy$') + +if [ -z "$files" ]; then + echo "No files found matching pattern: $name" + exit 1 +else + count=$(echo "$files" | wc -l) + echo "$files" + echo "$count test files found." + for file in $files; do + filedir=$(dirname "$file") + ( + cd "${DIR}/Source/IntegrationTests/TestFiles/LitTests/LitTest/$filedir" || exit + + build_flag="" + [ "$NO_BUILD" = "true" ] && build_flag="--no-build" + + dotnet run $build_flag --project "${DIR}/Source/Dafny" -- ${action} "$(basename "$file")" + ) + done +fi \ No newline at end of file diff --git a/Scripts/test.sh b/Scripts/test.sh new file mode 100644 index 00000000000..24225f4fdc7 --- /dev/null +++ b/Scripts/test.sh @@ -0,0 +1,59 @@ +#!/bin/bash +set -e + +# Ensure name is provided +if [ -z "$name" ]; then + echo "Syntax: make test name= [update=true] [build=false]" + exit 1 +fi + +# Default values for update and build +update_flag=${update:-false} +build_flag=${build:-true} + +# Set the integration tests folder +integration_tests_dir="${DIR}/Source/IntegrationTests" +lit_tests_dir="${integration_tests_dir}/TestFiles/LitTests/LitTest" + +# Handle no-build logic +if [ "$build_flag" = "false" ]; then + echo "" + echo "Build is disabled. Copying test files to the output directory..." + + framework_dir=$(find "${integration_tests_dir}/bin/Debug" -maxdepth 1 -type d -name "net*" | sort | tail -n 1) + if [ -z "$framework_dir" ]; then + echo "Error: Could not find target framework directory in bin/Debug. Please run at least once with build=true." + exit 1 + fi + output_dir="${framework_dir}/TestFiles/LitTests/LitTest" + + # Find and copy all matching files to the output directory + files=$(cd "$lit_tests_dir" && find . -type f -wholename "*$name*") + if [ -z "$files" ]; then + echo "No files found matching pattern: $name" + exit 1 + fi + + # Create output directory if it doesn't exist + mkdir -p "$output_dir" + + # Copy files + echo "$files" | while IFS= read -r file; do + echo "Copying $file to $output_dir" + cp "$lit_tests_dir/$file" "$output_dir/" + done +fi + +# Check if update flag is true +if [ "$update_flag" = "true" ]; then + echo "" + echo "Update mode enabled." + echo "Going to update the .expect files to match the current Dafny output." +fi + +# Run dotnet test +echo "Running integration tests..." +DAFNY_INTEGRATION_TESTS_UPDATE_EXPECT_FILE="$update_flag" \ +dotnet test "$integration_tests_dir" \ + $( [ "$build_flag" = "false" ] && echo "--no-build" ) \ + --filter "DisplayName~$name" diff --git a/Source/DafnyCore/AST/TypeDeclarations/NewtypeDecl.cs b/Source/DafnyCore/AST/TypeDeclarations/NewtypeDecl.cs index 608e237235e..fd3ba11742d 100644 --- a/Source/DafnyCore/AST/TypeDeclarations/NewtypeDecl.cs +++ b/Source/DafnyCore/AST/TypeDeclarations/NewtypeDecl.cs @@ -32,7 +32,7 @@ bool RedirectingTypeDecl.ConstraintIsCompilable { [FilledInDuringResolution] public bool TargetTypeCoversAllBitPatterns; // "target complete" -- indicates that any bit pattern that can fill the target type is a value of the newtype - public NewtypeDecl(IOrigin rangeOrigin, Name name, List typeParameters, ModuleDefinition module, + public NewtypeDecl(RangeToken rangeOrigin, Name name, List typeParameters, ModuleDefinition module, Type baseType, SubsetTypeDecl.WKind witnessKind, Expression witness, List parentTraits, List members, Attributes attributes, bool isRefining) : base(rangeOrigin, name, module, typeParameters, members, attributes, isRefining, parentTraits) { @@ -47,7 +47,7 @@ public NewtypeDecl(IOrigin rangeOrigin, Name name, List typeParam WitnessKind = witnessKind; this.NewSelfSynonym(); } - public NewtypeDecl(IOrigin rangeOrigin, Name name, List typeParameters, ModuleDefinition module, + public NewtypeDecl(RangeToken rangeOrigin, Name name, List typeParameters, ModuleDefinition module, BoundVar bv, Expression constraint, SubsetTypeDecl.WKind witnessKind, Expression witness, List parentTraits, List members, Attributes attributes, bool isRefining) : base(rangeOrigin, name, module, typeParameters, members, attributes, isRefining, parentTraits) { @@ -96,13 +96,21 @@ public Type RhsWithArgument(List typeArgs) { public TopLevelDecl AsTopLevelDecl => this; public TypeDeclSynonymInfo SynonymInfo { get; set; } - public TypeParameter.EqualitySupportValue EqualitySupport { + private IndDatatypeDecl.ES equalitySupport = IndDatatypeDecl.ES.NotYetComputed; + + public IndDatatypeDecl.ES EqualitySupport { get { - if (this.BaseType.SupportsEquality) { - return TypeParameter.EqualitySupportValue.Required; - } else { - return TypeParameter.EqualitySupportValue.Unspecified; + if (equalitySupport == IndDatatypeDecl.ES.NotYetComputed) { + var thingsChanged = false; + if (ModuleResolver.SurelyNeverSupportEquality(BaseType)) { + equalitySupport = IndDatatypeDecl.ES.Never; + } else { + ModuleResolver.DetermineEqualitySupportType(BaseType, ref thingsChanged); + equalitySupport = IndDatatypeDecl.ES.ConsultTypeArguments; + } } + + return equalitySupport; } } diff --git a/Source/DafnyCore/AST/Types/UserDefinedType.cs b/Source/DafnyCore/AST/Types/UserDefinedType.cs index 2dea4e86bad..d97ab765c13 100644 --- a/Source/DafnyCore/AST/Types/UserDefinedType.cs +++ b/Source/DafnyCore/AST/Types/UserDefinedType.cs @@ -376,7 +376,7 @@ public override string TypeName(DafnyOptions options, ModuleDefinition context, public override bool SupportsEquality { get { - if (ResolvedClass is ClassLikeDecl { IsReferenceTypeDecl: true } or NewtypeDecl) { + if (ResolvedClass is ClassLikeDecl { IsReferenceTypeDecl: true }) { return ResolvedClass.IsRevealedInScope(Type.GetScope()); } else if (ResolvedClass is TraitDecl) { return false; @@ -400,6 +400,12 @@ public override bool SupportsEquality { i++; } return true; + } else if (ResolvedClass is NewtypeDecl newtypeDecl) { + if (newtypeDecl.IsRevealedInScope(Type.GetScope())) { + return newtypeDecl.RhsWithArgument(TypeArgs).SupportsEquality; + } else { + return false; + } } else if (ResolvedClass is TypeSynonymDeclBase) { var t = (TypeSynonymDeclBase)ResolvedClass; if (t.SupportsEquality) { diff --git a/Source/DafnyCore/Resolver/CheckTypeCharacteristics_Visitor.cs b/Source/DafnyCore/Resolver/CheckTypeCharacteristics_Visitor.cs index 5474cba2974..d3c22ea6e4c 100644 --- a/Source/DafnyCore/Resolver/CheckTypeCharacteristics_Visitor.cs +++ b/Source/DafnyCore/Resolver/CheckTypeCharacteristics_Visitor.cs @@ -399,13 +399,40 @@ public static bool CheckCharacteristics(TypeParameter.TypeParameterCharacteristi return true; } - static string TypeEqualityErrorMessageHint(Type argType) { + public static string TypeEqualityErrorMessageHint(Type argType) { Contract.Requires(argType != null); - var cl = (argType.Normalize() as UserDefinedType)?.ResolvedClass; + argType = argType.Normalize(); + var cl = (argType as UserDefinedType)?.ResolvedClass; var tp = (TopLevelDecl)(cl as TypeParameter) ?? cl as AbstractTypeDecl; if (tp != null) { return string.Format(" (perhaps try declaring {2} '{0}' on line {1} as '{0}(==)', which says it can only be instantiated with a type that supports equality)", tp.Name, tp.tok.line, tp.WhatKind); } + + var typeArgs = argType.TypeArgs; + + if (argType.AsSeqType != null && typeArgs.Count >= 1) { + if (TypeEqualityErrorMessageHint(typeArgs[0]) is var messageSeq and not "") { + return messageSeq; + } + } + if (argType.AsMapType != null && + typeArgs.Count >= 2 && + TypeEqualityErrorMessageHint(typeArgs[1]) is var messageMap and not "") { + return messageMap; + } + if (argType.AsIndDatatype is { EqualitySupport: IndDatatypeDecl.ES.ConsultTypeArguments } decl) { + var i = 0; + foreach (var tParam in decl.TypeArgs) { + if (tParam.NecessaryForEqualitySupportOfSurroundingInductiveDatatype && i < typeArgs.Count && !typeArgs[i].SupportsEquality && TypeEqualityErrorMessageHint(typeArgs[i]) is var message and not "") { + return message; + } + i++; + } + } + + if (argType.AsNewtype is { } newTypeDecl) { + return TypeEqualityErrorMessageHint(newTypeDecl.RhsWithArgument(argType.TypeArgs)); + } return ""; } } \ No newline at end of file diff --git a/Source/DafnyCore/Resolver/ModuleResolver.cs b/Source/DafnyCore/Resolver/ModuleResolver.cs index 4e93aed2ce9..e36d3eb06af 100644 --- a/Source/DafnyCore/Resolver/ModuleResolver.cs +++ b/Source/DafnyCore/Resolver/ModuleResolver.cs @@ -783,7 +783,7 @@ public void RegisterByMethod(Function f, TopLevelDeclWithMembers cl) { var fn = new ApplySuffix(tok, null, new ExprDotName(tok, receiver, f.Name, f.TypeArgs.ConvertAll(typeParameter => (Type)new UserDefinedType(f.tok, typeParameter))), new ActualBindings(f.Ins.ConvertAll(Expression.CreateIdentExpr)).ArgumentBindings, - Token.NoToken); + tok); var post = new AttributedExpression(new BinaryExpr(tok, BinaryExpr.Opcode.Eq, r, fn)); Specification reads; if (Options.Get(Method.ReadsClausesOnMethods)) { @@ -2867,7 +2867,8 @@ void MarkSCCAsNotSupportingEquality() { return; // we are done } foreach (var arg in ctor.Formals) { - if(arg.IsGhost || SurelyDoesNotSupportEquality(arg.Type)) { + if (arg.IsGhost || SurelyNeverSupportEquality(arg.Type)) { + // arg.Type is known never to support equality MarkSCCAsNotSupportingEquality(); return; // we are done } @@ -2885,8 +2886,7 @@ void MarkSCCAsNotSupportingEquality() { } foreach (var ctor in dt.Ctors) { foreach (var arg in ctor.Formals) { - var type = arg.Type; - DetermineEqualitySupportType(type, ref thingsChanged); + DetermineEqualitySupportType(arg.Type, ref thingsChanged); } } } @@ -2926,51 +2926,59 @@ void MarkSCCAsNotSupportingEquality() { } } - private static bool SurelyDoesNotSupportEquality(Type type) - { - if (type.IsCoDatatype || - type.IsArrowType) { - return true; - } - - if (type.AsIndDatatype is { } anotherIndDt) { - if (anotherIndDt.EqualitySupport == IndDatatypeDecl.ES.Never) { - return true; - } - if(anotherIndDt.EqualitySupport == IndDatatypeDecl.ES.ConsultTypeArguments && - type.NormalizeExpand().TypeArgs.Zip(anotherIndDt.TypeArgs).ToList().Any(t => t.Second.NecessaryForEqualitySupportOfSurroundingInductiveDatatype && SurelyDoesNotSupportEquality(t.First))){ - return true; - } - } - - return false; + // If returns true, the given type never supports equality + // If return false, then the type must support equality if type parameters support equality + // It is unsound for a type to make this function return false when there is no type parameter + // assignment that makes this type support equality + public static bool SurelyNeverSupportEquality(Type type) { + type = type.Normalize(); + return + type.AsNewtype is { EqualitySupport: IndDatatypeDecl.ES.Never } || + type.AsIndDatatype is { EqualitySupport: IndDatatypeDecl.ES.Never } || + type.IsCoDatatype || type.IsArrowType || + type.AsSeqType is { Arg: var argType } && SurelyNeverSupportEquality(argType) || + type.AsMapType is { Range: var rangeType } && SurelyNeverSupportEquality(rangeType); } - private static void DetermineEqualitySupportType(Type type, ref bool thingsChanged) - { - if (type.AsTypeParameter is {} typeArg) { + public static void DetermineEqualitySupportType(Type type, ref bool thingsChanged) { + if (type.AsTypeParameter is { } typeArg) { typeArg.NecessaryForEqualitySupportOfSurroundingInductiveDatatype = true; thingsChanged = true; - } else if (type.AsMapType is {} typeMap) { - DetermineEqualitySupportType(typeMap.Range, ref thingsChanged); - } else if (type.AsSeqType is {} typeSeq) { - DetermineEqualitySupportType(typeSeq.Arg, ref thingsChanged); - } else if (type.AsIndDatatype is {} otherDt) { - if (otherDt.EqualitySupport == IndDatatypeDecl.ES.ConsultTypeArguments) { // datatype is in a different SCC - var otherUdt = (UserDefinedType)type.NormalizeExpand(); - var i = 0; - foreach (var otherTp in otherDt.TypeArgs) { - if (otherTp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype) { - var tp = otherUdt.TypeArgs[i].AsTypeParameter; - if (tp != null) { - tp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype = true; - thingsChanged = true; + } else if (type.Normalize() is UserDefinedType userDefinedType) { + if (userDefinedType.ResolvedClass is TypeSynonymDeclBase typeSynonymDecl) { + if (typeSynonymDecl.IsRevealedInScope(Type.GetScope())) { + DetermineEqualitySupportType(typeSynonymDecl.RhsWithArgument(userDefinedType.TypeArgs), ref thingsChanged); + } + } else if (userDefinedType.ResolvedClass is NewtypeDecl newtypeDecl) { + if (newtypeDecl.IsRevealedInScope(Type.GetScope())) { + DetermineEqualitySupportType(newtypeDecl.RhsWithArgument(userDefinedType.TypeArgs), ref thingsChanged); + } + } else if (userDefinedType.ResolvedClass is IndDatatypeDecl otherDt) { + if (otherDt.EqualitySupport == IndDatatypeDecl.ES.ConsultTypeArguments) { + // datatype is in a different SCC + var otherUdt = (UserDefinedType)type.NormalizeExpand(); + var i = 0; + foreach (var otherTp in otherDt.TypeArgs) { + if (otherTp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype) { + var tp = otherUdt.TypeArgs[i].AsTypeParameter; + if (tp != null) { + tp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype = true; + thingsChanged = true; + } } - } - i++; + i++; + } } } + } else if (type.AsMapType is { } typeMap) { + // A map type's Domain type is required to support equality (just like the argument type for sets and multisets), but + // it is optional for the map type's Range type to support equality. Thus, we need to determine the equality support for just the Range type. + DetermineEqualitySupportType(typeMap.Range, ref thingsChanged); + } else if (type.AsSeqType is { } typeSeq) { + // Like the Range type of a map, it is optional for a sequence type's argument type to support equality. So, we make a call + // to determine it. + DetermineEqualitySupportType(typeSeq.Arg, ref thingsChanged); } } @@ -3172,7 +3180,7 @@ internal Type ResolvedArrayType(IOrigin tok, int dims, Type arg, ResolutionConte } public Expression VarDotMethod(IOrigin tok, string varname, string methodname) { - return new ApplySuffix(tok, null, new ExprDotName(tok, new IdentifierExpr(tok, varname), methodname, null), new List(), Token.NoToken); + return new ApplySuffix(tok, null, new ExprDotName(tok, new IdentifierExpr(tok, varname), methodname, null), new List(), tok); } public Expression makeTemp(String prefix, AssignOrReturnStmt s, ResolutionContext resolutionContext, Expression ex) { @@ -3351,7 +3359,7 @@ public static UserDefinedType GetReceiverType(IOrigin tok, MemberDecl member) { } internal Expression VarDotFunction(IOrigin tok, string varname, string functionname) { - return new ApplySuffix(tok, null, new ExprDotName(tok, new IdentifierExpr(tok, varname), functionname, null), new List(), Token.NoToken); + return new ApplySuffix(tok, null, new ExprDotName(tok, new IdentifierExpr(tok, varname), functionname, null), new List(), tok); } // TODO search for occurrences of "new LetExpr" which could benefit from this helper diff --git a/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs b/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs index 0cd8a4ec60c..a746ae2f33c 100644 --- a/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs +++ b/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs @@ -244,8 +244,8 @@ private static void Check(List declarations, bool isAnExport, Erro visitor.VisitType(syn.tok, syn.Rhs, false); if (!isAnExport) { if (syn.SupportsEquality && !syn.Rhs.SupportsEquality) { - reporter.Error(MessageSource.Resolver, syn.tok, "type '{0}' declared as supporting equality, but the RHS type ({1}) might not", - syn.Name, syn.Rhs); + reporter.Error(MessageSource.Resolver, syn.tok, "type '{0}' declared as supporting equality, but the RHS type ({1}) might not{2}", + syn.Name, syn.Rhs, CheckTypeCharacteristics_Visitor.TypeEqualityErrorMessageHint(syn.Rhs)); } if (syn.Characteristics.IsNonempty && !syn.Rhs.IsNonempty) { reporter.Error(MessageSource.Resolver, syn.tok, "type '{0}' declared as being nonempty, but the RHS type ({1}) may be empty", From e07ed6e8a0d01fa36d42888e043328bda7c37d1e Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 16 Dec 2024 16:47:29 -0600 Subject: [PATCH 30/69] Fixed newtype range and equality support --- Scripts/test.sh | 4 +- .../FactorPathsOptimizationTest.cs | 2 +- .../AST/TypeDeclarations/NewtypeDecl.cs | 4 +- Source/DafnyCore/Backends/Dafny/ASTBuilder.cs | 14 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 32 +-- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 83 ++++++- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 213 +++++++++-------- .../DafnyCompilerRustUtils.cs | 2 +- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 2 +- Source/DafnyCore/GeneratedFromDafny/RAST.cs | 217 ++++++++++-------- Source/DafnyCore/Resolver/ModuleResolver.cs | 9 +- .../comp/rust/small/01-hash.dfy.expect | 1 + .../comp/rust/small/02-binary.dfy.expect | 1 + .../comp/rust/small/03-methodnamed.dfy.expect | 1 + .../comp/rust/small/04-mismatched.dfy.expect | 2 +- .../comp/rust/small/05-coerce.dfy.expect | 1 + 16 files changed, 365 insertions(+), 223 deletions(-) diff --git a/Scripts/test.sh b/Scripts/test.sh index 24225f4fdc7..c094b52c530 100644 --- a/Scripts/test.sh +++ b/Scripts/test.sh @@ -28,7 +28,7 @@ if [ "$build_flag" = "false" ]; then output_dir="${framework_dir}/TestFiles/LitTests/LitTest" # Find and copy all matching files to the output directory - files=$(cd "$lit_tests_dir" && find . -type f -wholename "*$name*") + files=$(cd "$lit_tests_dir" && find . -type f -regex '.*\.\(check\|dfy\|expect\)' -wholename "*$name*") if [ -z "$files" ]; then echo "No files found matching pattern: $name" exit 1 @@ -40,7 +40,7 @@ if [ "$build_flag" = "false" ]; then # Copy files echo "$files" | while IFS= read -r file; do echo "Copying $file to $output_dir" - cp "$lit_tests_dir/$file" "$output_dir/" + cp "$lit_tests_dir/$file" "$output_dir/$file" done fi diff --git a/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs b/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs index 7b3f9367309..140d35afc15 100644 --- a/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs +++ b/Source/DafnyCore.Test/GeneratedFromDafny/FactorPathsOptimizationTest.cs @@ -40,7 +40,7 @@ public static void TestApply() _3_std__any__Any = (((RAST.__default.@global).MSel(Dafny.Sequence.UnicodeFromString("std"))).MSel(Dafny.Sequence.UnicodeFromString("any"))).MSel(Dafny.Sequence.UnicodeFromString("Any")); RAST._IType _4_Any; _4_Any = RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Any")); - FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(RAST.__default.NoDoc, Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_0_T__Decl), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), (_3_std__any__Any).AsType())))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_0_T__Decl), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (_3_std__any__Any).AsType(), ((((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("onemodule"))).MSel(Dafny.Sequence.UnicodeFromString("test"))).AsType()).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), _3_std__any__Any)), RAST.ModDecl.create_StructDecl(RAST.Struct.create(RAST.__default.NoDoc, Dafny.Sequence>.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_1_T__Decl__simp), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), _4_Any)))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), _4_Any, (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))); + FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create(RAST.__default.NoDoc, Dafny.Sequence.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_0_T__Decl), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), (_3_std__any__Any).AsType())))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_0_T__Decl), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (_3_std__any__Any).AsType(), ((((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("onemodule"))).MSel(Dafny.Sequence.UnicodeFromString("test"))).AsType()).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), _3_std__any__Any)), RAST.ModDecl.create_StructDecl(RAST.Struct.create(RAST.__default.NoDoc, Dafny.Sequence.FromElements(), Dafny.Sequence.UnicodeFromString("test"), Dafny.Sequence.FromElements(_1_T__Decl__simp), RAST.Fields.create_NamedFields(Dafny.Sequence.FromElements(RAST.Field.create(RAST.Visibility.create_PUB(), RAST.Formal.create(Dafny.Sequence.UnicodeFromString("a"), _4_Any)))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), _4_Any, (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))); FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_0_T__Decl), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastObject"))).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))), RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("UpcastObject")))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(Dafny.Sequence.FromElements(_1_T__Decl__simp), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("UpcastObject"))).Apply(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("x")))), (RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("test"))).Apply(Dafny.Sequence.FromElements(_2_T)), Dafny.Sequence.FromElements()))))); FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummy"), (_3_std__any__Any).AsType(), RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("doit"), Std.Wrappers.Option.create_Some(((RAST.__default.std__rc__Rc).AsType()).Apply1(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("unknown")))), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("something"))).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_DynType((RAST.__default.std__default__Default).AsType())))).Apply(Dafny.Sequence.FromElements(RAST.__default.std__default__Default__default, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("rd!"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("obj"))))))), RAST.Expr.create_TypeAscription(RAST.Expr.create_ExprFromType(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyString"))).AsType()), ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType"))).AsType()))))))), RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), _3_std__any__Any)), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), RAST.__default.std__rc__Rc)), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), RAST.__default.std__default__Default)), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("rd")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyString")))), RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), (RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyType")))), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummy"), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Any")), RAST.Expr.create_StmtExpr(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("doit"), Std.Wrappers.Option.create_Some((RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Rc"))).Apply1(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("unknown")))), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("something"))).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_DynType(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Default")))))).Apply(Dafny.Sequence.FromElements(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Default"))).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply(Dafny.Sequence.FromElements()), (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("rd!"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("obj"))))))), RAST.Expr.create_TypeAscription(RAST.Expr.create_ExprFromType(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("DafnyString"))), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("DafnyType"))))))))); FactorPathsOptimizationTest.__default.ShouldBeEqual(Dafny.Helpers.Id>(FactorPathsOptimization.__default.apply(RAST.__default.crate))(RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.FromElements(), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Something")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummyExtern"), (((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("anothermodule"))).MSel(Dafny.Sequence.UnicodeFromString("Something"))).AsType(), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing")))), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummyIntern"), (((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("onemodule"))).MSel(Dafny.Sequence.UnicodeFromString("Something"))).AsType(), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing"))))))), RAST.Mod.create_Mod(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("onemodule"), Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.FromElements(), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Something")), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements())), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummyExtern"), (((RAST.__default.crate).MSel(Dafny.Sequence.UnicodeFromString("anothermodule"))).MSel(Dafny.Sequence.UnicodeFromString("Something"))).AsType(), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing")))), RAST.ModDecl.create_ConstDecl(RAST.Constant.create(RAST.__default.NoDoc, RAST.__default.NoAttr, Dafny.Sequence.UnicodeFromString("dummyIntern"), RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("Something")), RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("nothing"))))))); diff --git a/Source/DafnyCore/AST/TypeDeclarations/NewtypeDecl.cs b/Source/DafnyCore/AST/TypeDeclarations/NewtypeDecl.cs index fd3ba11742d..22bffb68304 100644 --- a/Source/DafnyCore/AST/TypeDeclarations/NewtypeDecl.cs +++ b/Source/DafnyCore/AST/TypeDeclarations/NewtypeDecl.cs @@ -32,7 +32,7 @@ bool RedirectingTypeDecl.ConstraintIsCompilable { [FilledInDuringResolution] public bool TargetTypeCoversAllBitPatterns; // "target complete" -- indicates that any bit pattern that can fill the target type is a value of the newtype - public NewtypeDecl(RangeToken rangeOrigin, Name name, List typeParameters, ModuleDefinition module, + public NewtypeDecl(IOrigin rangeOrigin, Name name, List typeParameters, ModuleDefinition module, Type baseType, SubsetTypeDecl.WKind witnessKind, Expression witness, List parentTraits, List members, Attributes attributes, bool isRefining) : base(rangeOrigin, name, module, typeParameters, members, attributes, isRefining, parentTraits) { @@ -47,7 +47,7 @@ public NewtypeDecl(RangeToken rangeOrigin, Name name, List typePa WitnessKind = witnessKind; this.NewSelfSynonym(); } - public NewtypeDecl(RangeToken rangeOrigin, Name name, List typeParameters, ModuleDefinition module, + public NewtypeDecl(IOrigin rangeOrigin, Name name, List typeParameters, ModuleDefinition module, BoundVar bv, Expression constraint, SubsetTypeDecl.WKind witnessKind, Expression witness, List parentTraits, List members, Attributes attributes, bool isRefining) : base(rangeOrigin, name, module, typeParameters, members, attributes, isRefining, parentTraits) { diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index 133ddb52435..8ca9a7e10b2 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -228,10 +228,11 @@ public object Finish() { interface NewtypeContainer : Container { void AddNewtype(Newtype item); - public NewtypeBuilder Newtype(string name, List typeParams, - DAST.Type baseType, NewtypeRange newtypeRange, Option constraint, List witnessStmts, DAST.Expression witness, - ISequence<_IAttribute> attributes, string docString) { - return new NewtypeBuilder(this, name, typeParams, newtypeRange, baseType, constraint, witnessStmts, witness, attributes, docString); + public NewtypeBuilder Newtype(string name, List typeParams, + DAST.Type baseType, NewtypeRange newtypeRange, Option constraint, + List witnessStmts, DAST.Expression witness, + ISequence<_IAttribute> attributes, string docString, _IEqualitySupport equalitySupport) { + return new NewtypeBuilder(this, name, typeParams, newtypeRange, baseType, constraint, witnessStmts, witness, attributes, docString, equalitySupport); } } @@ -247,11 +248,12 @@ class NewtypeBuilder : ClassLike { private ISequence<_IAttribute> attributes; private readonly List methods; private string docString; + private _IEqualitySupport equalitySupport; public NewtypeBuilder(NewtypeContainer parent, string name, List typeParams, NewtypeRange newtypeRange, DAST.Type baseType, Option constraint, List statements, DAST.Expression witness, - ISequence<_IAttribute> attributes, string docString) { + ISequence<_IAttribute> attributes, string docString, _IEqualitySupport equalitySupport) { this.parent = parent; this.name = name; this.typeParams = typeParams; @@ -262,6 +264,7 @@ public NewtypeBuilder(NewtypeContainer parent, string name, List ty this.witness = witness; this.attributes = attributes; this.docString = docString; + this.equalitySupport = equalitySupport; this.methods = new(); } @@ -285,6 +288,7 @@ public object Finish() { this.witness == null ? Option.create_None() : Option.create_Some(this.witness), + equalitySupport, attributes, Sequence.FromArray(methods.ToArray()) )); diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index d54221eec3b..6176acc75ff 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -510,10 +510,12 @@ protected override IClassWriter DeclareNewtype(NewtypeDecl nt, ConcreteSyntaxTre } var typeParams = GenTypeParams(nt.TypeArgs); + var equalitySupport = GenEqualitySupport(nt); + return new ClassWriter(this, false, builder.Newtype( nt.GetCompileName(Options), typeParams, GenType(nt.BaseType), NativeTypeToNewtypeRange(nt, false), - constraint, witnessStmts, witness, ParseAttributes(nt.Attributes), GetDocString(nt))); + constraint, witnessStmts, witness, ParseAttributes(nt.Attributes), GetDocString(nt), equalitySupport)); } else { throw new InvalidOperationException(); } @@ -1873,9 +1875,11 @@ private DAST.NewtypeRange NativeTypeToNewtypeRange(NewtypeDecl newtypeDecl, bool NativeType.Selection.UDoubleLong => NewtypeRange.create_U128(overflows), NativeType.Selection.DoubleLong => NewtypeRange.create_I128(overflows), _ => - EraseNewtypeLayers(newtypeDecl) is BoolType - ? NewtypeRange.create_Bool() - : NewtypeRange.create_NoRange() + EraseNewtypeLayers(newtypeDecl) is { } resType ? + resType is BoolType ? NewtypeRange.create_Bool() : + resType is MapType ? NewtypeRange.create_Map() : + resType is SeqType ? NewtypeRange.create_Sequence() + :NewtypeRange.create_NoRange() : NewtypeRange.create_NoRange() }); } @@ -1983,15 +1987,17 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type return baseType; } - private static _IEqualitySupport GenEqualitySupport(DatatypeDecl dd) - { - return dd is IndDatatypeDecl indDecl ? - indDecl.EqualitySupport == IndDatatypeDecl.ES.Never ? - EqualitySupport.create_Never() : - indDecl.EqualitySupport == IndDatatypeDecl.ES.ConsultTypeArguments ? - EqualitySupport.create_ConsultTypeArguments() : - EqualitySupport.create_Never() : - EqualitySupport.create_Never(); + private static _IEqualitySupport GenEqualitySupport(Declaration decl) { + Contract.Requires(decl is IndDatatypeDecl or NewtypeDecl); + IndDatatypeDecl.ES equalitySupport = + decl is IndDatatypeDecl indDecl ? indDecl.EqualitySupport : + decl is NewtypeDecl nt ? nt.EqualitySupport : IndDatatypeDecl.ES.Never; + + return equalitySupport switch { + IndDatatypeDecl.ES.Never => EqualitySupport.create_Never(), + IndDatatypeDecl.ES.ConsultTypeArguments => EqualitySupport.create_ConsultTypeArguments(), + _ => throw new InvalidOperationException() + }; } private static Type EraseNewtypeLayers(TopLevelDecl topLevel) { diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index fd8af9e3485..00e01fe305c 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -1939,6 +1939,8 @@ public interface _INewtypeRange { bool is_NativeArrayIndex { get; } bool is_BigInt { get; } bool is_Bool { get; } + bool is_Sequence { get; } + bool is_Map { get; } bool is_NoRange { get; } bool dtor_overflow { get; } _INewtypeRange DowncastClone(); @@ -1995,6 +1997,12 @@ public static _INewtypeRange create_BigInt() { public static _INewtypeRange create_Bool() { return new NewtypeRange_Bool(); } + public static _INewtypeRange create_Sequence() { + return new NewtypeRange_Sequence(); + } + public static _INewtypeRange create_Map() { + return new NewtypeRange_Map(); + } public static _INewtypeRange create_NoRange() { return new NewtypeRange_NoRange(); } @@ -2011,6 +2019,8 @@ public static _INewtypeRange create_NoRange() { public bool is_NativeArrayIndex { get { return this is NewtypeRange_NativeArrayIndex; } } public bool is_BigInt { get { return this is NewtypeRange_BigInt; } } public bool is_Bool { get { return this is NewtypeRange_Bool; } } + public bool is_Sequence { get { return this is NewtypeRange_Sequence; } } + public bool is_Map { get { return this is NewtypeRange_Map; } } public bool is_NoRange { get { return this is NewtypeRange_NoRange; } } public bool dtor_overflow { get { @@ -2032,7 +2042,7 @@ public bool CanOverflow() { return (((((((((((this).is_U8) || ((this).is_I8)) || ((this).is_U16)) || ((this).is_I16)) || ((this).is_U32)) || ((this).is_I32)) || ((this).is_U64)) || ((this).is_I64)) || ((this).is_U128)) || ((this).is_I128)) && ((this).dtor_overflow); } public bool HasArithmeticOperations() { - return !((this).is_Bool); + return ((!((this).is_Bool)) && (!((this).is_Map))) && (!((this).is_Sequence)); } } public class NewtypeRange_U8 : NewtypeRange { @@ -2368,6 +2378,48 @@ public override string ToString() { return s; } } + public class NewtypeRange_Sequence : NewtypeRange { + public NewtypeRange_Sequence() : base() { + } + public override _INewtypeRange DowncastClone() { + if (this is _INewtypeRange dt) { return dt; } + return new NewtypeRange_Sequence(); + } + public override bool Equals(object other) { + var oth = other as DAST.NewtypeRange_Sequence; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 13; + return (int) hash; + } + public override string ToString() { + string s = "DAST.NewtypeRange.Sequence"; + return s; + } + } + public class NewtypeRange_Map : NewtypeRange { + public NewtypeRange_Map() : base() { + } + public override _INewtypeRange DowncastClone() { + if (this is _INewtypeRange dt) { return dt; } + return new NewtypeRange_Map(); + } + public override bool Equals(object other) { + var oth = other as DAST.NewtypeRange_Map; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 14; + return (int) hash; + } + public override string ToString() { + string s = "DAST.NewtypeRange.Map"; + return s; + } + } public class NewtypeRange_NoRange : NewtypeRange { public NewtypeRange_NoRange() : base() { } @@ -2381,7 +2433,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 13; + hash = ((hash << 5) + hash) + 15; return (int) hash; } public override string ToString() { @@ -3762,6 +3814,7 @@ public interface _INewtype { Std.Wrappers._IOption dtor_constraint { get; } Dafny.ISequence dtor_witnessStmts { get; } Std.Wrappers._IOption dtor_witnessExpr { get; } + DAST._IEqualitySupport dtor_equalitySupport { get; } Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_classItems { get; } _INewtype DowncastClone(); @@ -3775,9 +3828,10 @@ public class Newtype : _INewtype { public readonly Std.Wrappers._IOption _constraint; public readonly Dafny.ISequence _witnessStmts; public readonly Std.Wrappers._IOption _witnessExpr; + public readonly DAST._IEqualitySupport _equalitySupport; public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _classItems; - public Newtype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes, Dafny.ISequence classItems) { + public Newtype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence classItems) { this._name = name; this._docString = docString; this._typeParams = typeParams; @@ -3786,16 +3840,17 @@ public Newtype(Dafny.ISequence name, Dafny.ISequence doc this._constraint = constraint; this._witnessStmts = witnessStmts; this._witnessExpr = witnessExpr; + this._equalitySupport = equalitySupport; this._attributes = attributes; this._classItems = classItems; } public _INewtype DowncastClone() { if (this is _INewtype dt) { return dt; } - return new Newtype(_name, _docString, _typeParams, _base, _range, _constraint, _witnessStmts, _witnessExpr, _attributes, _classItems); + return new Newtype(_name, _docString, _typeParams, _base, _range, _constraint, _witnessStmts, _witnessExpr, _equalitySupport, _attributes, _classItems); } public override bool Equals(object other) { var oth = other as DAST.Newtype; - return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._base, oth._base) && object.Equals(this._range, oth._range) && object.Equals(this._constraint, oth._constraint) && object.Equals(this._witnessStmts, oth._witnessStmts) && object.Equals(this._witnessExpr, oth._witnessExpr) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._classItems, oth._classItems); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._docString, oth._docString) && object.Equals(this._typeParams, oth._typeParams) && object.Equals(this._base, oth._base) && object.Equals(this._range, oth._range) && object.Equals(this._constraint, oth._constraint) && object.Equals(this._witnessStmts, oth._witnessStmts) && object.Equals(this._witnessExpr, oth._witnessExpr) && object.Equals(this._equalitySupport, oth._equalitySupport) && object.Equals(this._attributes, oth._attributes) && object.Equals(this._classItems, oth._classItems); } public override int GetHashCode() { ulong hash = 5381; @@ -3808,6 +3863,7 @@ public override int GetHashCode() { hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._constraint)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._witnessStmts)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._witnessExpr)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._equalitySupport)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._attributes)); hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._classItems)); return (int) hash; @@ -3831,13 +3887,15 @@ public override string ToString() { s += ", "; s += Dafny.Helpers.ToString(this._witnessExpr); s += ", "; + s += Dafny.Helpers.ToString(this._equalitySupport); + s += ", "; s += Dafny.Helpers.ToString(this._attributes); s += ", "; s += Dafny.Helpers.ToString(this._classItems); s += ")"; return s; } - private static readonly DAST._INewtype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.Type.Default(), DAST.NewtypeRange.Default(), Std.Wrappers.Option.Default(), Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly DAST._INewtype theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, DAST.Type.Default(), DAST.NewtypeRange.Default(), Std.Wrappers.Option.Default(), Dafny.Sequence.Empty, Std.Wrappers.Option.Default(), DAST.EqualitySupport.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static DAST._INewtype Default() { return theDefault; } @@ -3845,11 +3903,11 @@ public static DAST._INewtype Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _INewtype create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes, Dafny.ISequence classItems) { - return new Newtype(name, docString, typeParams, @base, range, constraint, witnessStmts, witnessExpr, attributes, classItems); + public static _INewtype create(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence classItems) { + return new Newtype(name, docString, typeParams, @base, range, constraint, witnessStmts, witnessExpr, equalitySupport, attributes, classItems); } - public static _INewtype create_Newtype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, Dafny.ISequence attributes, Dafny.ISequence classItems) { - return create(name, docString, typeParams, @base, range, constraint, witnessStmts, witnessExpr, attributes, classItems); + public static _INewtype create_Newtype(Dafny.ISequence name, Dafny.ISequence docString, Dafny.ISequence typeParams, DAST._IType @base, DAST._INewtypeRange range, Std.Wrappers._IOption constraint, Dafny.ISequence witnessStmts, Std.Wrappers._IOption witnessExpr, DAST._IEqualitySupport equalitySupport, Dafny.ISequence attributes, Dafny.ISequence classItems) { + return create(name, docString, typeParams, @base, range, constraint, witnessStmts, witnessExpr, equalitySupport, attributes, classItems); } public bool is_Newtype { get { return true; } } public Dafny.ISequence dtor_name { @@ -3892,6 +3950,11 @@ public Std.Wrappers._IOption dtor_witnessExpr { return this._witnessExpr; } } + public DAST._IEqualitySupport dtor_equalitySupport { + get { + return this._equalitySupport; + } + } public Dafny.ISequence dtor_attributes { get { return this._attributes; diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 010f8914f2d..b54f0004167 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -62,10 +62,10 @@ public bool HasAttribute(Dafny.ISequence attributes, Dafny.ISe } else { Defs._IExternAttribute _4_optExtern; _4_optExtern = Defs.__default.ExtractExternMod(mod); - Dafny.ISequence> _5_attributes; - _5_attributes = Dafny.Sequence>.FromElements(); + Dafny.ISequence _5_attributes; + _5_attributes = Dafny.Sequence.FromElements(); if ((this).HasAttribute((mod).dtor_attributes, Dafny.Sequence.UnicodeFromString("rust_cfg_test"))) { - _5_attributes = Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[cfg(test)]")); + _5_attributes = Dafny.Sequence.FromElements(RAST.Attribute.CfgTest); } Dafny.ISequence _6_body; DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _7_allmodules; @@ -471,7 +471,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _16_className = _out9; _17_extern = _out10; RAST._IStruct _18_struct; - _18_struct = RAST.Struct.create((c).dtor_docString, Dafny.Sequence>.FromElements(), _16_className, _2_rTypeParamsDecls, RAST.Fields.create_NamedFields(_4_fields)); + _18_struct = RAST.Struct.create((c).dtor_docString, Dafny.Sequence.FromElements(), _16_className, _2_rTypeParamsDecls, RAST.Fields.create_NamedFields(_4_fields)); s = Dafny.Sequence.FromElements(); if ((_17_extern).is_NoExtern) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(_18_struct))); @@ -514,7 +514,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc if (((this).HasAttribute((_25_m).dtor_attributes, Dafny.Sequence.UnicodeFromString("test"))) && ((new BigInteger(((_25_m).dtor_params).Count)).Sign == 0)) { Dafny.ISequence _27_fnName; _27_fnName = Defs.__default.escapeName((_25_m).dtor_name); - _23_testMethods = Dafny.Sequence.Concat(_23_testMethods, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create((_25_m).dtor_docString, Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[test]")), RAST.Visibility.create_PUB(), RAST.Fn.create(_27_fnName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_default"))).FSel(_27_fnName)).Apply(Dafny.Sequence.FromElements()))))))); + _23_testMethods = Dafny.Sequence.Concat(_23_testMethods, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create((_25_m).dtor_docString, Dafny.Sequence.FromElements(RAST.Attribute.Name(Dafny.Sequence.UnicodeFromString("test"))), RAST.Visibility.create_PUB(), RAST.Fn.create(_27_fnName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_default"))).FSel(_27_fnName)).Apply(Dafny.Sequence.FromElements()))))))); } } s = Dafny.Sequence.Concat(s, _23_testMethods); @@ -683,7 +683,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } } } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create((t).dtor_docString, Dafny.Sequence>.FromElements(), _1_rTypeParamsDecls, _10_traitFullType, _17_parents, _12_implBody))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TraitDecl(RAST.Trait.create((t).dtor_docString, Dafny.Sequence.FromElements(), _1_rTypeParamsDecls, _10_traitFullType, _17_parents, _12_implBody))); s = Dafny.Sequence.Concat(s, _28_downcastDefinition); if (((t).dtor_traitType).is_GeneralTrait) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("clone"))).MSel(Dafny.Sequence.UnicodeFromString("Clone"))).AsType(), RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("clone"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()))))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_1_rTypeParamsDecls, RAST.__default.DafnyPrint, RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((_11_traitFullExpr).FSel(Dafny.Sequence.UnicodeFromString("_fmt_print"))).Apply(Dafny.Sequence.FromElements(((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); @@ -725,43 +725,56 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc RAST._IType _8_resultingType; _8_resultingType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams); Dafny.ISequence _9_attributes = Dafny.Sequence.Empty; + Dafny.ISequence> _10_deriveTraits; + _10_deriveTraits = Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("Clone")); if (Defs.__default.IsNewtypeCopy((c).dtor_range)) { - _9_attributes = Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq, Copy)]"); - } else { - _9_attributes = Dafny.Sequence.UnicodeFromString("#[derive(Clone, PartialEq)]"); + _10_deriveTraits = Dafny.Sequence>.Concat(_10_deriveTraits, Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("Copy"))); } - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create((c).dtor_docString, Dafny.Sequence>.FromElements(_9_attributes, Dafny.Sequence.UnicodeFromString("#[repr(transparent)]")), _7_newtypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _4_wrappedType)))))); - RAST._IExpr _10_fnBody = RAST.Expr.Default(); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create((c).dtor_docString, Dafny.Sequence.FromElements(RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("derive"), _10_deriveTraits), RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("repr"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("transparent")))), _7_newtypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _4_wrappedType)))))); + if ((((c).dtor_equalitySupport).is_Always) || (((c).dtor_equalitySupport).is_ConsultTypeArguments)) { + bool _11_consultTypeArguments; + _11_consultTypeArguments = ((c).dtor_equalitySupport).is_ConsultTypeArguments; + RAST._IExpr _12_eqImplBody; + _12_eqImplBody = ((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))).Equals((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0"))); + RAST._IExpr _13_hashImplBody; + _13_hashImplBody = (Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + Dafny.ISequence _14_impls; + Dafny.ISequence _out4; + _out4 = (this).GenEqHashImpls((c).dtor_typeParams, _2_rTypeParamsDecls, _1_rTypeParams, _11_consultTypeArguments, _8_resultingType, _12_eqImplBody, _13_hashImplBody); + _14_impls = _out4; + s = Dafny.Sequence.Concat(s, _14_impls); + } + RAST._IExpr _15_fnBody = RAST.Expr.Default(); Std.Wrappers._IOption _source0 = (c).dtor_witnessExpr; { if (_source0.is_Some) { - DAST._IExpression _11_e = _source0.dtor_value; + DAST._IExpression _16_e = _source0.dtor_value; { - DAST._IExpression _12_e; - _12_e = DAST.Expression.create_Convert(_11_e, (c).dtor_base, _6_newtypeType); - RAST._IExpr _13_r; - Defs._IOwnership _14___v5; - Dafny.ISet> _15___v6; - RAST._IExpr _out4; - Defs._IOwnership _out5; - Dafny.ISet> _out6; - (this).GenExpr(_12_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out4, out _out5, out _out6); - _13_r = _out4; - _14___v5 = _out5; - _15___v6 = _out6; - _10_fnBody = _13_r; + DAST._IExpression _17_e; + _17_e = DAST.Expression.create_Convert(_16_e, (c).dtor_base, _6_newtypeType); + RAST._IExpr _18_r; + Defs._IOwnership _19___v5; + Dafny.ISet> _20___v6; + RAST._IExpr _out5; + Defs._IOwnership _out6; + Dafny.ISet> _out7; + (this).GenExpr(_17_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); + _18_r = _out5; + _19___v5 = _out6; + _20___v6 = _out7; + _15_fnBody = _18_r; } goto after_match0; } } { { - _10_fnBody = (RAST.Expr.create_Identifier(_7_newtypeName)).Apply1(RAST.__default.std__default__Default__default); + _15_fnBody = (RAST.Expr.create_Identifier(_7_newtypeName)).Apply1(RAST.__default.std__default__Default__default); } } after_match0: ; - RAST._IImplMember _16_body; - _16_body = RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _7_newtypeName), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("default"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(_10_fnBody))); + RAST._IImplMember _21_body; + _21_body = RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _7_newtypeName), Dafny.Sequence.FromElements(), RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("default"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(_15_fnBody))); Std.Wrappers._IOption _source1 = (c).dtor_constraint; { if (_source1.is_None) { @@ -770,50 +783,50 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } { DAST._INewtypeConstraint value0 = _source1.dtor_value; - DAST._IFormal _17_formal = value0.dtor_variable; - Dafny.ISequence _18_constraintStmts = value0.dtor_constraintStmts; - RAST._IExpr _19_rStmts; - Dafny.ISet> _20___v7; - Defs._IEnvironment _21_newEnv; - RAST._IExpr _out7; - Dafny.ISet> _out8; - Defs._IEnvironment _out9; - (this).GenStmts(_18_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out7, out _out8, out _out9); - _19_rStmts = _out7; - _20___v7 = _out8; - _21_newEnv = _out9; - Dafny.ISequence _22_rFormals; - Dafny.ISequence _out10; - _out10 = (this).GenParams(Dafny.Sequence.FromElements(_17_formal), Dafny.Sequence.FromElements(_17_formal), false); - _22_rFormals = _out10; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Constraint check"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _22_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_19_rStmts)))))))); + DAST._IFormal _22_formal = value0.dtor_variable; + Dafny.ISequence _23_constraintStmts = value0.dtor_constraintStmts; + RAST._IExpr _24_rStmts; + Dafny.ISet> _25___v7; + Defs._IEnvironment _26_newEnv; + RAST._IExpr _out8; + Dafny.ISet> _out9; + Defs._IEnvironment _out10; + (this).GenStmts(_23_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out8, out _out9, out _out10); + _24_rStmts = _out8; + _25___v7 = _out9; + _26_newEnv = _out10; + Dafny.ISequence _27_rFormals; + Dafny.ISequence _out11; + _out11 = (this).GenParams(Dafny.Sequence.FromElements(_22_formal), Dafny.Sequence.FromElements(_22_formal), false); + _27_rFormals = _out11; + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Constraint check"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _27_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_24_rStmts)))))))); } after_match1: ; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _8_resultingType, Dafny.Sequence.FromElements(_16_body))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _8_resultingType, Dafny.Sequence.FromElements(_21_body))))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("For Dafny print statements"), RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsType(), _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Target"), _4_wrappedType), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("deref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(((RAST.Path.create_Self()).MSel(Dafny.Sequence.UnicodeFromString("Target"))).AsType())), Std.Wrappers.Option.create_Some(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("SAFETY: The newtype is marked as transparent"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_from_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("o"), RAST.Type.create_Borrowed(_4_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Std.Wrappers.Option.create_Some(RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("transmute"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("o"))))))))))))); - Dafny.ISequence _23_rTypeParamsDeclsWithHash; - _23_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_23_rTypeParamsDeclsWithHash, _8_resultingType, (Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))))); + Dafny.ISequence _28_rTypeParamsDeclsWithHash; + _28_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_28_rTypeParamsDeclsWithHash, _8_resultingType, (Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))))); if (((c).dtor_range).HasArithmeticOperations()) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.OpsImpl(new Dafny.Rune('+'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('-'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('*'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('/'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.PartialOrdImpl(_2_rTypeParamsDecls, _8_resultingType, _7_newtypeName))); } if (((c).dtor_range).is_Bool) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.UnaryOpsImpl(new Dafny.Rune('!'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName))); } - Dafny.ISequence _24_implementation; - Dafny.IMap>,Dafny.ISequence> _25_traitBodies; - Dafny.ISequence _out11; - Dafny.IMap>,Dafny.ISequence> _out12; - (this).GenClassImplBody((c).dtor_classItems, false, _6_newtypeType, _0_typeParamsSeq, out _out11, out _out12); - _24_implementation = _out11; - _25_traitBodies = _out12; - if ((new BigInteger((_25_traitBodies).Count)).Sign == 1) { + Dafny.ISequence _29_implementation; + Dafny.IMap>,Dafny.ISequence> _30_traitBodies; + Dafny.ISequence _out12; + Dafny.IMap>,Dafny.ISequence> _out13; + (this).GenClassImplBody((c).dtor_classItems, false, _6_newtypeType, _0_typeParamsSeq, out _out12, out _out13); + _29_implementation = _out12; + _30_traitBodies = _out13; + if ((new BigInteger((_30_traitBodies).Count)).Sign == 1) { (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("No support for trait in newtypes yet")); } - if ((new BigInteger((_24_implementation).Count)).Sign == 1) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams), _24_implementation)))); + if ((new BigInteger((_29_implementation).Count)).Sign == 1) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams), _29_implementation)))); } return s; } @@ -836,7 +849,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc RAST._IType _out3; _out3 = (this).GenType((c).dtor_base, Defs.GenTypeContext.@default()); _4_resultingType = _out3; - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TypeDecl(RAST.TypeSynonym.create((c).dtor_docString, Dafny.Sequence>.FromElements(), _3_synonymTypeName, _2_rTypeParamsDecls, _4_resultingType))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_TypeDecl(RAST.TypeSynonym.create((c).dtor_docString, Dafny.Sequence.FromElements(), _3_synonymTypeName, _2_rTypeParamsDecls, _4_resultingType))); Dafny.ISequence _5_defaultConstrainedTypeParams; _5_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); Std.Wrappers._IOption _source0 = (c).dtor_witnessExpr; @@ -866,7 +879,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _12___v10 = _out9; Dafny.ISequence _13_constantName; _13_constantName = Defs.__default.escapeName(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_init_"), ((c).dtor_name))); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _3_synonymTypeName), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_13_constantName, _5_defaultConstrainedTypeParams, Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_4_resultingType), Std.Wrappers.Option.create_Some((_7_rStmts).Then(_10_rExpr))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_TopFnDecl(RAST.TopFnDecl.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _3_synonymTypeName), Dafny.Sequence.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_13_constantName, _5_defaultConstrainedTypeParams, Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(_4_resultingType), Std.Wrappers.Option.create_Some((_7_rStmts).Then(_10_rExpr))))))); } goto after_match0; } @@ -889,6 +902,26 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) { return (this).write(RAST.Expr.create_LiteralString(s, false, false), false); } + public Dafny.ISequence GenEqHashImpls(Dafny.ISequence typeParamsDecls, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence rTypeParams, bool consultTypeArguments, RAST._IType datatypeType, RAST._IExpr eqImplBody, RAST._IExpr hashImplBody) + { + Dafny.ISequence impls = Dafny.Sequence.Empty; + Dafny.ISequence _0_rTypeParamsDeclsWithEq; + _0_rTypeParamsDeclsWithEq = rTypeParamsDecls; + Dafny.ISequence _1_rTypeParamsDeclsWithHash; + _1_rTypeParamsDeclsWithHash = rTypeParamsDecls; + if (consultTypeArguments) { + BigInteger _hi0 = new BigInteger((rTypeParamsDecls).Count); + for (BigInteger _2_i = BigInteger.Zero; _2_i < _hi0; _2_i++) { + if ((((typeParamsDecls).Select(_2_i)).dtor_info).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype) { + _0_rTypeParamsDeclsWithEq = Dafny.Sequence.Update(_0_rTypeParamsDeclsWithEq, _2_i, ((_0_rTypeParamsDeclsWithEq).Select(_2_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Eq, RAST.__default.Hash))); + _1_rTypeParamsDeclsWithHash = Dafny.Sequence.Update(_1_rTypeParamsDeclsWithHash, _2_i, ((_1_rTypeParamsDeclsWithHash).Select(_2_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Hash))); + } + } + } + impls = Defs.__default.EqImpl(_0_rTypeParamsDeclsWithEq, datatypeType, rTypeParams, eqImplBody); + impls = Dafny.Sequence.Concat(impls, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_1_rTypeParamsDeclsWithHash, datatypeType, hashImplBody))); + return impls; + } public Dafny.ISequence GenDatatype(DAST._IDatatype c, Dafny.ISequence> path) { Dafny.ISequence s = Dafny.Sequence.Empty; @@ -1063,7 +1096,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } RAST._IExpr _47_methodBody; _47_methodBody = RAST.Expr.create_Match(RAST.__default.self, _35_cases); - _27_implBody = Dafny.Sequence.Concat(_27_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl((((new BigInteger(((c).dtor_ctors).Count)) == (BigInteger.One)) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Returns a borrow of the field "), _33_callName)) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Gets the field "), _33_callName), Dafny.Sequence.UnicodeFromString(" for all enum members which have it")))), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_33_callName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_34_formalType)), Std.Wrappers.Option.create_Some(_47_methodBody))))); + _27_implBody = Dafny.Sequence.Concat(_27_implBody, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl((((new BigInteger(((c).dtor_ctors).Count)) == (BigInteger.One)) ? (Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Returns a borrow of the field "), _33_callName)) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Gets the field "), _33_callName), Dafny.Sequence.UnicodeFromString(" for all enum members which have it")))), Dafny.Sequence.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(_33_callName, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(_34_formalType)), Std.Wrappers.Option.create_Some(_47_methodBody))))); } } } @@ -1138,7 +1171,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _68_cIsAlwaysEq = ((c).dtor_equalitySupport).is_Always; RAST._IType _69_datatypeType; _69_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("#[derive(Clone)]")), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _69_datatypeType, _27_implBody))); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, Dafny.Sequence.FromElements(RAST.Attribute.DeriveClone), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _69_datatypeType, _27_implBody))); if ((new BigInteger(((c).dtor_superTraitTypes).Count)).Sign == 1) { RAST._IType _70_fullType; if (_0_isRcWrapped) { @@ -1352,43 +1385,35 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _69_datatypeType, _120_instantiationType, _9_singletonConstructors))); } if ((((c).dtor_equalitySupport).is_Always) || (((c).dtor_equalitySupport).is_ConsultTypeArguments)) { - Dafny.ISequence _121_rTypeParamsDeclsWithEq; - _121_rTypeParamsDeclsWithEq = _3_rTypeParamsDecls; - Dafny.ISequence _122_rTypeParamsDeclsWithHash; - _122_rTypeParamsDeclsWithHash = _3_rTypeParamsDecls; - if (((c).dtor_equalitySupport).is_ConsultTypeArguments) { - BigInteger _hi11 = new BigInteger((_3_rTypeParamsDecls).Count); - for (BigInteger _123_i = BigInteger.Zero; _123_i < _hi11; _123_i++) { - if (((((c).dtor_typeParams).Select(_123_i)).dtor_info).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype) { - _121_rTypeParamsDeclsWithEq = Dafny.Sequence.Update(_121_rTypeParamsDeclsWithEq, _123_i, ((_121_rTypeParamsDeclsWithEq).Select(_123_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Eq, RAST.__default.Hash))); - _122_rTypeParamsDeclsWithHash = Dafny.Sequence.Update(_122_rTypeParamsDeclsWithHash, _123_i, ((_122_rTypeParamsDeclsWithHash).Select(_123_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Hash))); - } - } - } - s = Dafny.Sequence.Concat(s, Defs.__default.EqImpl(_121_rTypeParamsDeclsWithEq, _69_datatypeType, _2_rTypeParams, _118_eqImplBody)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_122_rTypeParamsDeclsWithHash, _69_datatypeType, _117_hashImplBody))); + bool _121_consultTypeArguments; + _121_consultTypeArguments = ((c).dtor_equalitySupport).is_ConsultTypeArguments; + Dafny.ISequence _122_impls; + Dafny.ISequence _out22; + _out22 = (this).GenEqHashImpls((c).dtor_typeParams, _3_rTypeParamsDecls, _2_rTypeParams, _121_consultTypeArguments, _69_datatypeType, _118_eqImplBody, _117_hashImplBody); + _122_impls = _out22; + s = Dafny.Sequence.Concat(s, _122_impls); } if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - RAST._IExpr _124_structName; - _124_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _125_structAssignments; - _125_structAssignments = Dafny.Sequence.FromElements(); - BigInteger _hi12 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); - for (BigInteger _126_i = BigInteger.Zero; _126_i < _hi12; _126_i++) { - DAST._IDatatypeDtor _127_dtor; - _127_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_126_i); - _125_structAssignments = Dafny.Sequence.Concat(_125_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_127_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); + RAST._IExpr _123_structName; + _123_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _124_structAssignments; + _124_structAssignments = Dafny.Sequence.FromElements(); + BigInteger _hi11 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); + for (BigInteger _125_i = BigInteger.Zero; _125_i < _hi11; _125_i++) { + DAST._IDatatypeDtor _126_dtor; + _126_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_125_i); + _124_structAssignments = Dafny.Sequence.Concat(_124_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_126_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); } if ((false) && (_68_cIsAlwaysEq)) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _69_datatypeType, _124_structName, _125_structAssignments))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _69_datatypeType, _123_structName, _124_structAssignments))); } s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _69_datatypeType))); } - Dafny.ISequence _128_superTraitImplementations; - Dafny.ISequence _out22; - _out22 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, _68_cIsAlwaysEq, Dafny.Sequence.UnicodeFromString("datatype")); - _128_superTraitImplementations = _out22; - s = Dafny.Sequence.Concat(s, _128_superTraitImplementations); + Dafny.ISequence _127_superTraitImplementations; + Dafny.ISequence _out23; + _out23 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, _68_cIsAlwaysEq, Dafny.Sequence.UnicodeFromString("datatype")); + _127_superTraitImplementations = _out23; + s = Dafny.Sequence.Concat(s, _127_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -7112,7 +7137,7 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul _0_externUseDecls = Dafny.Sequence.Concat(_0_externUseDecls, Dafny.Sequence.FromElements(RAST.ModDecl.create_UseDecl(RAST.Use.create(RAST.Visibility.create_PUB(), ((RAST.__default.crate).MSel(_3_externalMod)).MSel(Dafny.Sequence.UnicodeFromString("*")))))); } if (!(_0_externUseDecls).Equals(Dafny.Sequence.FromElements())) { - s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(s, (RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("Flattens all imported externs so that they can be accessed from this module"), Dafny.Sequence>.FromElements(), Defs.__default.DAFNY__EXTERN__MODULE, _0_externUseDecls))._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("\n")); + s = Dafny.Sequence.Concat(Dafny.Sequence.Concat(s, (RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString("Flattens all imported externs so that they can be accessed from this module"), Dafny.Sequence.FromElements(), Defs.__default.DAFNY__EXTERN__MODULE, _0_externUseDecls))._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString("\n")); } DafnyCompilerRustUtils._ISeqMap, DafnyCompilerRustUtils._IGatheringModule> _5_allModules; _5_allModules = DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Empty(); diff --git a/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs b/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs index aea446e0c0b..252c6de85ca 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DafnyCompilerRustUtils.cs @@ -242,7 +242,7 @@ public DafnyCompilerRustUtils._IGatheringModule Merge(DafnyCompilerRustUtils._IG } } else { Dafny.ISequence _1_enclosingModule = (containingPath).Select(BigInteger.Zero); - return DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Single(_1_enclosingModule, DafnyCompilerRustUtils.GatheringModule.create_GatheringModule(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence>.FromElements(), _1_enclosingModule, Dafny.Sequence.FromElements()), DafnyCompilerRustUtils.GatheringModule.Wrap((containingPath).Drop(BigInteger.One), rawDecl))); + return DafnyCompilerRustUtils.SeqMap, DafnyCompilerRustUtils._IGatheringModule>.Single(_1_enclosingModule, DafnyCompilerRustUtils.GatheringModule.create_GatheringModule(RAST.Mod.create_Mod(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.FromElements(), _1_enclosingModule, Dafny.Sequence.FromElements()), DafnyCompilerRustUtils.GatheringModule.Wrap((containingPath).Drop(BigInteger.One), rawDecl))); } } public RAST._IMod ToRust() { diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index 6e9fba65060..9bd57c73c02 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -528,7 +528,7 @@ public static RAST._IModDecl CoerceImpl(Dafny.ISequence rT } public static RAST._IModDecl SingletonsImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, RAST._IType instantiationType, Dafny.ISequence singletonConstructors) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Enumerates all possible values of "), (datatypeType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence>.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_AllSingletonConstructors"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SequenceIter"))).AsType()).Apply(Dafny.Sequence.FromElements(instantiationType))), Std.Wrappers.Option.create_Some((((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).AsExpr()).Apply(singletonConstructors)).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0())))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Enumerates all possible values of "), (datatypeType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.FromElements(), RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_AllSingletonConstructors"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SequenceIter"))).AsType()).Apply(Dafny.Sequence.FromElements(instantiationType))), Std.Wrappers.Option.create_Some((((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("seq!"))).AsExpr()).Apply(singletonConstructors)).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0())))))); } public static RAST._IModDecl HashImpl(Dafny.ISequence rTypeParamsDeclsWithHash, RAST._IType datatypeOrNewtypeType, RAST._IExpr hashImplBody) { diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index 58e2aa62102..eede8991622 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -359,8 +359,8 @@ public static RAST._IExpr std__rc__Rc__new { get { public static RAST._IExpr std__default__Default__default { get { return ((RAST.__default.std__default__Default).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0(); } } - public static Dafny.ISequence> NoAttr { get { - return Dafny.Sequence>.FromElements(); + public static Dafny.ISequence NoAttr { get { + return Dafny.Sequence.FromElements(); } } public static BigInteger MAX__TUPLE__SIZE { get { return new BigInteger(12); @@ -600,7 +600,7 @@ public T VisitTopFn(T acc, RAST._ITopFnDecl t) { RAST._ITopFnDecl _source0 = t; { - Dafny.ISequence> _0_attributes = _source0.dtor_attributes; + Dafny.ISequence _0_attributes = _source0.dtor_attributes; RAST._IVisibility _1_visibility = _source0.dtor_visibility; RAST._IFn _2_fn = _source0.dtor_fn; return (this).VisitFn(acc, _2_fn); @@ -657,7 +657,7 @@ public T VisitMember(T acc, RAST._IImplMember member) { if (_source0.is_FnDecl) { Dafny.ISequence _1_docString = _source0.dtor_docString; - Dafny.ISequence> _2_attributes = _source0.dtor_attributes; + Dafny.ISequence _2_attributes = _source0.dtor_attributes; RAST._IVisibility _3_pub = _source0.dtor_pub; RAST._IFn _4_fun = _source0.dtor_fun; return (this).VisitFn(acc, _4_fun); @@ -859,7 +859,7 @@ public RAST._IStruct ReplaceStruct(RAST._IStruct @struct) { RAST._IStruct _source0 = @struct; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; Dafny.ISequence _2_name = _source0.dtor_name; Dafny.ISequence _3_typeParams = _source0.dtor_typeParams; RAST._IFields _4_fields = _source0.dtor_fields; @@ -870,7 +870,7 @@ public RAST._ITypeSynonym ReplaceTypeDecl(RAST._ITypeSynonym t) { RAST._ITypeSynonym _source0 = t; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; Dafny.ISequence _2_name = _source0.dtor_name; Dafny.ISequence _3_typeParams = _source0.dtor_typeParams; RAST._IType _4_tpe = _source0.dtor_tpe; @@ -881,7 +881,7 @@ public RAST._IConstant ReplaceConst(RAST._IConstant t) { RAST._IConstant _source0 = t; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; Dafny.ISequence _2_name = _source0.dtor_name; RAST._IType _3_tpe = _source0.dtor_tpe; RAST._IExpr _4_value = _source0.dtor_value; @@ -892,7 +892,7 @@ public RAST._IEnum ReplaceEnum(RAST._IEnum @enum) { RAST._IEnum _source0 = @enum; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; Dafny.ISequence _2_name = _source0.dtor_name; Dafny.ISequence _3_typeParams = _source0.dtor_typeParams; Dafny.ISequence _4_variants = _source0.dtor_variants; @@ -932,7 +932,7 @@ public RAST._ITrait ReplaceTrait(RAST._ITrait tr) { RAST._ITrait _source0 = tr; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; Dafny.ISequence _2_typeParams = _source0.dtor_typeParams; RAST._IType _3_tpe = _source0.dtor_tpe; Dafny.ISequence _4_parents = _source0.dtor_parents; @@ -946,7 +946,7 @@ public RAST._ITopFnDecl ReplaceTopFn(RAST._ITopFnDecl t) { RAST._ITopFnDecl _source0 = t; { Dafny.ISequence _0_docString = _source0.dtor_docString; - Dafny.ISequence> _1_attributes = _source0.dtor_attributes; + Dafny.ISequence _1_attributes = _source0.dtor_attributes; RAST._IVisibility _2_visibility = _source0.dtor_visibility; RAST._IFn _3_fn = _source0.dtor_fn; return RAST.TopFnDecl.create(_0_docString, _1_attributes, _2_visibility, (this).ReplaceFn(_3_fn)); @@ -989,7 +989,7 @@ public RAST._IImplMember ReplaceImplMember(RAST._IImplMember t) { { if (_source0.is_FnDecl) { Dafny.ISequence _1_docString = _source0.dtor_docString; - Dafny.ISequence> _2_attributes = _source0.dtor_attributes; + Dafny.ISequence _2_attributes = _source0.dtor_attributes; RAST._IVisibility _3_pub = _source0.dtor_pub; RAST._IFn _4_fun = _source0.dtor_fun; return RAST.ImplMember.create_FnDecl(_1_docString, _2_attributes, _3_pub, (this).ReplaceFn(_4_fun)); @@ -1043,7 +1043,7 @@ public interface _IMod { bool is_Mod { get; } bool is_ExternMod { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_body { get; } _IMod DowncastClone(); @@ -1053,7 +1053,7 @@ public interface _IMod { public abstract class Mod : _IMod { public Mod() { } - private static readonly RAST._IMod theDefault = create_Mod(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly RAST._IMod theDefault = create_Mod(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static RAST._IMod Default() { return theDefault; } @@ -1061,7 +1061,7 @@ public static RAST._IMod Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IMod create_Mod(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence body) { + public static _IMod create_Mod(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence body) { return new Mod_Mod(docString, attributes, name, body); } public static _IMod create_ExternMod(Dafny.ISequence name) { @@ -1075,7 +1075,7 @@ public Dafny.ISequence dtor_docString { return ((Mod_Mod)d)._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { var d = this; return ((Mod_Mod)d)._attributes; @@ -1119,7 +1119,7 @@ public __T Fold<__T>(__T acc, Func<__T, RAST._IModDecl, __T> accBuilder) } { Dafny.ISequence _1_docString = _source0.dtor_docString; - Dafny.ISequence> _2_attributes = _source0.dtor_attributes; + Dafny.ISequence _2_attributes = _source0.dtor_attributes; Dafny.ISequence _3_name = _source0.dtor_name; Dafny.ISequence _4_body = _source0.dtor_body; return Dafny.Sequence.Concat(Dafny.Sequence.Concat(RAST.__default.ToDocstringPrefix(_1_docString, ind), RAST.Attribute.ToStringMultiple(_2_attributes, ind)), Dafny.Helpers.Let>(((new BigInteger((_4_body).Count)).Sign == 1) && (((_4_body).Select(BigInteger.Zero)).is_UseDecl), _pat_let13_0 => Dafny.Helpers.Let>(_pat_let13_0, _5_startWithUse => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n"), _pat_let_tv0), RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(""))), _pat_let14_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let14_0, _6_prefixIfNotUseDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.Concat(_pat_let_tv1, RAST.__default.IND)) : (Dafny.Sequence.UnicodeFromString(""))), _pat_let15_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let15_0, _7_prefixIfUseDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.UnicodeFromString("\n")) : (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("\n\n"), _pat_let_tv2), RAST.__default.IND))), _pat_let16_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let16_0, _8_infixDecl => Dafny.Helpers.Let, Dafny.ISequence>(((_5_startWithUse) ? (Dafny.Sequence.UnicodeFromString("")) : (Dafny.Sequence.Concat(_pat_let_tv3, RAST.__default.IND))), _pat_let17_0 => Dafny.Helpers.Let, Dafny.ISequence>(_pat_let17_0, _9_initialIdent => Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("pub mod "), _3_name), Dafny.Sequence.UnicodeFromString(" {")), Dafny.Sequence.UnicodeFromString("\n")), _9_initialIdent), RAST.__default.SeqToString(_4_body, Dafny.Helpers.Id, Dafny.ISequence, Dafny.ISequence, Func>>>((_10_prefixIfUseDecl, _11_prefixIfNotUseDecl, _12_ind) => ((System.Func>)((_13_modDecl) => { @@ -1130,10 +1130,10 @@ public __T Fold<__T>(__T acc, Func<__T, RAST._IModDecl, __T> accBuilder) } public class Mod_Mod : Mod { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _body; - public Mod_Mod(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence body) : base() { + public Mod_Mod(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence body) : base() { this._docString = docString; this._attributes = attributes; this._name = name; @@ -1659,7 +1659,7 @@ public RAST._IPath dtor_path { public interface _ITopFnDecl { bool is_TopFn { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } RAST._IVisibility dtor_visibility { get; } RAST._IFn dtor_fn { get; } _ITopFnDecl DowncastClone(); @@ -1667,10 +1667,10 @@ public interface _ITopFnDecl { } public class TopFnDecl : _ITopFnDecl { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly RAST._IVisibility _visibility; public readonly RAST._IFn _fn; - public TopFnDecl(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { + public TopFnDecl(Dafny.ISequence docString, Dafny.ISequence attributes, RAST._IVisibility visibility, RAST._IFn fn) { this._docString = docString; this._attributes = attributes; this._visibility = visibility; @@ -1706,7 +1706,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._ITopFnDecl theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, RAST.Visibility.Default(), RAST.Fn.Default()); + private static readonly RAST._ITopFnDecl theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Visibility.Default(), RAST.Fn.Default()); public static RAST._ITopFnDecl Default() { return theDefault; } @@ -1714,10 +1714,10 @@ public static RAST._ITopFnDecl Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITopFnDecl create(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { + public static _ITopFnDecl create(Dafny.ISequence docString, Dafny.ISequence attributes, RAST._IVisibility visibility, RAST._IFn fn) { return new TopFnDecl(docString, attributes, visibility, fn); } - public static _ITopFnDecl create_TopFn(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility visibility, RAST._IFn fn) { + public static _ITopFnDecl create_TopFn(Dafny.ISequence docString, Dafny.ISequence attributes, RAST._IVisibility visibility, RAST._IFn fn) { return create(docString, attributes, visibility, fn); } public bool is_TopFn { get { return true; } } @@ -1726,7 +1726,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -1747,66 +1747,103 @@ public RAST._IFn dtor_fn { } public interface _IAttribute { - bool is_RawAttribute { get; } - Dafny.ISequence dtor_content { get; } + bool is_ApplyAttribute { get; } + Dafny.ISequence dtor_name { get; } + Dafny.ISequence> dtor_derived { get; } + _IAttribute DowncastClone(); + Dafny.ISequence _ToString(Dafny.ISequence ind); } public class Attribute : _IAttribute { - public readonly Dafny.ISequence _content; - public Attribute(Dafny.ISequence content) { - this._content = content; + public readonly Dafny.ISequence _name; + public readonly Dafny.ISequence> _derived; + public Attribute(Dafny.ISequence name, Dafny.ISequence> derived) { + this._name = name; + this._derived = derived; } - public static Dafny.ISequence DowncastClone(Dafny.ISequence _this) { - return _this; + public _IAttribute DowncastClone() { + if (this is _IAttribute dt) { return dt; } + return new Attribute(_name, _derived); } public override bool Equals(object other) { var oth = other as RAST.Attribute; - return oth != null && object.Equals(this._content, oth._content); + return oth != null && object.Equals(this._name, oth._name) && object.Equals(this._derived, oth._derived); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 0; - hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._content)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._name)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._derived)); return (int) hash; } public override string ToString() { - string s = "RAST.Attribute.RawAttribute"; + string s = "RAST.Attribute.ApplyAttribute"; s += "("; - s += this._content.ToVerbatimString(true); + s += this._name.ToVerbatimString(true); + s += ", "; + s += Dafny.Helpers.ToString(this._derived); s += ")"; return s; } - private static readonly Dafny.ISequence theDefault = Dafny.Sequence.Empty; - public static Dafny.ISequence Default() { + private static readonly RAST._IAttribute theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty); + public static RAST._IAttribute Default() { return theDefault; } - private static readonly Dafny.TypeDescriptor> _TYPE = new Dafny.TypeDescriptor>(Dafny.Sequence.Empty); - public static Dafny.TypeDescriptor> _TypeDescriptor() { + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(RAST.Attribute.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IAttribute create(Dafny.ISequence content) { - return new Attribute(content); + public static _IAttribute create(Dafny.ISequence name, Dafny.ISequence> derived) { + return new Attribute(name, derived); } - public static _IAttribute create_RawAttribute(Dafny.ISequence content) { - return create(content); + public static _IAttribute create_ApplyAttribute(Dafny.ISequence name, Dafny.ISequence> derived) { + return create(name, derived); } - public bool is_RawAttribute { get { return true; } } - public Dafny.ISequence dtor_content { + public bool is_ApplyAttribute { get { return true; } } + public Dafny.ISequence dtor_name { get { - return this._content; + return this._name; + } + } + public Dafny.ISequence> dtor_derived { + get { + return this._derived; } } - public static Dafny.ISequence ToStringMultiple(Dafny.ISequence> attributes, Dafny.ISequence ind) + public static RAST._IAttribute Name(Dafny.ISequence name) { + return RAST.Attribute.create(name, Dafny.Sequence>.FromElements()); + } + public Dafny.ISequence _ToString(Dafny.ISequence ind) { + RAST._IAttribute _source0 = this; + { + Dafny.ISequence _0_name = _source0.dtor_name; + Dafny.ISequence> _1_derived = _source0.dtor_derived; + Dafny.ISequence _2_arguments = (((new BigInteger((_1_derived).Count)).Sign != 0) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString>(_1_derived, ((System.Func, Dafny.ISequence>)((_3_derived) => { + return _3_derived; + })), Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(")"))) : (Dafny.Sequence.UnicodeFromString(""))); + return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("#["), _0_name), _2_arguments), Dafny.Sequence.UnicodeFromString("]")); + } + } + public static Dafny.ISequence ToStringMultiple(Dafny.ISequence attributes, Dafny.ISequence ind) { - return RAST.__default.SeqToString>(attributes, Dafny.Helpers.Id, Func, Dafny.ISequence>>>((_0_ind) => ((System.Func, Dafny.ISequence>)((_1_attribute) => { - return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_1_attribute), Dafny.Sequence.UnicodeFromString("\n")), _0_ind); + return RAST.__default.SeqToString(attributes, Dafny.Helpers.Id, Func>>>((_0_ind) => ((System.Func>)((_1_attribute) => { + return Dafny.Sequence.Concat(Dafny.Sequence.Concat((_1_attribute)._ToString(_0_ind), Dafny.Sequence.UnicodeFromString("\n")), _0_ind); })))(ind), Dafny.Sequence.UnicodeFromString("")); } + public static RAST._IAttribute DeriveClone { get { + return RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("derive"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("Clone"))); + } } + public static RAST._IAttribute DeriveCloneAndCopy { get { + return RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("derive"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("Clone"), Dafny.Sequence.UnicodeFromString("Copy"))); + } } + public static RAST._IAttribute CfgTest { get { + return RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("cfg"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("test"))); + } } } public interface _IStruct { bool is_Struct { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } RAST._IFields dtor_fields { get; } @@ -1815,11 +1852,11 @@ public interface _IStruct { } public class Struct : _IStruct { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _typeParams; public readonly RAST._IFields _fields; - public Struct(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { + public Struct(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { this._docString = docString; this._attributes = attributes; this._name = name; @@ -1859,7 +1896,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._IStruct theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Fields.Default()); + private static readonly RAST._IStruct theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Fields.Default()); public static RAST._IStruct Default() { return theDefault; } @@ -1867,10 +1904,10 @@ public static RAST._IStruct Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IStruct create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { + public static _IStruct create(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { return new Struct(docString, attributes, name, typeParams, fields); } - public static _IStruct create_Struct(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { + public static _IStruct create_Struct(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IFields fields) { return create(docString, attributes, name, typeParams, fields); } public bool is_Struct { get { return true; } } @@ -1879,7 +1916,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -1907,7 +1944,7 @@ public RAST._IFields dtor_fields { public interface _ITypeSynonym { bool is_TypeSynonym { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } RAST._IType dtor_tpe { get; } @@ -1916,11 +1953,11 @@ public interface _ITypeSynonym { } public class TypeSynonym : _ITypeSynonym { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _typeParams; public readonly RAST._IType _tpe; - public TypeSynonym(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { + public TypeSynonym(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { this._docString = docString; this._attributes = attributes; this._name = name; @@ -1960,7 +1997,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._ITypeSynonym theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Type.Default()); + private static readonly RAST._ITypeSynonym theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Type.Default()); public static RAST._ITypeSynonym Default() { return theDefault; } @@ -1968,10 +2005,10 @@ public static RAST._ITypeSynonym Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITypeSynonym create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { + public static _ITypeSynonym create(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { return new TypeSynonym(docString, attributes, name, typeParams, tpe); } - public static _ITypeSynonym create_TypeSynonym(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { + public static _ITypeSynonym create_TypeSynonym(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, RAST._IType tpe) { return create(docString, attributes, name, typeParams, tpe); } public bool is_TypeSynonym { get { return true; } } @@ -1980,7 +2017,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -2008,7 +2045,7 @@ public RAST._IType dtor_tpe { public interface _IConstant { bool is_Constant { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_name { get; } RAST._IType dtor_tpe { get; } RAST._IExpr dtor_value { get; } @@ -2017,11 +2054,11 @@ public interface _IConstant { } public class Constant : _IConstant { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _name; public readonly RAST._IType _tpe; public readonly RAST._IExpr _value; - public Constant(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { + public Constant(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { this._docString = docString; this._attributes = attributes; this._name = name; @@ -2061,7 +2098,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._IConstant theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, RAST.Type.Default(), RAST.Expr.Default()); + private static readonly RAST._IConstant theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Type.Default(), RAST.Expr.Default()); public static RAST._IConstant Default() { return theDefault; } @@ -2069,10 +2106,10 @@ public static RAST._IConstant Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IConstant create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { + public static _IConstant create(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { return new Constant(docString, attributes, name, tpe, @value); } - public static _IConstant create_Constant(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { + public static _IConstant create_Constant(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, RAST._IType tpe, RAST._IExpr @value) { return create(docString, attributes, name, tpe, @value); } public bool is_Constant { get { return true; } } @@ -2081,7 +2118,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -2454,7 +2491,7 @@ public RAST._IFields dtor_fields { public interface _IEnum { bool is_Enum { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_name { get; } Dafny.ISequence dtor_typeParams { get; } Dafny.ISequence dtor_variants { get; } @@ -2463,11 +2500,11 @@ public interface _IEnum { } public class Enum : _IEnum { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _name; public readonly Dafny.ISequence _typeParams; public readonly Dafny.ISequence _variants; - public Enum(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + public Enum(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { this._docString = docString; this._attributes = attributes; this._name = name; @@ -2507,7 +2544,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._IEnum theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly RAST._IEnum theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static RAST._IEnum Default() { return theDefault; } @@ -2515,10 +2552,10 @@ public static RAST._IEnum Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _IEnum create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + public static _IEnum create(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { return new Enum(docString, attributes, name, typeParams, variants); } - public static _IEnum create_Enum(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { + public static _IEnum create_Enum(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence name, Dafny.ISequence typeParams, Dafny.ISequence variants) { return create(docString, attributes, name, typeParams, variants); } public bool is_Enum { get { return true; } } @@ -2527,7 +2564,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -4729,7 +4766,7 @@ public override string ToString() { public interface _ITrait { bool is_Trait { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } Dafny.ISequence dtor_typeParams { get; } RAST._IType dtor_tpe { get; } Dafny.ISequence dtor_parents { get; } @@ -4739,12 +4776,12 @@ public interface _ITrait { } public class Trait : _ITrait { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly Dafny.ISequence _typeParams; public readonly RAST._IType _tpe; public readonly Dafny.ISequence _parents; public readonly Dafny.ISequence _body; - public Trait(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { + public Trait(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { this._docString = docString; this._attributes = attributes; this._typeParams = typeParams; @@ -4788,7 +4825,7 @@ public override string ToString() { s += ")"; return s; } - private static readonly RAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence>.Empty, Dafny.Sequence.Empty, RAST.Type.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); + private static readonly RAST._ITrait theDefault = create(Dafny.Sequence.Empty, Dafny.Sequence.Empty, Dafny.Sequence.Empty, RAST.Type.Default(), Dafny.Sequence.Empty, Dafny.Sequence.Empty); public static RAST._ITrait Default() { return theDefault; } @@ -4796,10 +4833,10 @@ public static RAST._ITrait Default() { public static Dafny.TypeDescriptor _TypeDescriptor() { return _TYPE; } - public static _ITrait create(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { + public static _ITrait create(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { return new Trait(docString, attributes, typeParams, tpe, parents, body); } - public static _ITrait create_Trait(Dafny.ISequence docString, Dafny.ISequence> attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { + public static _ITrait create_Trait(Dafny.ISequence docString, Dafny.ISequence attributes, Dafny.ISequence typeParams, RAST._IType tpe, Dafny.ISequence parents, Dafny.ISequence body) { return create(docString, attributes, typeParams, tpe, parents, body); } public bool is_Trait { get { return true; } } @@ -4808,7 +4845,7 @@ public Dafny.ISequence dtor_docString { return this._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { return this._attributes; } @@ -5002,7 +5039,7 @@ public interface _IImplMember { Dafny.ISequence dtor_name { get; } RAST._IType dtor_rhs { get; } Dafny.ISequence dtor_docString { get; } - Dafny.ISequence> dtor_attributes { get; } + Dafny.ISequence dtor_attributes { get; } RAST._IVisibility dtor_pub { get; } RAST._IFn dtor_fun { get; } RAST._IExpr dtor_expr { get; } @@ -5026,7 +5063,7 @@ public static _IImplMember create_RawImplMember(Dafny.ISequence cont public static _IImplMember create_TypeDeclMember(Dafny.ISequence name, RAST._IType rhs) { return new ImplMember_TypeDeclMember(name, rhs); } - public static _IImplMember create_FnDecl(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility pub, RAST._IFn fun) { + public static _IImplMember create_FnDecl(Dafny.ISequence docString, Dafny.ISequence attributes, RAST._IVisibility pub, RAST._IFn fun) { return new ImplMember_FnDecl(docString, attributes, pub, fun); } public static _IImplMember create_ImplMemberMacro(RAST._IExpr expr) { @@ -5060,7 +5097,7 @@ public Dafny.ISequence dtor_docString { return ((ImplMember_FnDecl)d)._docString; } } - public Dafny.ISequence> dtor_attributes { + public Dafny.ISequence dtor_attributes { get { var d = this; return ((ImplMember_FnDecl)d)._attributes; @@ -5158,10 +5195,10 @@ public override string ToString() { } public class ImplMember_FnDecl : ImplMember { public readonly Dafny.ISequence _docString; - public readonly Dafny.ISequence> _attributes; + public readonly Dafny.ISequence _attributes; public readonly RAST._IVisibility _pub; public readonly RAST._IFn _fun; - public ImplMember_FnDecl(Dafny.ISequence docString, Dafny.ISequence> attributes, RAST._IVisibility pub, RAST._IFn fun) : base() { + public ImplMember_FnDecl(Dafny.ISequence docString, Dafny.ISequence attributes, RAST._IVisibility pub, RAST._IFn fun) : base() { this._docString = docString; this._attributes = attributes; this._pub = pub; diff --git a/Source/DafnyCore/Resolver/ModuleResolver.cs b/Source/DafnyCore/Resolver/ModuleResolver.cs index e36d3eb06af..9121265f277 100644 --- a/Source/DafnyCore/Resolver/ModuleResolver.cs +++ b/Source/DafnyCore/Resolver/ModuleResolver.cs @@ -783,7 +783,7 @@ public void RegisterByMethod(Function f, TopLevelDeclWithMembers cl) { var fn = new ApplySuffix(tok, null, new ExprDotName(tok, receiver, f.Name, f.TypeArgs.ConvertAll(typeParameter => (Type)new UserDefinedType(f.tok, typeParameter))), new ActualBindings(f.Ins.ConvertAll(Expression.CreateIdentExpr)).ArgumentBindings, - tok); + Token.NoToken); var post = new AttributedExpression(new BinaryExpr(tok, BinaryExpr.Opcode.Eq, r, fn)); Specification reads; if (Options.Get(Method.ReadsClausesOnMethods)) { @@ -2947,6 +2947,9 @@ public static void DetermineEqualitySupportType(Type type, ref bool thingsChange } else if (type.Normalize() is UserDefinedType userDefinedType) { if (userDefinedType.ResolvedClass is TypeSynonymDeclBase typeSynonymDecl) { if (typeSynonymDecl.IsRevealedInScope(Type.GetScope())) { + if (typeSynonymDecl.Characteristics.EqualitySupport == TypeParameter.EqualitySupportValue.Required) { + return; // It's guaranteed that this type synonym requires equality + } DetermineEqualitySupportType(typeSynonymDecl.RhsWithArgument(userDefinedType.TypeArgs), ref thingsChanged); } } else if (userDefinedType.ResolvedClass is NewtypeDecl newtypeDecl) { @@ -3180,7 +3183,7 @@ internal Type ResolvedArrayType(IOrigin tok, int dims, Type arg, ResolutionConte } public Expression VarDotMethod(IOrigin tok, string varname, string methodname) { - return new ApplySuffix(tok, null, new ExprDotName(tok, new IdentifierExpr(tok, varname), methodname, null), new List(), tok); + return new ApplySuffix(tok, null, new ExprDotName(tok, new IdentifierExpr(tok, varname), methodname, null), new List(), Token.NoToken); } public Expression makeTemp(String prefix, AssignOrReturnStmt s, ResolutionContext resolutionContext, Expression ex) { @@ -3359,7 +3362,7 @@ public static UserDefinedType GetReceiverType(IOrigin tok, MemberDecl member) { } internal Expression VarDotFunction(IOrigin tok, string varname, string functionname) { - return new ApplySuffix(tok, null, new ExprDotName(tok, new IdentifierExpr(tok, varname), functionname, null), new List(), tok); + return new ApplySuffix(tok, null, new ExprDotName(tok, new IdentifierExpr(tok, varname), functionname, null), new List(), Token.NoToken); } // TODO search for occurrences of "new LetExpr" which could benefit from this helper diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect index 19e90eca854..d2b8ffb5439 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy.expect @@ -1,2 +1,3 @@ + Dafny program verifier finished with 1 verified, 0 errors ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect index 19e90eca854..d2b8ffb5439 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy.expect @@ -1,2 +1,3 @@ + Dafny program verifier finished with 1 verified, 0 errors ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect index 19e90eca854..d2b8ffb5439 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy.expect @@ -1,2 +1,3 @@ + Dafny program verifier finished with 1 verified, 0 errors ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect index ec66568c1f0..ebe2328e072 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy.expect @@ -1,2 +1,2 @@ + Dafny program verifier finished with 2 verified, 0 errors -ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect index 020b23b7235..2f22d47cee8 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy.expect @@ -1,2 +1,3 @@ + Dafny program verifier finished with 3 verified, 0 errors ok \ No newline at end of file From b04dce71e1f1f0f78019ba08f727bdbae4338ddc Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Tue, 17 Dec 2024 14:41:00 -0600 Subject: [PATCH 31/69] Fixed the fix --- Source/DafnyCore/Backends/Dafny/AST.dfy | 4 +- Source/DafnyCore/Backends/Dafny/ASTBuilder.cs | 2 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 36 +- .../Rust/Dafny-compiler-rust-rast.dfy | 4 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 52 +- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 63 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 2964 +++++++++-------- Source/DafnyCore/GeneratedFromDafny/RAST.cs | 7 +- Source/DafnyCore/Resolver/ModuleResolver.cs | 18 +- 9 files changed, 1576 insertions(+), 1574 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 64593f6c0a7..7d11362b43e 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -295,7 +295,7 @@ module {:extern "DAST"} DAST { datatype TypeParameterInfo = TypeParameterInfo(variance: Variance, necessaryForEqualitySupportOfSurroundingInductiveDatatype: bool) - datatype EqualitySupport = Never | Always | ConsultTypeArguments + datatype EqualitySupport = Never | ConsultTypeArguments datatype ResolvedTypeBase = | Class() @@ -495,7 +495,7 @@ module {:extern "DAST"} DAST { SeqValue(elements: seq, typ: Type) | SetValue(elements: seq) | MultisetValue(elements: seq) | - MapValue(mapElems: seq<(Expression, Expression)>) | + MapValue(mapElems: seq<(Expression, Expression)>, domainType: Type, rangeType: Type) | MapBuilder(keyType: Type, valueType: Type) | SeqUpdate(expr: Expression, indexExpr: Expression, value: Expression) | MapUpdate(expr: Expression, indexExpr: Expression, value: Expression) | diff --git a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs index 8ca9a7e10b2..b95a13de24c 100644 --- a/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs +++ b/Source/DafnyCore/Backends/Dafny/ASTBuilder.cs @@ -1486,7 +1486,7 @@ class CallExprBuilder : ExprContainer, BuildableExpr { readonly List args = new(); List> outs = null; - public _ICallSignature Signature { get; } + public _ICallSignature Signature { get; } public CallExprBuilder(_ICallSignature signature) { Signature = signature; diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 6176acc75ff..8bb1171ec17 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -370,8 +370,7 @@ private static bool CanDowncast(Type parentTrait, TraitDecl subTrait, out Type d return canDowncast; } - private static bool IsCompatibleWith(Type type, TypeParameter typeParameter) - { + private static bool IsCompatibleWith(Type type, TypeParameter typeParameter) { return (typeParameter.Characteristics.EqualitySupport == TypeParameter.EqualitySupportValue.Unspecified || type.SupportsEquality) && typeParameter.TypeBounds.TrueForAll(t => type.IsSubtypeOf(t, false, true)); } @@ -437,8 +436,7 @@ from arg in ctor.Formals } } - private List GenTypeParams(List typePargs) - { + private List GenTypeParams(List typePargs) { List typeParams = new(); foreach (var tp in typePargs) { typeParams.Add(GenTypeArgDecl(tp)); @@ -508,10 +506,8 @@ protected override IClassWriter DeclareNewtype(NewtypeDecl nt, ConcreteSyntaxTre } else { constraint = (Option)Option.create_None(); } - var typeParams = GenTypeParams(nt.TypeArgs); - var equalitySupport = GenEqualitySupport(nt); - + var typeParams = GenTypeParams(nt.TypeArgs); return new ClassWriter(this, false, builder.Newtype( nt.GetCompileName(Options), typeParams, GenType(nt.BaseType), NativeTypeToNewtypeRange(nt, false), @@ -1159,7 +1155,7 @@ protected override void TrCallStmt(CallStmt s, string receiverReplacement, Concr if (s.Method == enclosingMethod && enclosingMethod.IsTailRecursive) { base.TrCallStmt(s, receiverReplacement, wr, wrStmts, wrStmtsAfterCall); } else { - var signature = GetCallSignature(s.Method);; + var signature = GetCallSignature(s.Method); ; var callBuilder = stmtContainer.Builder.Call(signature); base.TrCallStmt(s, receiverReplacement, new BuilderSyntaxTree(callBuilder, this), wrStmts, wrStmtsAfterCall); } @@ -1195,15 +1191,13 @@ protected override void EmitCallToInheritedMethod(Method method, [CanBeNull] Top } } - private _ICallSignature GetCallSignature(MethodOrFunction method) - { + private _ICallSignature GetCallSignature(MethodOrFunction method) { var parameters = GetParameters(method, out var inheritedParameters, out _); var signature = DAST.CallSignature.create_CallSignature(parameters, inheritedParameters); return signature; } - private Sequence GetParameters(MethodOrFunction method, out Sequence inheritedParameters, out MemberDecl inheritedMethod) - { + private Sequence GetParameters(MethodOrFunction method, out Sequence inheritedParameters, out MemberDecl inheritedMethod) { var parameters = GenFormals(method.Ins); inheritedMethod = GetTopMostOverriddenMemberDeclIfDifferent(method); var oldThisContext = thisContext; @@ -1212,7 +1206,7 @@ private _ICallSignature GetCallSignature(MethodOrFunction method) thisContext = oldThisContext; return parameters; } - + protected override ConcreteSyntaxTree StartCall(Function f, ConcreteSyntaxTree wr) { if (wr is BuilderSyntaxTree exprContainer) { var signature = GetCallSignature(f); @@ -1875,11 +1869,11 @@ private DAST.NewtypeRange NativeTypeToNewtypeRange(NewtypeDecl newtypeDecl, bool NativeType.Selection.UDoubleLong => NewtypeRange.create_U128(overflows), NativeType.Selection.DoubleLong => NewtypeRange.create_I128(overflows), _ => - EraseNewtypeLayers(newtypeDecl) is { } resType ? + EraseNewtypeLayers(newtypeDecl) is { } resType ? resType is BoolType ? NewtypeRange.create_Bool() : resType is MapType ? NewtypeRange.create_Map() : resType is SeqType ? NewtypeRange.create_Sequence() - :NewtypeRange.create_NoRange() : NewtypeRange.create_NoRange() + : NewtypeRange.create_NoRange() : NewtypeRange.create_NoRange() }); } @@ -1957,12 +1951,12 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type if (topLevel is NewtypeDecl newType) { var range = NativeTypeToNewtypeRange(newType, false); - var newtypeBase = newType.BaseType; + var newtypeBase = newType.RhsWithArgument(typeArgs); resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Newtype( GenType(newtypeBase), range, erasedIfNewtype); } else if (topLevel is TypeSynonymDecl typeSynonym) { // Also SubsetTypeDecl resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_SynonymType( - GenType(typeSynonym.Rhs.Subst(typeSynonym.TypeArgs.Zip(typeArgs).ToDictionary(kv => kv.Item1, kv => kv.Item2)).NormalizeExpand())); + GenType(typeSynonym.RhsWithArgument(typeArgs))); } else if (topLevel is TraitDecl traitDecl) { var traitType = traitDecl.IsReferenceTypeDecl ? TraitType.create_ObjectTrait() @@ -1992,7 +1986,7 @@ private static _IEqualitySupport GenEqualitySupport(Declaration decl) { IndDatatypeDecl.ES equalitySupport = decl is IndDatatypeDecl indDecl ? indDecl.EqualitySupport : decl is NewtypeDecl nt ? nt.EqualitySupport : IndDatatypeDecl.ES.Never; - + return equalitySupport switch { IndDatatypeDecl.ES.Never => EqualitySupport.create_Never(), IndDatatypeDecl.ES.ConsultTypeArguments => EqualitySupport.create_ConsultTypeArguments(), @@ -3226,7 +3220,8 @@ protected override void EmitMapDisplay(MapType mt, IOrigin tok, List>.FromArray(elementsAST.ToArray()) + Sequence<_System.Tuple2>.FromArray(elementsAST.ToArray()), + GenType(mt.Domain), GenType(mt.Range) )); } else { throw new InvalidOperationException(); @@ -3290,8 +3285,7 @@ protected override void EmitSetBuilder_Add(CollectionType ct, string collName, E //throw new InvalidOperationException(); } - private static _ICallSignature CreateSignature(ISequence<_IFormal> params_) - { + private static _ICallSignature CreateSignature(ISequence<_IFormal> params_) { return CallSignature.create_CallSignature(params_, params_); } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index 24b4d0a604c..f8883c6df55 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -459,7 +459,7 @@ module RAST match this { case ApplyAttribute(name, derived) => var arguments := if |derived| != 0 then - "("+SeqToString(derived, (derived: string) => derived)+")" + "("+SeqToString(derived, (derived: string) => derived, ", ")+")" else ""; "#["+name+arguments+"]" } @@ -1673,6 +1673,8 @@ module RAST PrecedenceAssociativity(9, LeftToRight) else PrecedenceAssociativity(110, RightToLeft) + case "=>" => // Not a Rust operation, used in the map macro syntax + PrecedenceAssociativity(120, RightToLeft) case _ => PrecedenceAssociativity(0, RequiresParentheses) } case Lambda(_, _, _) => PrecedenceAssociativity(300, LeftToRight) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 46de5b70bda..f901d966114 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -789,17 +789,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { rTypeParamsDecls, R.NamelessFields([R.NamelessField(R.PUB, wrappedType)]) ))]; - if c.equalitySupport.Always? || c.equalitySupport.ConsultTypeArguments? { - var consultTypeArguments := c.equalitySupport.ConsultTypeArguments?; + if c.equalitySupport.ConsultTypeArguments? { var eqImplBody := R.self.Sel("0").Equals(R.Identifier("other").Sel("0")); var hashImplBody := - hash_function.Apply([R.self.Sel("0"), R.Identifier("_state")]); + hash_function.Apply([R.Borrow(R.self.Sel("0")), R.Identifier("_state")]); var impls := GenEqHashImpls( c.typeParams, rTypeParamsDecls, rTypeParams, - consultTypeArguments, resultingType, eqImplBody, hashImplBody); @@ -906,15 +904,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Block( //"The newtype is marked as transparent", R.std.MSel("mem").MSel("transmute").AsExpr().Apply1(R.Identifier("o")))))))]))]; - var rTypeParamsDeclsWithHash := R.TypeParamDecl.AddConstraintsMultiple( - rTypeParamsDecls, [R.Hash] - ); - s := s + [ - HashImpl( - rTypeParamsDeclsWithHash, - resultingType, - hash_function.Apply([R.Borrow(R.Identifier("self").Sel("0")), R.Identifier("_state")]) - )]; if c.range.HasArithmeticOperations() { s := s + [ OpsImpl('+', rTypeParamsDecls, resultingType, newtypeName), @@ -1004,7 +993,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { typeParamsDecls: seq, rTypeParamsDecls: seq, rTypeParams: seq, - consultTypeArguments: bool, datatypeType: R.Type, eqImplBody: R.Expr, hashImplBody: R.Expr @@ -1013,12 +1001,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { { var rTypeParamsDeclsWithEq := rTypeParamsDecls; var rTypeParamsDeclsWithHash := rTypeParamsDecls; - if consultTypeArguments { - for i := 0 to |rTypeParamsDecls| { - if typeParamsDecls[i].info.necessaryForEqualitySupportOfSurroundingInductiveDatatype { - rTypeParamsDeclsWithEq := rTypeParamsDeclsWithEq[i := rTypeParamsDeclsWithEq[i].AddConstraints([R.Eq, R.Hash])]; - rTypeParamsDeclsWithHash := rTypeParamsDeclsWithHash[i := rTypeParamsDeclsWithHash[i].AddConstraints([R.Hash])]; - } + for i := 0 to |rTypeParamsDecls| { + if typeParamsDecls[i].info.necessaryForEqualitySupportOfSurroundingInductiveDatatype { + rTypeParamsDeclsWithEq := rTypeParamsDeclsWithEq[i := rTypeParamsDeclsWithEq[i].AddConstraints([R.Eq, R.Hash])]; + rTypeParamsDeclsWithHash := rTypeParamsDeclsWithHash[i := rTypeParamsDeclsWithHash[i].AddConstraints([R.Hash])]; } } impls := EqImpl(rTypeParamsDeclsWithEq, datatypeType, rTypeParams, eqImplBody); @@ -1225,7 +1211,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { )]; } } - var cIsAlwaysEq := c.equalitySupport.Always?; + var cIsAlwaysEq := c.equalitySupport.ConsultTypeArguments? && + forall t <- c.typeParams :: !t.info.necessaryForEqualitySupportOfSurroundingInductiveDatatype; var datatypeType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); // Derive PartialEq when c supports equality / derive Clone in all cases @@ -1457,13 +1444,11 @@ module {:extern "DCOMP"} DafnyToRustCompiler { SingletonsImpl(rTypeParamsDecls, datatypeType, instantiationType, singletonConstructors)]; } - if c.equalitySupport.Always? || c.equalitySupport.ConsultTypeArguments? { - var consultTypeArguments := c.equalitySupport.ConsultTypeArguments?; + if c.equalitySupport.ConsultTypeArguments? { var impls := GenEqHashImpls( c.typeParams, rTypeParamsDecls, rTypeParams, - consultTypeArguments, datatypeType, eqImplBody, hashImplBody); @@ -3199,7 +3184,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } } else { - r := Error("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"); + r := Error("Source and/or target types is/are not Object, Ptr, General trait or Datatype"); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } @@ -3722,29 +3707,32 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r, resultingOwnership := FromOwned(r, expectedOwnership); return; } - case MapValue(mapElems) => { + case MapValue(mapElems, rangeType, domainType) => { var generatedValues := []; readIdents := {}; - var i := 0; - while i < |mapElems| { + for i := 0 to |mapElems| { var recursiveGenKey, _, recIdentsKey := GenExpr(mapElems[i].0, selfIdent, env, OwnershipOwned); var recursiveGenValue, _, recIdentsValue := GenExpr(mapElems[i].1, selfIdent, env, OwnershipOwned); generatedValues := generatedValues + [(recursiveGenKey, recursiveGenValue)]; readIdents := readIdents + recIdentsKey + recIdentsValue; - i := i + 1; } - i := 0; var arguments := []; - while i < |generatedValues| { + for i := 0 to |generatedValues| { var genKey := generatedValues[i].0; var genValue := generatedValues[i].1; arguments := arguments + [R.BinaryOp("=>", genKey, genValue, DAST.Format.BinaryOpFormat.NoFormat())]; - i := i + 1; } r := R.dafny_runtime.MSel("map!").AsExpr().Apply(arguments); + if |generatedValues| == 0 { // Rust cannot infer the type + var rangeTpe := GenType(rangeType, GenTypeContext.default()); + var domainTpe := GenType(domainType, GenTypeContext.default()); + r := R.TypeAscription( + r, R.dafny_runtime.MSel("Map").AsType().Apply([rangeTpe, domainTpe]) + ); + } r, resultingOwnership := FromOwned(r, expectedOwnership); return; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 00e01fe305c..168904aecc5 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -2722,7 +2722,6 @@ public bool dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype { public interface _IEqualitySupport { bool is_Never { get; } - bool is_Always { get; } bool is_ConsultTypeArguments { get; } _IEqualitySupport DowncastClone(); } @@ -2740,19 +2739,14 @@ public static DAST._IEqualitySupport Default() { public static _IEqualitySupport create_Never() { return new EqualitySupport_Never(); } - public static _IEqualitySupport create_Always() { - return new EqualitySupport_Always(); - } public static _IEqualitySupport create_ConsultTypeArguments() { return new EqualitySupport_ConsultTypeArguments(); } public bool is_Never { get { return this is EqualitySupport_Never; } } - public bool is_Always { get { return this is EqualitySupport_Always; } } public bool is_ConsultTypeArguments { get { return this is EqualitySupport_ConsultTypeArguments; } } public static System.Collections.Generic.IEnumerable<_IEqualitySupport> AllSingletonConstructors { get { yield return EqualitySupport.create_Never(); - yield return EqualitySupport.create_Always(); yield return EqualitySupport.create_ConsultTypeArguments(); } } @@ -2779,27 +2773,6 @@ public override string ToString() { return s; } } - public class EqualitySupport_Always : EqualitySupport { - public EqualitySupport_Always() : base() { - } - public override _IEqualitySupport DowncastClone() { - if (this is _IEqualitySupport dt) { return dt; } - return new EqualitySupport_Always(); - } - public override bool Equals(object other) { - var oth = other as DAST.EqualitySupport_Always; - return oth != null; - } - public override int GetHashCode() { - ulong hash = 5381; - hash = ((hash << 5) + hash) + 1; - return (int) hash; - } - public override string ToString() { - string s = "DAST.EqualitySupport.Always"; - return s; - } - } public class EqualitySupport_ConsultTypeArguments : EqualitySupport { public EqualitySupport_ConsultTypeArguments() : base() { } @@ -2813,7 +2786,7 @@ public override bool Equals(object other) { } public override int GetHashCode() { ulong hash = 5381; - hash = ((hash << 5) + hash) + 2; + hash = ((hash << 5) + hash) + 1; return (int) hash; } public override string ToString() { @@ -7076,6 +7049,8 @@ public interface _IExpression { DAST._IExpression dtor_elem { get; } Dafny.ISequence dtor_elements { get; } Dafny.ISequence<_System._ITuple2> dtor_mapElems { get; } + DAST._IType dtor_domainType { get; } + DAST._IType dtor_rangeType { get; } DAST._IType dtor_keyType { get; } DAST._IType dtor_valueType { get; } DAST._IExpression dtor_expr { get; } @@ -7188,8 +7163,8 @@ public static _IExpression create_SetValue(Dafny.ISequence el public static _IExpression create_MultisetValue(Dafny.ISequence elements) { return new Expression_MultisetValue(elements); } - public static _IExpression create_MapValue(Dafny.ISequence<_System._ITuple2> mapElems) { - return new Expression_MapValue(mapElems); + public static _IExpression create_MapValue(Dafny.ISequence<_System._ITuple2> mapElems, DAST._IType domainType, DAST._IType rangeType) { + return new Expression_MapValue(mapElems, domainType, rangeType); } public static _IExpression create_MapBuilder(DAST._IType keyType, DAST._IType valueType) { return new Expression_MapBuilder(keyType, valueType); @@ -7485,6 +7460,18 @@ public Dafny.ISequence dtor_elements { return ((Expression_MapValue)d)._mapElems; } } + public DAST._IType dtor_domainType { + get { + var d = this; + return ((Expression_MapValue)d)._domainType; + } + } + public DAST._IType dtor_rangeType { + get { + var d = this; + return ((Expression_MapValue)d)._rangeType; + } + } public DAST._IType dtor_keyType { get { var d = this; @@ -8306,27 +8293,37 @@ public override string ToString() { } public class Expression_MapValue : Expression { public readonly Dafny.ISequence<_System._ITuple2> _mapElems; - public Expression_MapValue(Dafny.ISequence<_System._ITuple2> mapElems) : base() { + public readonly DAST._IType _domainType; + public readonly DAST._IType _rangeType; + public Expression_MapValue(Dafny.ISequence<_System._ITuple2> mapElems, DAST._IType domainType, DAST._IType rangeType) : base() { this._mapElems = mapElems; + this._domainType = domainType; + this._rangeType = rangeType; } public override _IExpression DowncastClone() { if (this is _IExpression dt) { return dt; } - return new Expression_MapValue(_mapElems); + return new Expression_MapValue(_mapElems, _domainType, _rangeType); } public override bool Equals(object other) { var oth = other as DAST.Expression_MapValue; - return oth != null && object.Equals(this._mapElems, oth._mapElems); + return oth != null && object.Equals(this._mapElems, oth._mapElems) && object.Equals(this._domainType, oth._domainType) && object.Equals(this._rangeType, oth._rangeType); } public override int GetHashCode() { ulong hash = 5381; hash = ((hash << 5) + hash) + 15; hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._mapElems)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._domainType)); + hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._rangeType)); return (int) hash; } public override string ToString() { string s = "DAST.Expression.MapValue"; s += "("; s += Dafny.Helpers.ToString(this._mapElems); + s += ", "; + s += Dafny.Helpers.ToString(this._domainType); + s += ", "; + s += Dafny.Helpers.ToString(this._rangeType); s += ")"; return s; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index b54f0004167..ad4e865b2dd 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -731,50 +731,48 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _10_deriveTraits = Dafny.Sequence>.Concat(_10_deriveTraits, Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("Copy"))); } s = Dafny.Sequence.FromElements(RAST.ModDecl.create_StructDecl(RAST.Struct.create((c).dtor_docString, Dafny.Sequence.FromElements(RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("derive"), _10_deriveTraits), RAST.Attribute.create(Dafny.Sequence.UnicodeFromString("repr"), Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("transparent")))), _7_newtypeName, _2_rTypeParamsDecls, RAST.Fields.create_NamelessFields(Dafny.Sequence.FromElements(RAST.NamelessField.create(RAST.Visibility.create_PUB(), _4_wrappedType)))))); - if ((((c).dtor_equalitySupport).is_Always) || (((c).dtor_equalitySupport).is_ConsultTypeArguments)) { - bool _11_consultTypeArguments; - _11_consultTypeArguments = ((c).dtor_equalitySupport).is_ConsultTypeArguments; - RAST._IExpr _12_eqImplBody; - _12_eqImplBody = ((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))).Equals((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0"))); - RAST._IExpr _13_hashImplBody; - _13_hashImplBody = (Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); - Dafny.ISequence _14_impls; + if (((c).dtor_equalitySupport).is_ConsultTypeArguments) { + RAST._IExpr _11_eqImplBody; + _11_eqImplBody = ((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))).Equals((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other"))).Sel(Dafny.Sequence.UnicodeFromString("0"))); + RAST._IExpr _12_hashImplBody; + _12_hashImplBody = (Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + Dafny.ISequence _13_impls; Dafny.ISequence _out4; - _out4 = (this).GenEqHashImpls((c).dtor_typeParams, _2_rTypeParamsDecls, _1_rTypeParams, _11_consultTypeArguments, _8_resultingType, _12_eqImplBody, _13_hashImplBody); - _14_impls = _out4; - s = Dafny.Sequence.Concat(s, _14_impls); + _out4 = (this).GenEqHashImpls((c).dtor_typeParams, _2_rTypeParamsDecls, _1_rTypeParams, _8_resultingType, _11_eqImplBody, _12_hashImplBody); + _13_impls = _out4; + s = Dafny.Sequence.Concat(s, _13_impls); } - RAST._IExpr _15_fnBody = RAST.Expr.Default(); + RAST._IExpr _14_fnBody = RAST.Expr.Default(); Std.Wrappers._IOption _source0 = (c).dtor_witnessExpr; { if (_source0.is_Some) { - DAST._IExpression _16_e = _source0.dtor_value; + DAST._IExpression _15_e = _source0.dtor_value; { - DAST._IExpression _17_e; - _17_e = DAST.Expression.create_Convert(_16_e, (c).dtor_base, _6_newtypeType); - RAST._IExpr _18_r; - Defs._IOwnership _19___v5; - Dafny.ISet> _20___v6; + DAST._IExpression _16_e; + _16_e = DAST.Expression.create_Convert(_15_e, (c).dtor_base, _6_newtypeType); + RAST._IExpr _17_r; + Defs._IOwnership _18___v5; + Dafny.ISet> _19___v6; RAST._IExpr _out5; Defs._IOwnership _out6; Dafny.ISet> _out7; - (this).GenExpr(_17_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); - _18_r = _out5; - _19___v5 = _out6; - _20___v6 = _out7; - _15_fnBody = _18_r; + (this).GenExpr(_16_e, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out5, out _out6, out _out7); + _17_r = _out5; + _18___v5 = _out6; + _19___v6 = _out7; + _14_fnBody = _17_r; } goto after_match0; } } { { - _15_fnBody = (RAST.Expr.create_Identifier(_7_newtypeName)).Apply1(RAST.__default.std__default__Default__default); + _14_fnBody = (RAST.Expr.create_Identifier(_7_newtypeName)).Apply1(RAST.__default.std__default__Default__default); } } after_match0: ; - RAST._IImplMember _21_body; - _21_body = RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _7_newtypeName), Dafny.Sequence.FromElements(), RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("default"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(_15_fnBody))); + RAST._IImplMember _20_body; + _20_body = RAST.ImplMember.create_FnDecl(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("An element of "), _7_newtypeName), Dafny.Sequence.FromElements(), RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("default"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(), Std.Wrappers.Option.create_Some(RAST.__default.SelfOwned), Std.Wrappers.Option.create_Some(_14_fnBody))); Std.Wrappers._IOption _source1 = (c).dtor_constraint; { if (_source1.is_None) { @@ -783,50 +781,47 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } { DAST._INewtypeConstraint value0 = _source1.dtor_value; - DAST._IFormal _22_formal = value0.dtor_variable; - Dafny.ISequence _23_constraintStmts = value0.dtor_constraintStmts; - RAST._IExpr _24_rStmts; - Dafny.ISet> _25___v7; - Defs._IEnvironment _26_newEnv; + DAST._IFormal _21_formal = value0.dtor_variable; + Dafny.ISequence _22_constraintStmts = value0.dtor_constraintStmts; + RAST._IExpr _23_rStmts; + Dafny.ISet> _24___v7; + Defs._IEnvironment _25_newEnv; RAST._IExpr _out8; Dafny.ISet> _out9; Defs._IEnvironment _out10; - (this).GenStmts(_23_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out8, out _out9, out _out10); - _24_rStmts = _out8; - _25___v7 = _out9; - _26_newEnv = _out10; - Dafny.ISequence _27_rFormals; + (this).GenStmts(_22_constraintStmts, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), false, Std.Wrappers.Option>>.create_None(), out _out8, out _out9, out _out10); + _23_rStmts = _out8; + _24___v7 = _out9; + _25_newEnv = _out10; + Dafny.ISequence _26_rFormals; Dafny.ISequence _out11; - _out11 = (this).GenParams(Dafny.Sequence.FromElements(_22_formal), Dafny.Sequence.FromElements(_22_formal), false); - _27_rFormals = _out11; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Constraint check"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _27_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_24_rStmts)))))))); + _out11 = (this).GenParams(Dafny.Sequence.FromElements(_21_formal), Dafny.Sequence.FromElements(_21_formal), false); + _26_rFormals = _out11; + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Constraint check"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("is"), Dafny.Sequence.FromElements(), _26_rFormals, Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_23_rStmts)))))))); } after_match1: ; - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _8_resultingType, Dafny.Sequence.FromElements(_21_body))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DefaultTrait, _8_resultingType, Dafny.Sequence.FromElements(_20_body))))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, RAST.__default.DafnyPrint, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("For Dafny print statements"), RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("fmt_print"), Dafny.Sequence.FromElements(), Defs.__default.fmt__print__parameters, Std.Wrappers.Option.create_Some(Defs.__default.fmt__print__result), Std.Wrappers.Option.create_Some(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("in_seq")))))))))))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("ops"))).MSel(Dafny.Sequence.UnicodeFromString("Deref"))).AsType(), _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_TypeDeclMember(Dafny.Sequence.UnicodeFromString("Target"), _4_wrappedType), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("deref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed(((RAST.Path.create_Self()).MSel(Dafny.Sequence.UnicodeFromString("Target"))).AsType())), Std.Wrappers.Option.create_Some(RAST.__default.Borrow((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("0"))))))))))); s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, _8_resultingType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("SAFETY: The newtype is marked as transparent"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_from_ref"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("o"), RAST.Type.create_Borrowed(_4_wrappedType))), Std.Wrappers.Option.create_Some(RAST.Type.create_Borrowed((RAST.Path.create_Self()).AsType())), Std.Wrappers.Option.create_Some(RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("mem"))).MSel(Dafny.Sequence.UnicodeFromString("transmute"))).AsExpr()).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("o"))))))))))))); - Dafny.ISequence _28_rTypeParamsDeclsWithHash; - _28_rTypeParamsDeclsWithHash = RAST.TypeParamDecl.AddConstraintsMultiple(_2_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.Hash)); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.HashImpl(_28_rTypeParamsDeclsWithHash, _8_resultingType, (Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.__default.Borrow((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))).Sel(Dafny.Sequence.UnicodeFromString("0"))), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))))); if (((c).dtor_range).HasArithmeticOperations()) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.OpsImpl(new Dafny.Rune('+'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('-'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('*'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.OpsImpl(new Dafny.Rune('/'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName), Defs.__default.PartialOrdImpl(_2_rTypeParamsDecls, _8_resultingType, _7_newtypeName))); } if (((c).dtor_range).is_Bool) { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.UnaryOpsImpl(new Dafny.Rune('!'), _2_rTypeParamsDecls, _8_resultingType, _7_newtypeName))); } - Dafny.ISequence _29_implementation; - Dafny.IMap>,Dafny.ISequence> _30_traitBodies; + Dafny.ISequence _27_implementation; + Dafny.IMap>,Dafny.ISequence> _28_traitBodies; Dafny.ISequence _out12; Dafny.IMap>,Dafny.ISequence> _out13; (this).GenClassImplBody((c).dtor_classItems, false, _6_newtypeType, _0_typeParamsSeq, out _out12, out _out13); - _29_implementation = _out12; - _30_traitBodies = _out13; - if ((new BigInteger((_30_traitBodies).Count)).Sign == 1) { + _27_implementation = _out12; + _28_traitBodies = _out13; + if ((new BigInteger((_28_traitBodies).Count)).Sign == 1) { (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.UnicodeFromString("No support for trait in newtypes yet")); } - if ((new BigInteger((_29_implementation).Count)).Sign == 1) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams), _29_implementation)))); + if ((new BigInteger((_27_implementation).Count)).Sign == 1) { + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_2_rTypeParamsDecls, RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_7_newtypeName), _1_rTypeParams), _27_implementation)))); } return s; } @@ -902,20 +897,18 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) { return (this).write(RAST.Expr.create_LiteralString(s, false, false), false); } - public Dafny.ISequence GenEqHashImpls(Dafny.ISequence typeParamsDecls, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence rTypeParams, bool consultTypeArguments, RAST._IType datatypeType, RAST._IExpr eqImplBody, RAST._IExpr hashImplBody) + public Dafny.ISequence GenEqHashImpls(Dafny.ISequence typeParamsDecls, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence rTypeParams, RAST._IType datatypeType, RAST._IExpr eqImplBody, RAST._IExpr hashImplBody) { Dafny.ISequence impls = Dafny.Sequence.Empty; Dafny.ISequence _0_rTypeParamsDeclsWithEq; _0_rTypeParamsDeclsWithEq = rTypeParamsDecls; Dafny.ISequence _1_rTypeParamsDeclsWithHash; _1_rTypeParamsDeclsWithHash = rTypeParamsDecls; - if (consultTypeArguments) { - BigInteger _hi0 = new BigInteger((rTypeParamsDecls).Count); - for (BigInteger _2_i = BigInteger.Zero; _2_i < _hi0; _2_i++) { - if ((((typeParamsDecls).Select(_2_i)).dtor_info).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype) { - _0_rTypeParamsDeclsWithEq = Dafny.Sequence.Update(_0_rTypeParamsDeclsWithEq, _2_i, ((_0_rTypeParamsDeclsWithEq).Select(_2_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Eq, RAST.__default.Hash))); - _1_rTypeParamsDeclsWithHash = Dafny.Sequence.Update(_1_rTypeParamsDeclsWithHash, _2_i, ((_1_rTypeParamsDeclsWithHash).Select(_2_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Hash))); - } + BigInteger _hi0 = new BigInteger((rTypeParamsDecls).Count); + for (BigInteger _2_i = BigInteger.Zero; _2_i < _hi0; _2_i++) { + if ((((typeParamsDecls).Select(_2_i)).dtor_info).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype) { + _0_rTypeParamsDeclsWithEq = Dafny.Sequence.Update(_0_rTypeParamsDeclsWithEq, _2_i, ((_0_rTypeParamsDeclsWithEq).Select(_2_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Eq, RAST.__default.Hash))); + _1_rTypeParamsDeclsWithHash = Dafny.Sequence.Update(_1_rTypeParamsDeclsWithHash, _2_i, ((_1_rTypeParamsDeclsWithHash).Select(_2_i)).AddConstraints(Dafny.Sequence.FromElements(RAST.__default.Hash))); } } impls = Defs.__default.EqImpl(_0_rTypeParamsDeclsWithEq, datatypeType, rTypeParams, eqImplBody); @@ -1168,252 +1161,253 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } } bool _68_cIsAlwaysEq; - _68_cIsAlwaysEq = ((c).dtor_equalitySupport).is_Always; - RAST._IType _69_datatypeType; - _69_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); - s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, Dafny.Sequence.FromElements(RAST.Attribute.DeriveClone), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _69_datatypeType, _27_implBody))); + _68_cIsAlwaysEq = (((c).dtor_equalitySupport).is_ConsultTypeArguments) && (Dafny.Helpers.Id>((_69_c) => Dafny.Helpers.Quantifier(((_69_c).dtor_typeParams).UniqueElements, true, (((_forall_var_0) => { + DAST._ITypeArgDecl _70_t = (DAST._ITypeArgDecl)_forall_var_0; + return !(((_69_c).dtor_typeParams).Contains(_70_t)) || (!(((_70_t).dtor_info).dtor_necessaryForEqualitySupportOfSurroundingInductiveDatatype)); + }))))(c)); + RAST._IType _71_datatypeType; + _71_datatypeType = RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(_4_datatypeName), _2_rTypeParams); + s = Dafny.Sequence.FromElements(RAST.ModDecl.create_EnumDecl(RAST.Enum.create((c).dtor_docString, Dafny.Sequence.FromElements(RAST.Attribute.DeriveClone), _4_datatypeName, _3_rTypeParamsDecls, _6_ctors)), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(_3_rTypeParamsDecls, _71_datatypeType, _27_implBody))); if ((new BigInteger(((c).dtor_superTraitTypes).Count)).Sign == 1) { - RAST._IType _70_fullType; + RAST._IType _72_fullType; if (_0_isRcWrapped) { - _70_fullType = RAST.__default.Rc(_69_datatypeType); + _72_fullType = RAST.__default.Rc(_71_datatypeType); } else { - _70_fullType = _69_datatypeType; + _72_fullType = _71_datatypeType; } - Std.Wrappers._IOption _71_downcastDefinitionOpt; - _71_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_3_rTypeParamsDecls, _70_fullType); - if ((_71_downcastDefinitionOpt).is_None) { - RAST._IExpr _72_dummy; + Std.Wrappers._IOption _73_downcastDefinitionOpt; + _73_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_3_rTypeParamsDecls, _72_fullType); + if ((_73_downcastDefinitionOpt).is_None) { + RAST._IExpr _74_dummy; RAST._IExpr _out15; - _out15 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _72_dummy = _out15; + _out15 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast definition for "), (_72_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _74_dummy = _out15; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_71_downcastDefinitionOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_73_downcastDefinitionOpt).dtor_value)); } - Std.Wrappers._IOption _73_downcastImplementationsOpt; - _73_downcastImplementationsOpt = Defs.__default.DowncastImplFor(_3_rTypeParamsDecls, _70_fullType); - if ((_73_downcastImplementationsOpt).is_None) { - RAST._IExpr _74_dummy; + Std.Wrappers._IOption _75_downcastImplementationsOpt; + _75_downcastImplementationsOpt = Defs.__default.DowncastImplFor(_3_rTypeParamsDecls, _72_fullType); + if ((_75_downcastImplementationsOpt).is_None) { + RAST._IExpr _76_dummy; RAST._IExpr _out16; - _out16 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _74_dummy = _out16; + _out16 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation for "), (_72_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _76_dummy = _out16; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_73_downcastImplementationsOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_75_downcastImplementationsOpt).dtor_value)); } BigInteger _hi7 = new BigInteger(((c).dtor_superTraitNegativeTypes).Count); - for (BigInteger _75_i = BigInteger.Zero; _75_i < _hi7; _75_i++) { - RAST._IType _76_negativeTraitType; + for (BigInteger _77_i = BigInteger.Zero; _77_i < _hi7; _77_i++) { + RAST._IType _78_negativeTraitType; RAST._IType _out17; - _out17 = (this).GenType(((c).dtor_superTraitNegativeTypes).Select(_75_i), Defs.GenTypeContext.@default()); - _76_negativeTraitType = _out17; - Std.Wrappers._IOption _77_downcastDefinitionOpt; - _77_downcastDefinitionOpt = Defs.__default.DowncastNotImplFor(_3_rTypeParamsDecls, _76_negativeTraitType, _70_fullType); - if ((_77_downcastDefinitionOpt).is_None) { - RAST._IExpr _78_dummy; + _out17 = (this).GenType(((c).dtor_superTraitNegativeTypes).Select(_77_i), Defs.GenTypeContext.@default()); + _78_negativeTraitType = _out17; + Std.Wrappers._IOption _79_downcastDefinitionOpt; + _79_downcastDefinitionOpt = Defs.__default.DowncastNotImplFor(_3_rTypeParamsDecls, _78_negativeTraitType, _72_fullType); + if ((_79_downcastDefinitionOpt).is_None) { + RAST._IExpr _80_dummy; RAST._IExpr _out18; - _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate negative downcast definition for "), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _78_dummy = _out18; + _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate negative downcast definition for "), (_72_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _80_dummy = _out18; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_77_downcastDefinitionOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_79_downcastDefinitionOpt).dtor_value)); } } BigInteger _hi8 = new BigInteger(((c).dtor_superTraitTypes).Count); - for (BigInteger _79_i = BigInteger.Zero; _79_i < _hi8; _79_i++) { - DAST._IType _80_c; - _80_c = ((c).dtor_superTraitTypes).Select(_79_i); - if ((((_80_c).is_UserDefined) && ((((_80_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_80_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { + for (BigInteger _81_i = BigInteger.Zero; _81_i < _hi8; _81_i++) { + DAST._IType _82_c; + _82_c = ((c).dtor_superTraitTypes).Select(_81_i); + if ((((_82_c).is_UserDefined) && ((((_82_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_82_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { goto continue_3_0; } - RAST._IType _81_cType; + RAST._IType _83_cType; RAST._IType _out19; - _out19 = (this).GenType(_80_c, Defs.GenTypeContext.@default()); - _81_cType = _out19; - bool _82_isImplementing; - _82_isImplementing = true; - Std.Wrappers._IOption _83_downcastImplementationsOpt; - _83_downcastImplementationsOpt = Defs.__default.DowncastImplTraitFor(_3_rTypeParamsDecls, _81_cType, _82_isImplementing, _70_fullType); - if ((_83_downcastImplementationsOpt).is_None) { - RAST._IExpr _84_dummy; + _out19 = (this).GenType(_82_c, Defs.GenTypeContext.@default()); + _83_cType = _out19; + bool _84_isImplementing; + _84_isImplementing = true; + Std.Wrappers._IOption _85_downcastImplementationsOpt; + _85_downcastImplementationsOpt = Defs.__default.DowncastImplTraitFor(_3_rTypeParamsDecls, _83_cType, _84_isImplementing, _72_fullType); + if ((_85_downcastImplementationsOpt).is_None) { + RAST._IExpr _86_dummy; RAST._IExpr _out20; - _out20 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation of "), (_81_cType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" for ")), (_70_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); - _84_dummy = _out20; + _out20 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate downcast implementation of "), (_83_cType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" for ")), (_72_fullType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _86_dummy = _out20; } else { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_83_downcastImplementationsOpt).dtor_value)); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_85_downcastImplementationsOpt).dtor_value)); } continue_3_0: ; } after_3_0: ; } - Dafny.ISequence _85_printImplBodyCases; - _85_printImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _86_hashImplBodyCases; - _86_hashImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _87_coerceImplBodyCases; - _87_coerceImplBodyCases = Dafny.Sequence.FromElements(); - Dafny.ISequence _88_partialEqImplBodyCases; - _88_partialEqImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _87_printImplBodyCases; + _87_printImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _88_hashImplBodyCases; + _88_hashImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _89_coerceImplBodyCases; + _89_coerceImplBodyCases = Dafny.Sequence.FromElements(); + Dafny.ISequence _90_partialEqImplBodyCases; + _90_partialEqImplBodyCases = Dafny.Sequence.FromElements(); BigInteger _hi9 = new BigInteger(((c).dtor_ctors).Count); - for (BigInteger _89_i = BigInteger.Zero; _89_i < _hi9; _89_i++) { - DAST._IDatatypeCtor _90_ctor; - _90_ctor = ((c).dtor_ctors).Select(_89_i); - Dafny.ISequence _91_ctorMatch; - _91_ctorMatch = Defs.__default.escapeName((_90_ctor).dtor_name); - Dafny.ISequence _92_modulePrefix; + for (BigInteger _91_i = BigInteger.Zero; _91_i < _hi9; _91_i++) { + DAST._IDatatypeCtor _92_ctor; + _92_ctor = ((c).dtor_ctors).Select(_91_i); + Dafny.ISequence _93_ctorMatch; + _93_ctorMatch = Defs.__default.escapeName((_92_ctor).dtor_name); + Dafny.ISequence _94_modulePrefix; if (((((c).dtor_enclosingModule))).Equals(Dafny.Sequence.UnicodeFromString("_module"))) { - _92_modulePrefix = Dafny.Sequence.UnicodeFromString(""); + _94_modulePrefix = Dafny.Sequence.UnicodeFromString(""); } else { - _92_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); - } - Dafny.ISequence _93_ctorName; - _93_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_92_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_90_ctor).dtor_name)); - if (((new BigInteger((_93_ctorName).Count)) >= (new BigInteger(13))) && (((_93_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { - _93_ctorName = Dafny.Sequence.UnicodeFromString(""); - } - RAST._IExpr _94_printRhs; - _94_printRhs = (this).writeStr(Dafny.Sequence.Concat(_93_ctorName, (((_90_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); - RAST._IExpr _95_hashRhs; - _95_hashRhs = (this).InitEmptyExpr(); - RAST._IExpr _96_partialEqRhs; - _96_partialEqRhs = RAST.Expr.create_LiteralBool(true); - Dafny.ISequence _97_coerceRhsArgs; - _97_coerceRhsArgs = Dafny.Sequence.FromElements(); - bool _98_isNumeric; - _98_isNumeric = false; - Dafny.ISequence _99_ctorMatchInner; - _99_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); - Dafny.ISequence _100_ctorMatchInner2; - _100_ctorMatchInner2 = Dafny.Sequence.UnicodeFromString(""); - BigInteger _hi10 = new BigInteger(((_90_ctor).dtor_args).Count); - for (BigInteger _101_j = BigInteger.Zero; _101_j < _hi10; _101_j++) { - DAST._IDatatypeDtor _102_dtor; - _102_dtor = ((_90_ctor).dtor_args).Select(_101_j); - Dafny.ISequence _103_patternName; - _103_patternName = Defs.__default.escapeVar(((_102_dtor).dtor_formal).dtor_name); - DAST._IType _104_formalType; - _104_formalType = ((_102_dtor).dtor_formal).dtor_typ; - if (((_101_j).Sign == 0) && ((_103_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { - _98_isNumeric = true; - } - if (_98_isNumeric) { - _103_patternName = Std.Wrappers.Option>.GetOr((_102_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_101_j))); - } - if ((_104_formalType).is_Arrow) { - _95_hashRhs = (_95_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); + _94_modulePrefix = Dafny.Sequence.Concat((((c).dtor_enclosingModule)), Dafny.Sequence.UnicodeFromString(".")); + } + Dafny.ISequence _95_ctorName; + _95_ctorName = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_94_modulePrefix, ((c).dtor_name)), Dafny.Sequence.UnicodeFromString(".")), ((_92_ctor).dtor_name)); + if (((new BigInteger((_95_ctorName).Count)) >= (new BigInteger(13))) && (((_95_ctorName).Subsequence(BigInteger.Zero, new BigInteger(13))).Equals(Dafny.Sequence.UnicodeFromString("_System.Tuple")))) { + _95_ctorName = Dafny.Sequence.UnicodeFromString(""); + } + RAST._IExpr _96_printRhs; + _96_printRhs = (this).writeStr(Dafny.Sequence.Concat(_95_ctorName, (((_92_ctor).dtor_hasAnyArgs) ? (Dafny.Sequence.UnicodeFromString("(")) : (Dafny.Sequence.UnicodeFromString("")))), false); + RAST._IExpr _97_hashRhs; + _97_hashRhs = (this).InitEmptyExpr(); + RAST._IExpr _98_partialEqRhs; + _98_partialEqRhs = RAST.Expr.create_LiteralBool(true); + Dafny.ISequence _99_coerceRhsArgs; + _99_coerceRhsArgs = Dafny.Sequence.FromElements(); + bool _100_isNumeric; + _100_isNumeric = false; + Dafny.ISequence _101_ctorMatchInner; + _101_ctorMatchInner = Dafny.Sequence.UnicodeFromString(""); + Dafny.ISequence _102_ctorMatchInner2; + _102_ctorMatchInner2 = Dafny.Sequence.UnicodeFromString(""); + BigInteger _hi10 = new BigInteger(((_92_ctor).dtor_args).Count); + for (BigInteger _103_j = BigInteger.Zero; _103_j < _hi10; _103_j++) { + DAST._IDatatypeDtor _104_dtor; + _104_dtor = ((_92_ctor).dtor_args).Select(_103_j); + Dafny.ISequence _105_patternName; + _105_patternName = Defs.__default.escapeVar(((_104_dtor).dtor_formal).dtor_name); + DAST._IType _106_formalType; + _106_formalType = ((_104_dtor).dtor_formal).dtor_typ; + if (((_103_j).Sign == 0) && ((_105_patternName).Equals(Dafny.Sequence.UnicodeFromString("0")))) { + _100_isNumeric = true; + } + if (_100_isNumeric) { + _105_patternName = Std.Wrappers.Option>.GetOr((_104_dtor).dtor_callName, Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("v"), Std.Strings.__default.OfNat(_103_j))); + } + if ((_106_formalType).is_Arrow) { + _97_hashRhs = (_97_hashRhs).Then(((RAST.Expr.create_LiteralInt(Dafny.Sequence.UnicodeFromString("0"))).Sel(Dafny.Sequence.UnicodeFromString("hash"))).Apply1(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state")))); } else { - _95_hashRhs = (_95_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_103_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); + _97_hashRhs = (_97_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_105_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); } - _99_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_99_ctorMatchInner, _103_patternName), Dafny.Sequence.UnicodeFromString(", ")); - _100_ctorMatchInner2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_100_ctorMatchInner2, _103_patternName), Dafny.Sequence.UnicodeFromString(": ")), Dafny.Sequence.UnicodeFromString("_2_")), _103_patternName), Dafny.Sequence.UnicodeFromString(", ")); - if ((_104_formalType).is_Arrow) { - _96_partialEqRhs = (_96_partialEqRhs).And(RAST.Expr.create_LiteralBool(false)); + _101_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_101_ctorMatchInner, _105_patternName), Dafny.Sequence.UnicodeFromString(", ")); + _102_ctorMatchInner2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_102_ctorMatchInner2, _105_patternName), Dafny.Sequence.UnicodeFromString(": ")), Dafny.Sequence.UnicodeFromString("_2_")), _105_patternName), Dafny.Sequence.UnicodeFromString(", ")); + if ((_106_formalType).is_Arrow) { + _98_partialEqRhs = (_98_partialEqRhs).And(RAST.Expr.create_LiteralBool(false)); } else { - _96_partialEqRhs = (_96_partialEqRhs).And((RAST.Expr.create_Identifier(_103_patternName)).Equals(RAST.Expr.create_Identifier(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_2_"), _103_patternName)))); + _98_partialEqRhs = (_98_partialEqRhs).And((RAST.Expr.create_Identifier(_105_patternName)).Equals(RAST.Expr.create_Identifier(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_2_"), _105_patternName)))); } - if ((_101_j).Sign == 1) { - _94_printRhs = (_94_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); + if ((_103_j).Sign == 1) { + _96_printRhs = (_96_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); } - _94_printRhs = (_94_printRhs).Then((((_104_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_103_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); - RAST._IExpr _105_coerceRhsArg = RAST.Expr.Default(); - RAST._IType _106_formalTpe; + _96_printRhs = (_96_printRhs).Then((((_106_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_105_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); + RAST._IExpr _107_coerceRhsArg = RAST.Expr.Default(); + RAST._IType _108_formalTpe; RAST._IType _out21; - _out21 = (this).GenType(_104_formalType, Defs.GenTypeContext.@default()); - _106_formalTpe = _out21; - DAST._IType _107_newFormalType; - _107_newFormalType = (_104_formalType).Replace(_51_coerceMap); - RAST._IType _108_newFormalTpe; - _108_newFormalTpe = (_106_formalTpe).ReplaceMap(_52_rCoerceMap); - Std.Wrappers._IResult,RAST._IExpr>>> _109_upcastConverter; - _109_upcastConverter = (this).UpcastConversionLambda(_104_formalType, _106_formalTpe, _107_newFormalType, _108_newFormalTpe, _53_coerceMapToArg); - if ((_109_upcastConverter).is_Success) { - RAST._IExpr _110_coercionFunction; - _110_coercionFunction = (_109_upcastConverter).dtor_value; - _105_coerceRhsArg = (_110_coercionFunction).Apply1(RAST.Expr.create_Identifier(_103_patternName)); + _out21 = (this).GenType(_106_formalType, Defs.GenTypeContext.@default()); + _108_formalTpe = _out21; + DAST._IType _109_newFormalType; + _109_newFormalType = (_106_formalType).Replace(_51_coerceMap); + RAST._IType _110_newFormalTpe; + _110_newFormalTpe = (_108_formalTpe).ReplaceMap(_52_rCoerceMap); + Std.Wrappers._IResult,RAST._IExpr>>> _111_upcastConverter; + _111_upcastConverter = (this).UpcastConversionLambda(_106_formalType, _108_formalTpe, _109_newFormalType, _110_newFormalTpe, _53_coerceMapToArg); + if ((_111_upcastConverter).is_Success) { + RAST._IExpr _112_coercionFunction; + _112_coercionFunction = (_111_upcastConverter).dtor_value; + _107_coerceRhsArg = (_112_coercionFunction).Apply1(RAST.Expr.create_Identifier(_105_patternName)); } else { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_101_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); - _105_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); - } - _97_coerceRhsArgs = Dafny.Sequence.Concat(_97_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_103_patternName, _105_coerceRhsArg))); - } - RAST._IExpr _111_coerceRhs; - _111_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_90_ctor).dtor_name)), _97_coerceRhsArgs); - Dafny.ISequence _112_pattern = Dafny.Sequence.Empty; - Dafny.ISequence _113_pattern2 = Dafny.Sequence.Empty; - if (_98_isNumeric) { - _112_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_91_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _99_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); - _113_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_91_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _100_ctorMatchInner2), Dafny.Sequence.UnicodeFromString(")")); + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_103_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); + _107_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); + } + _99_coerceRhsArgs = Dafny.Sequence.Concat(_99_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_105_patternName, _107_coerceRhsArg))); + } + RAST._IExpr _113_coerceRhs; + _113_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_92_ctor).dtor_name)), _99_coerceRhsArgs); + Dafny.ISequence _114_pattern = Dafny.Sequence.Empty; + Dafny.ISequence _115_pattern2 = Dafny.Sequence.Empty; + if (_100_isNumeric) { + _114_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _101_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + _115_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _102_ctorMatchInner2), Dafny.Sequence.UnicodeFromString(")")); } else { - _112_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_91_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _99_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); - _113_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_91_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _100_ctorMatchInner2), Dafny.Sequence.UnicodeFromString("}")); + _114_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _101_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + _115_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _102_ctorMatchInner2), Dafny.Sequence.UnicodeFromString("}")); } - if ((_90_ctor).dtor_hasAnyArgs) { - _94_printRhs = (_94_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); + if ((_92_ctor).dtor_hasAnyArgs) { + _96_printRhs = (_96_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); } - _94_printRhs = (_94_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); - _85_printImplBodyCases = Dafny.Sequence.Concat(_85_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _112_pattern), RAST.Expr.create_Block(_94_printRhs)))); - _86_hashImplBodyCases = Dafny.Sequence.Concat(_86_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _112_pattern), RAST.Expr.create_Block(_95_hashRhs)))); - _88_partialEqImplBodyCases = Dafny.Sequence.Concat(_88_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _112_pattern), Dafny.Sequence.UnicodeFromString(", ")), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _113_pattern2), Dafny.Sequence.UnicodeFromString(")")), RAST.Expr.create_Block(_96_partialEqRhs)))); - _87_coerceImplBodyCases = Dafny.Sequence.Concat(_87_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _91_ctorMatch), RAST.Expr.create_Block(_111_coerceRhs)))); + _96_printRhs = (_96_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); + _87_printImplBodyCases = Dafny.Sequence.Concat(_87_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _114_pattern), RAST.Expr.create_Block(_96_printRhs)))); + _88_hashImplBodyCases = Dafny.Sequence.Concat(_88_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _114_pattern), RAST.Expr.create_Block(_97_hashRhs)))); + _90_partialEqImplBodyCases = Dafny.Sequence.Concat(_90_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _114_pattern), Dafny.Sequence.UnicodeFromString(", ")), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _115_pattern2), Dafny.Sequence.UnicodeFromString(")")), RAST.Expr.create_Block(_98_partialEqRhs)))); + _89_coerceImplBodyCases = Dafny.Sequence.Concat(_89_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _93_ctorMatch), RAST.Expr.create_Block(_113_coerceRhs)))); } - _88_partialEqImplBodyCases = Dafny.Sequence.Concat(_88_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.UnicodeFromString("_"), RAST.Expr.create_Block(RAST.Expr.create_LiteralBool(false))))); + _90_partialEqImplBodyCases = Dafny.Sequence.Concat(_90_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.UnicodeFromString("_"), RAST.Expr.create_Block(RAST.Expr.create_LiteralBool(false))))); if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { - Dafny.ISequence _114_extraCases; - _114_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); - _85_printImplBodyCases = Dafny.Sequence.Concat(_85_printImplBodyCases, _114_extraCases); - _86_hashImplBodyCases = Dafny.Sequence.Concat(_86_hashImplBodyCases, _114_extraCases); - _87_coerceImplBodyCases = Dafny.Sequence.Concat(_87_coerceImplBodyCases, _114_extraCases); - } - Dafny.ISequence _115_defaultConstrainedTypeParams; - _115_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - RAST._IExpr _116_printImplBody; - _116_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _85_printImplBodyCases); - RAST._IExpr _117_hashImplBody; - _117_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _86_hashImplBodyCases); - RAST._IExpr _118_eqImplBody; - _118_eqImplBody = RAST.Expr.create_Match(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))), _88_partialEqImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _69_datatypeType, _2_rTypeParams, _116_printImplBody))); + Dafny.ISequence _116_extraCases; + _116_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + _87_printImplBodyCases = Dafny.Sequence.Concat(_87_printImplBodyCases, _116_extraCases); + _88_hashImplBodyCases = Dafny.Sequence.Concat(_88_hashImplBodyCases, _116_extraCases); + _89_coerceImplBodyCases = Dafny.Sequence.Concat(_89_coerceImplBodyCases, _116_extraCases); + } + Dafny.ISequence _117_defaultConstrainedTypeParams; + _117_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + RAST._IExpr _118_printImplBody; + _118_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _87_printImplBodyCases); + RAST._IExpr _119_hashImplBody; + _119_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _88_hashImplBodyCases); + RAST._IExpr _120_eqImplBody; + _120_eqImplBody = RAST.Expr.create_Match(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))), _90_partialEqImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _71_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _71_datatypeType, _2_rTypeParams, _118_printImplBody))); if ((new BigInteger((_49_rCoerceTypeParams).Count)).Sign == 1) { - RAST._IExpr _119_coerceImplBody; - _119_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _87_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _69_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _119_coerceImplBody))); + RAST._IExpr _121_coerceImplBody; + _121_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _89_coerceImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _71_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _121_coerceImplBody))); } if ((new BigInteger((_9_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { - RAST._IType _120_instantiationType; + RAST._IType _122_instantiationType; if (_0_isRcWrapped) { - _120_instantiationType = RAST.__default.Rc(_69_datatypeType); + _122_instantiationType = RAST.__default.Rc(_71_datatypeType); } else { - _120_instantiationType = _69_datatypeType; + _122_instantiationType = _71_datatypeType; } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _69_datatypeType, _120_instantiationType, _9_singletonConstructors))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _71_datatypeType, _122_instantiationType, _9_singletonConstructors))); } - if ((((c).dtor_equalitySupport).is_Always) || (((c).dtor_equalitySupport).is_ConsultTypeArguments)) { - bool _121_consultTypeArguments; - _121_consultTypeArguments = ((c).dtor_equalitySupport).is_ConsultTypeArguments; - Dafny.ISequence _122_impls; + if (((c).dtor_equalitySupport).is_ConsultTypeArguments) { + Dafny.ISequence _123_impls; Dafny.ISequence _out22; - _out22 = (this).GenEqHashImpls((c).dtor_typeParams, _3_rTypeParamsDecls, _2_rTypeParams, _121_consultTypeArguments, _69_datatypeType, _118_eqImplBody, _117_hashImplBody); - _122_impls = _out22; - s = Dafny.Sequence.Concat(s, _122_impls); + _out22 = (this).GenEqHashImpls((c).dtor_typeParams, _3_rTypeParamsDecls, _2_rTypeParams, _71_datatypeType, _120_eqImplBody, _119_hashImplBody); + _123_impls = _out22; + s = Dafny.Sequence.Concat(s, _123_impls); } if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - RAST._IExpr _123_structName; - _123_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _124_structAssignments; - _124_structAssignments = Dafny.Sequence.FromElements(); + RAST._IExpr _124_structName; + _124_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _125_structAssignments; + _125_structAssignments = Dafny.Sequence.FromElements(); BigInteger _hi11 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); - for (BigInteger _125_i = BigInteger.Zero; _125_i < _hi11; _125_i++) { - DAST._IDatatypeDtor _126_dtor; - _126_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_125_i); - _124_structAssignments = Dafny.Sequence.Concat(_124_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_126_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); + for (BigInteger _126_i = BigInteger.Zero; _126_i < _hi11; _126_i++) { + DAST._IDatatypeDtor _127_dtor; + _127_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_126_i); + _125_structAssignments = Dafny.Sequence.Concat(_125_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_127_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); } if ((false) && (_68_cIsAlwaysEq)) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _69_datatypeType, _123_structName, _124_structAssignments))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _71_datatypeType, _124_structName, _125_structAssignments))); } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _69_datatypeType))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _71_datatypeType))); } - Dafny.ISequence _127_superTraitImplementations; + Dafny.ISequence _128_superTraitImplementations; Dafny.ISequence _out23; _out23 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, _68_cIsAlwaysEq, Dafny.Sequence.UnicodeFromString("datatype")); - _127_superTraitImplementations = _out23; - s = Dafny.Sequence.Concat(s, _127_superTraitImplementations); + _128_superTraitImplementations = _out23; + s = Dafny.Sequence.Concat(s, _128_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -4431,7 +4425,7 @@ public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership } } else { RAST._IExpr _out12; - _out12 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"), (this).InitEmptyExpr()); + _out12 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types is/are not Object, Ptr, General trait or Datatype"), (this).InitEmptyExpr()); r = _out12; RAST._IExpr _out13; Defs._IOwnership _out14; @@ -5375,54 +5369,64 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { if (_source0.is_MapValue) { Dafny.ISequence<_System._ITuple2> _102_mapElems = _source0.dtor_mapElems; + DAST._IType _103_rangeType = _source0.dtor_domainType; + DAST._IType _104_domainType = _source0.dtor_rangeType; { - Dafny.ISequence<_System._ITuple2> _103_generatedValues; - _103_generatedValues = Dafny.Sequence<_System._ITuple2>.FromElements(); + Dafny.ISequence<_System._ITuple2> _105_generatedValues; + _105_generatedValues = Dafny.Sequence<_System._ITuple2>.FromElements(); readIdents = Dafny.Set>.FromElements(); - BigInteger _104_i; - _104_i = BigInteger.Zero; - while ((_104_i) < (new BigInteger((_102_mapElems).Count))) { - RAST._IExpr _105_recursiveGenKey; - Defs._IOwnership _106___v90; - Dafny.ISet> _107_recIdentsKey; + BigInteger _hi7 = new BigInteger((_102_mapElems).Count); + for (BigInteger _106_i = BigInteger.Zero; _106_i < _hi7; _106_i++) { + RAST._IExpr _107_recursiveGenKey; + Defs._IOwnership _108___v90; + Dafny.ISet> _109_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; - (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); - _105_recursiveGenKey = _out90; - _106___v90 = _out91; - _107_recIdentsKey = _out92; - RAST._IExpr _108_recursiveGenValue; - Defs._IOwnership _109___v91; - Dafny.ISet> _110_recIdentsValue; + (this).GenExpr(((_102_mapElems).Select(_106_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); + _107_recursiveGenKey = _out90; + _108___v90 = _out91; + _109_recIdentsKey = _out92; + RAST._IExpr _110_recursiveGenValue; + Defs._IOwnership _111___v91; + Dafny.ISet> _112_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; - (this).GenExpr(((_102_mapElems).Select(_104_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); - _108_recursiveGenValue = _out93; - _109___v91 = _out94; - _110_recIdentsValue = _out95; - _103_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_103_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_105_recursiveGenKey, _108_recursiveGenValue))); - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _107_recIdentsKey), _110_recIdentsValue); - _104_i = (_104_i) + (BigInteger.One); - } - _104_i = BigInteger.Zero; - Dafny.ISequence _111_arguments; - _111_arguments = Dafny.Sequence.FromElements(); - while ((_104_i) < (new BigInteger((_103_generatedValues).Count))) { - RAST._IExpr _112_genKey; - _112_genKey = ((_103_generatedValues).Select(_104_i)).dtor__0; - RAST._IExpr _113_genValue; - _113_genValue = ((_103_generatedValues).Select(_104_i)).dtor__1; - _111_arguments = Dafny.Sequence.Concat(_111_arguments, Dafny.Sequence.FromElements(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=>"), _112_genKey, _113_genValue, DAST.Format.BinaryOpFormat.create_NoFormat()))); - _104_i = (_104_i) + (BigInteger.One); - } - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("map!"))).AsExpr()).Apply(_111_arguments); - RAST._IExpr _out96; - Defs._IOwnership _out97; - (this).FromOwned(r, expectedOwnership, out _out96, out _out97); - r = _out96; - resultingOwnership = _out97; + (this).GenExpr(((_102_mapElems).Select(_106_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); + _110_recursiveGenValue = _out93; + _111___v91 = _out94; + _112_recIdentsValue = _out95; + _105_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_105_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_107_recursiveGenKey, _110_recursiveGenValue))); + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _109_recIdentsKey), _112_recIdentsValue); + } + Dafny.ISequence _113_arguments; + _113_arguments = Dafny.Sequence.FromElements(); + BigInteger _hi8 = new BigInteger((_105_generatedValues).Count); + for (BigInteger _114_i = BigInteger.Zero; _114_i < _hi8; _114_i++) { + RAST._IExpr _115_genKey; + _115_genKey = ((_105_generatedValues).Select(_114_i)).dtor__0; + RAST._IExpr _116_genValue; + _116_genValue = ((_105_generatedValues).Select(_114_i)).dtor__1; + _113_arguments = Dafny.Sequence.Concat(_113_arguments, Dafny.Sequence.FromElements(RAST.Expr.create_BinaryOp(Dafny.Sequence.UnicodeFromString("=>"), _115_genKey, _116_genValue, DAST.Format.BinaryOpFormat.create_NoFormat()))); + } + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("map!"))).AsExpr()).Apply(_113_arguments); + if ((new BigInteger((_105_generatedValues).Count)).Sign == 0) { + RAST._IType _117_rangeTpe; + RAST._IType _out96; + _out96 = (this).GenType(_103_rangeType, Defs.GenTypeContext.@default()); + _117_rangeTpe = _out96; + RAST._IType _118_domainTpe; + RAST._IType _out97; + _out97 = (this).GenType(_104_domainType, Defs.GenTypeContext.@default()); + _118_domainTpe = _out97; + r = RAST.Expr.create_TypeAscription(r, (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Map"))).AsType()).Apply(Dafny.Sequence.FromElements(_117_rangeTpe, _118_domainTpe))); + } + RAST._IExpr _out98; + Defs._IOwnership _out99; + (this).FromOwned(r, expectedOwnership, out _out98, out _out99); + r = _out98; + resultingOwnership = _out99; return ; } goto after_match0; @@ -5430,47 +5434,47 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SeqUpdate) { - DAST._IExpression _114_expr = _source0.dtor_expr; - DAST._IExpression _115_index = _source0.dtor_indexExpr; - DAST._IExpression _116_value = _source0.dtor_value; + DAST._IExpression _119_expr = _source0.dtor_expr; + DAST._IExpression _120_index = _source0.dtor_indexExpr; + DAST._IExpression _121_value = _source0.dtor_value; { - RAST._IExpr _117_exprR; - Defs._IOwnership _118___v92; - Dafny.ISet> _119_exprIdents; - RAST._IExpr _out98; - Defs._IOwnership _out99; - Dafny.ISet> _out100; - (this).GenExpr(_114_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out98, out _out99, out _out100); - _117_exprR = _out98; - _118___v92 = _out99; - _119_exprIdents = _out100; - RAST._IExpr _120_indexR; - Defs._IOwnership _121_indexOwnership; - Dafny.ISet> _122_indexIdents; - RAST._IExpr _out101; - Defs._IOwnership _out102; - Dafny.ISet> _out103; - (this).GenExpr(_115_index, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out101, out _out102, out _out103); - _120_indexR = _out101; - _121_indexOwnership = _out102; - _122_indexIdents = _out103; - RAST._IExpr _123_valueR; - Defs._IOwnership _124_valueOwnership; - Dafny.ISet> _125_valueIdents; - RAST._IExpr _out104; - Defs._IOwnership _out105; - Dafny.ISet> _out106; - (this).GenExpr(_116_value, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out104, out _out105, out _out106); - _123_valueR = _out104; - _124_valueOwnership = _out105; - _125_valueIdents = _out106; - r = ((_117_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_120_indexR, _123_valueR)); - RAST._IExpr _out107; - Defs._IOwnership _out108; - (this).FromOwned(r, expectedOwnership, out _out107, out _out108); - r = _out107; - resultingOwnership = _out108; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_119_exprIdents, _122_indexIdents), _125_valueIdents); + RAST._IExpr _122_exprR; + Defs._IOwnership _123___v92; + Dafny.ISet> _124_exprIdents; + RAST._IExpr _out100; + Defs._IOwnership _out101; + Dafny.ISet> _out102; + (this).GenExpr(_119_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out100, out _out101, out _out102); + _122_exprR = _out100; + _123___v92 = _out101; + _124_exprIdents = _out102; + RAST._IExpr _125_indexR; + Defs._IOwnership _126_indexOwnership; + Dafny.ISet> _127_indexIdents; + RAST._IExpr _out103; + Defs._IOwnership _out104; + Dafny.ISet> _out105; + (this).GenExpr(_120_index, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out103, out _out104, out _out105); + _125_indexR = _out103; + _126_indexOwnership = _out104; + _127_indexIdents = _out105; + RAST._IExpr _128_valueR; + Defs._IOwnership _129_valueOwnership; + Dafny.ISet> _130_valueIdents; + RAST._IExpr _out106; + Defs._IOwnership _out107; + Dafny.ISet> _out108; + (this).GenExpr(_121_value, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out106, out _out107, out _out108); + _128_valueR = _out106; + _129_valueOwnership = _out107; + _130_valueIdents = _out108; + r = ((_122_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_125_indexR, _128_valueR)); + RAST._IExpr _out109; + Defs._IOwnership _out110; + (this).FromOwned(r, expectedOwnership, out _out109, out _out110); + r = _out109; + resultingOwnership = _out110; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_124_exprIdents, _127_indexIdents), _130_valueIdents); return ; } goto after_match0; @@ -5478,47 +5482,47 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapUpdate) { - DAST._IExpression _126_expr = _source0.dtor_expr; - DAST._IExpression _127_index = _source0.dtor_indexExpr; - DAST._IExpression _128_value = _source0.dtor_value; + DAST._IExpression _131_expr = _source0.dtor_expr; + DAST._IExpression _132_index = _source0.dtor_indexExpr; + DAST._IExpression _133_value = _source0.dtor_value; { - RAST._IExpr _129_exprR; - Defs._IOwnership _130___v93; - Dafny.ISet> _131_exprIdents; - RAST._IExpr _out109; - Defs._IOwnership _out110; - Dafny.ISet> _out111; - (this).GenExpr(_126_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out109, out _out110, out _out111); - _129_exprR = _out109; - _130___v93 = _out110; - _131_exprIdents = _out111; - RAST._IExpr _132_indexR; - Defs._IOwnership _133_indexOwnership; - Dafny.ISet> _134_indexIdents; - RAST._IExpr _out112; - Defs._IOwnership _out113; - Dafny.ISet> _out114; - (this).GenExpr(_127_index, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out112, out _out113, out _out114); - _132_indexR = _out112; - _133_indexOwnership = _out113; - _134_indexIdents = _out114; - RAST._IExpr _135_valueR; - Defs._IOwnership _136_valueOwnership; - Dafny.ISet> _137_valueIdents; - RAST._IExpr _out115; - Defs._IOwnership _out116; - Dafny.ISet> _out117; - (this).GenExpr(_128_value, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out115, out _out116, out _out117); - _135_valueR = _out115; - _136_valueOwnership = _out116; - _137_valueIdents = _out117; - r = ((_129_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_132_indexR, _135_valueR)); - RAST._IExpr _out118; - Defs._IOwnership _out119; - (this).FromOwned(r, expectedOwnership, out _out118, out _out119); - r = _out118; - resultingOwnership = _out119; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_131_exprIdents, _134_indexIdents), _137_valueIdents); + RAST._IExpr _134_exprR; + Defs._IOwnership _135___v93; + Dafny.ISet> _136_exprIdents; + RAST._IExpr _out111; + Defs._IOwnership _out112; + Dafny.ISet> _out113; + (this).GenExpr(_131_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out111, out _out112, out _out113); + _134_exprR = _out111; + _135___v93 = _out112; + _136_exprIdents = _out113; + RAST._IExpr _137_indexR; + Defs._IOwnership _138_indexOwnership; + Dafny.ISet> _139_indexIdents; + RAST._IExpr _out114; + Defs._IOwnership _out115; + Dafny.ISet> _out116; + (this).GenExpr(_132_index, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out114, out _out115, out _out116); + _137_indexR = _out114; + _138_indexOwnership = _out115; + _139_indexIdents = _out116; + RAST._IExpr _140_valueR; + Defs._IOwnership _141_valueOwnership; + Dafny.ISet> _142_valueIdents; + RAST._IExpr _out117; + Defs._IOwnership _out118; + Dafny.ISet> _out119; + (this).GenExpr(_133_value, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out117, out _out118, out _out119); + _140_valueR = _out117; + _141_valueOwnership = _out118; + _142_valueIdents = _out119; + r = ((_134_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_137_indexR, _140_valueR)); + RAST._IExpr _out120; + Defs._IOwnership _out121; + (this).FromOwned(r, expectedOwnership, out _out120, out _out121); + r = _out120; + resultingOwnership = _out121; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_136_exprIdents, _139_indexIdents), _142_valueIdents); return ; } goto after_match0; @@ -5530,31 +5534,31 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Defs._ISelfInfo _source1 = selfIdent; { if (_source1.is_ThisTyped) { - Dafny.ISequence _138_id = _source1.dtor_rSelfName; - DAST._IType _139_dafnyType = _source1.dtor_dafnyType; + Dafny.ISequence _143_id = _source1.dtor_rSelfName; + DAST._IType _144_dafnyType = _source1.dtor_dafnyType; { - RAST._IExpr _out120; - Defs._IOwnership _out121; - Dafny.ISet> _out122; - (this).GenIdent(_138_id, selfIdent, env, expectedOwnership, out _out120, out _out121, out _out122); - r = _out120; - resultingOwnership = _out121; - readIdents = _out122; + RAST._IExpr _out122; + Defs._IOwnership _out123; + Dafny.ISet> _out124; + (this).GenIdent(_143_id, selfIdent, env, expectedOwnership, out _out122, out _out123, out _out124); + r = _out122; + resultingOwnership = _out123; + readIdents = _out124; } goto after_match1; } } { - Defs._ISelfInfo _140_None = _source1; + Defs._ISelfInfo _145_None = _source1; { - RAST._IExpr _out123; - _out123 = (this).Error(Dafny.Sequence.UnicodeFromString("this outside of a method"), (this).InitEmptyExpr()); - r = _out123; - RAST._IExpr _out124; - Defs._IOwnership _out125; - (this).FromOwned(r, expectedOwnership, out _out124, out _out125); - r = _out124; - resultingOwnership = _out125; + RAST._IExpr _out125; + _out125 = (this).Error(Dafny.Sequence.UnicodeFromString("this outside of a method"), (this).InitEmptyExpr()); + r = _out125; + RAST._IExpr _out126; + Defs._IOwnership _out127; + (this).FromOwned(r, expectedOwnership, out _out126, out _out127); + r = _out126; + resultingOwnership = _out127; readIdents = Dafny.Set>.FromElements(); } } @@ -5566,47 +5570,47 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Ite) { - DAST._IExpression _141_cond = _source0.dtor_cond; - DAST._IExpression _142_t = _source0.dtor_thn; - DAST._IExpression _143_f = _source0.dtor_els; + DAST._IExpression _146_cond = _source0.dtor_cond; + DAST._IExpression _147_t = _source0.dtor_thn; + DAST._IExpression _148_f = _source0.dtor_els; { - RAST._IExpr _144_cond; - Defs._IOwnership _145___v94; - Dafny.ISet> _146_recIdentsCond; - RAST._IExpr _out126; - Defs._IOwnership _out127; - Dafny.ISet> _out128; - (this).GenExpr(_141_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out126, out _out127, out _out128); - _144_cond = _out126; - _145___v94 = _out127; - _146_recIdentsCond = _out128; - RAST._IExpr _147_fExpr; - Defs._IOwnership _148_fOwned; - Dafny.ISet> _149_recIdentsF; - RAST._IExpr _out129; - Defs._IOwnership _out130; - Dafny.ISet> _out131; - (this).GenExpr(_143_f, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out129, out _out130, out _out131); - _147_fExpr = _out129; - _148_fOwned = _out130; - _149_recIdentsF = _out131; - RAST._IExpr _150_tExpr; - Defs._IOwnership _151___v95; - Dafny.ISet> _152_recIdentsT; - RAST._IExpr _out132; - Defs._IOwnership _out133; - Dafny.ISet> _out134; - (this).GenExpr(_142_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out132, out _out133, out _out134); - _150_tExpr = _out132; - _151___v95 = _out133; - _152_recIdentsT = _out134; - r = RAST.Expr.create_IfExpr(_144_cond, _150_tExpr, _147_fExpr); - RAST._IExpr _out135; - Defs._IOwnership _out136; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out135, out _out136); - r = _out135; - resultingOwnership = _out136; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_146_recIdentsCond, _152_recIdentsT), _149_recIdentsF); + RAST._IExpr _149_cond; + Defs._IOwnership _150___v94; + Dafny.ISet> _151_recIdentsCond; + RAST._IExpr _out128; + Defs._IOwnership _out129; + Dafny.ISet> _out130; + (this).GenExpr(_146_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out128, out _out129, out _out130); + _149_cond = _out128; + _150___v94 = _out129; + _151_recIdentsCond = _out130; + RAST._IExpr _152_fExpr; + Defs._IOwnership _153_fOwned; + Dafny.ISet> _154_recIdentsF; + RAST._IExpr _out131; + Defs._IOwnership _out132; + Dafny.ISet> _out133; + (this).GenExpr(_148_f, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out131, out _out132, out _out133); + _152_fExpr = _out131; + _153_fOwned = _out132; + _154_recIdentsF = _out133; + RAST._IExpr _155_tExpr; + Defs._IOwnership _156___v95; + Dafny.ISet> _157_recIdentsT; + RAST._IExpr _out134; + Defs._IOwnership _out135; + Dafny.ISet> _out136; + (this).GenExpr(_147_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out134, out _out135, out _out136); + _155_tExpr = _out134; + _156___v95 = _out135; + _157_recIdentsT = _out136; + r = RAST.Expr.create_IfExpr(_149_cond, _155_tExpr, _152_fExpr); + RAST._IExpr _out137; + Defs._IOwnership _out138; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out137, out _out138); + r = _out137; + resultingOwnership = _out138; + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_151_recIdentsCond, _157_recIdentsT), _154_recIdentsF); return ; } goto after_match0; @@ -5616,55 +5620,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_UnOp) { DAST._IUnaryOp unOp0 = _source0.dtor_unOp; if (unOp0.is_Not) { - DAST._IExpression _153_e = _source0.dtor_expr; - DAST.Format._IUnaryOpFormat _154_format = _source0.dtor_format1; - { - RAST._IExpr _155_recursiveGen; - Defs._IOwnership _156___v96; - Dafny.ISet> _157_recIdents; - RAST._IExpr _out137; - Defs._IOwnership _out138; - Dafny.ISet> _out139; - (this).GenExpr(_153_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out137, out _out138, out _out139); - _155_recursiveGen = _out137; - _156___v96 = _out138; - _157_recIdents = _out139; - r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _155_recursiveGen, _154_format); - RAST._IExpr _out140; - Defs._IOwnership _out141; - (this).FromOwned(r, expectedOwnership, out _out140, out _out141); - r = _out140; - resultingOwnership = _out141; - readIdents = _157_recIdents; - return ; - } - goto after_match0; - } - } - } - { - if (_source0.is_UnOp) { - DAST._IUnaryOp unOp1 = _source0.dtor_unOp; - if (unOp1.is_BitwiseNot) { DAST._IExpression _158_e = _source0.dtor_expr; DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; { RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v97; + Defs._IOwnership _161___v96; Dafny.ISet> _162_recIdents; + RAST._IExpr _out139; + Defs._IOwnership _out140; + Dafny.ISet> _out141; + (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out139, out _out140, out _out141); + _160_recursiveGen = _out139; + _161___v96 = _out140; + _162_recIdents = _out141; + r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); RAST._IExpr _out142; Defs._IOwnership _out143; - Dafny.ISet> _out144; - (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out142, out _out143, out _out144); - _160_recursiveGen = _out142; - _161___v97 = _out143; - _162_recIdents = _out144; - r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); - RAST._IExpr _out145; - Defs._IOwnership _out146; - (this).FromOwned(r, expectedOwnership, out _out145, out _out146); - r = _out145; - resultingOwnership = _out146; + (this).FromOwned(r, expectedOwnership, out _out142, out _out143); + r = _out142; + resultingOwnership = _out143; readIdents = _162_recIdents; return ; } @@ -5674,27 +5648,27 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_UnOp) { - DAST._IUnaryOp unOp2 = _source0.dtor_unOp; - if (unOp2.is_Cardinality) { + DAST._IUnaryOp unOp1 = _source0.dtor_unOp; + if (unOp1.is_BitwiseNot) { DAST._IExpression _163_e = _source0.dtor_expr; DAST.Format._IUnaryOpFormat _164_format = _source0.dtor_format1; { RAST._IExpr _165_recursiveGen; - Defs._IOwnership _166_recOwned; + Defs._IOwnership _166___v97; Dafny.ISet> _167_recIdents; + RAST._IExpr _out144; + Defs._IOwnership _out145; + Dafny.ISet> _out146; + (this).GenExpr(_163_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out144, out _out145, out _out146); + _165_recursiveGen = _out144; + _166___v97 = _out145; + _167_recIdents = _out146; + r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _165_recursiveGen, _164_format); RAST._IExpr _out147; Defs._IOwnership _out148; - Dafny.ISet> _out149; - (this).GenExpr(_163_e, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out147, out _out148, out _out149); - _165_recursiveGen = _out147; - _166_recOwned = _out148; - _167_recIdents = _out149; - r = ((_165_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("cardinality"))).Apply0(); - RAST._IExpr _out150; - Defs._IOwnership _out151; - (this).FromOwned(r, expectedOwnership, out _out150, out _out151); - r = _out150; - resultingOwnership = _out151; + (this).FromOwned(r, expectedOwnership, out _out147, out _out148); + r = _out147; + resultingOwnership = _out148; readIdents = _167_recIdents; return ; } @@ -5702,65 +5676,95 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } } } + { + if (_source0.is_UnOp) { + DAST._IUnaryOp unOp2 = _source0.dtor_unOp; + if (unOp2.is_Cardinality) { + DAST._IExpression _168_e = _source0.dtor_expr; + DAST.Format._IUnaryOpFormat _169_format = _source0.dtor_format1; + { + RAST._IExpr _170_recursiveGen; + Defs._IOwnership _171_recOwned; + Dafny.ISet> _172_recIdents; + RAST._IExpr _out149; + Defs._IOwnership _out150; + Dafny.ISet> _out151; + (this).GenExpr(_168_e, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out149, out _out150, out _out151); + _170_recursiveGen = _out149; + _171_recOwned = _out150; + _172_recIdents = _out151; + r = ((_170_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("cardinality"))).Apply0(); + RAST._IExpr _out152; + Defs._IOwnership _out153; + (this).FromOwned(r, expectedOwnership, out _out152, out _out153); + r = _out152; + resultingOwnership = _out153; + readIdents = _172_recIdents; + return ; + } + goto after_match0; + } + } + } { if (_source0.is_BinOp) { - RAST._IExpr _out152; - Defs._IOwnership _out153; - Dafny.ISet> _out154; - (this).GenExprBinary(e, selfIdent, env, expectedOwnership, out _out152, out _out153, out _out154); - r = _out152; - resultingOwnership = _out153; - readIdents = _out154; + RAST._IExpr _out154; + Defs._IOwnership _out155; + Dafny.ISet> _out156; + (this).GenExprBinary(e, selfIdent, env, expectedOwnership, out _out154, out _out155, out _out156); + r = _out154; + resultingOwnership = _out155; + readIdents = _out156; goto after_match0; } } { if (_source0.is_ArrayLen) { - DAST._IExpression _168_expr = _source0.dtor_expr; - DAST._IType _169_exprType = _source0.dtor_exprType; - BigInteger _170_dim = _source0.dtor_dim; - bool _171_native = _source0.dtor_native; + DAST._IExpression _173_expr = _source0.dtor_expr; + DAST._IType _174_exprType = _source0.dtor_exprType; + BigInteger _175_dim = _source0.dtor_dim; + bool _176_native = _source0.dtor_native; { - RAST._IExpr _172_recursiveGen; - Defs._IOwnership _173___v102; - Dafny.ISet> _174_recIdents; - RAST._IExpr _out155; - Defs._IOwnership _out156; - Dafny.ISet> _out157; - (this).GenExpr(_168_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out155, out _out156, out _out157); - _172_recursiveGen = _out155; - _173___v102 = _out156; - _174_recIdents = _out157; - RAST._IType _175_arrayType; - RAST._IType _out158; - _out158 = (this).GenType(_169_exprType, Defs.GenTypeContext.@default()); - _175_arrayType = _out158; - if (!((_175_arrayType).IsObjectOrPointer())) { - RAST._IExpr _out159; - _out159 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array length of something not an array but "), (_175_arrayType)._ToString(Defs.__default.IND)), (this).InitEmptyExpr()); - r = _out159; + RAST._IExpr _177_recursiveGen; + Defs._IOwnership _178___v102; + Dafny.ISet> _179_recIdents; + RAST._IExpr _out157; + Defs._IOwnership _out158; + Dafny.ISet> _out159; + (this).GenExpr(_173_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out157, out _out158, out _out159); + _177_recursiveGen = _out157; + _178___v102 = _out158; + _179_recIdents = _out159; + RAST._IType _180_arrayType; + RAST._IType _out160; + _out160 = (this).GenType(_174_exprType, Defs.GenTypeContext.@default()); + _180_arrayType = _out160; + if (!((_180_arrayType).IsObjectOrPointer())) { + RAST._IExpr _out161; + _out161 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array length of something not an array but "), (_180_arrayType)._ToString(Defs.__default.IND)), (this).InitEmptyExpr()); + r = _out161; } else { - RAST._IType _176_underlying; - _176_underlying = (_175_arrayType).ObjectOrPointerUnderlying(); - if (((_170_dim).Sign == 0) && ((_176_underlying).is_Array)) { - r = ((((this).read__macro).Apply1(_172_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); + RAST._IType _181_underlying; + _181_underlying = (_180_arrayType).ObjectOrPointerUnderlying(); + if (((_175_dim).Sign == 0) && ((_181_underlying).is_Array)) { + r = ((((this).read__macro).Apply1(_177_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); } else { - if ((_170_dim).Sign == 0) { - r = (((((this).read__macro).Apply1(_172_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("data"))).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); + if ((_175_dim).Sign == 0) { + r = (((((this).read__macro).Apply1(_177_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("data"))).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); } else { - r = ((((this).read__macro).Apply1(_172_recursiveGen)).Sel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("length"), Std.Strings.__default.OfNat(_170_dim)), Dafny.Sequence.UnicodeFromString("_usize")))).Apply0(); + r = ((((this).read__macro).Apply1(_177_recursiveGen)).Sel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("length"), Std.Strings.__default.OfNat(_175_dim)), Dafny.Sequence.UnicodeFromString("_usize")))).Apply0(); } } - if (!(_171_native)) { + if (!(_176_native)) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(r); } } - RAST._IExpr _out160; - Defs._IOwnership _out161; - (this).FromOwned(r, expectedOwnership, out _out160, out _out161); - r = _out160; - resultingOwnership = _out161; - readIdents = _174_recIdents; + RAST._IExpr _out162; + Defs._IOwnership _out163; + (this).FromOwned(r, expectedOwnership, out _out162, out _out163); + r = _out162; + resultingOwnership = _out163; + readIdents = _179_recIdents; return ; } goto after_match0; @@ -5768,25 +5772,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapKeys) { - DAST._IExpression _177_expr = _source0.dtor_expr; + DAST._IExpression _182_expr = _source0.dtor_expr; { - RAST._IExpr _178_recursiveGen; - Defs._IOwnership _179___v103; - Dafny.ISet> _180_recIdents; - RAST._IExpr _out162; - Defs._IOwnership _out163; - Dafny.ISet> _out164; - (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out162, out _out163, out _out164); - _178_recursiveGen = _out162; - _179___v103 = _out163; - _180_recIdents = _out164; - readIdents = _180_recIdents; - r = ((_178_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); - RAST._IExpr _out165; - Defs._IOwnership _out166; - (this).FromOwned(r, expectedOwnership, out _out165, out _out166); - r = _out165; - resultingOwnership = _out166; + RAST._IExpr _183_recursiveGen; + Defs._IOwnership _184___v103; + Dafny.ISet> _185_recIdents; + RAST._IExpr _out164; + Defs._IOwnership _out165; + Dafny.ISet> _out166; + (this).GenExpr(_182_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out164, out _out165, out _out166); + _183_recursiveGen = _out164; + _184___v103 = _out165; + _185_recIdents = _out166; + readIdents = _185_recIdents; + r = ((_183_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); + RAST._IExpr _out167; + Defs._IOwnership _out168; + (this).FromOwned(r, expectedOwnership, out _out167, out _out168); + r = _out167; + resultingOwnership = _out168; return ; } goto after_match0; @@ -5794,25 +5798,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapValues) { - DAST._IExpression _181_expr = _source0.dtor_expr; + DAST._IExpression _186_expr = _source0.dtor_expr; { - RAST._IExpr _182_recursiveGen; - Defs._IOwnership _183___v104; - Dafny.ISet> _184_recIdents; - RAST._IExpr _out167; - Defs._IOwnership _out168; - Dafny.ISet> _out169; - (this).GenExpr(_181_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out167, out _out168, out _out169); - _182_recursiveGen = _out167; - _183___v104 = _out168; - _184_recIdents = _out169; - readIdents = _184_recIdents; - r = ((_182_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); - RAST._IExpr _out170; - Defs._IOwnership _out171; - (this).FromOwned(r, expectedOwnership, out _out170, out _out171); - r = _out170; - resultingOwnership = _out171; + RAST._IExpr _187_recursiveGen; + Defs._IOwnership _188___v104; + Dafny.ISet> _189_recIdents; + RAST._IExpr _out169; + Defs._IOwnership _out170; + Dafny.ISet> _out171; + (this).GenExpr(_186_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out169, out _out170, out _out171); + _187_recursiveGen = _out169; + _188___v104 = _out170; + _189_recIdents = _out171; + readIdents = _189_recIdents; + r = ((_187_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); + RAST._IExpr _out172; + Defs._IOwnership _out173; + (this).FromOwned(r, expectedOwnership, out _out172, out _out173); + r = _out172; + resultingOwnership = _out173; return ; } goto after_match0; @@ -5820,25 +5824,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapItems) { - DAST._IExpression _185_expr = _source0.dtor_expr; + DAST._IExpression _190_expr = _source0.dtor_expr; { - RAST._IExpr _186_recursiveGen; - Defs._IOwnership _187___v105; - Dafny.ISet> _188_recIdents; - RAST._IExpr _out172; - Defs._IOwnership _out173; - Dafny.ISet> _out174; - (this).GenExpr(_185_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out172, out _out173, out _out174); - _186_recursiveGen = _out172; - _187___v105 = _out173; - _188_recIdents = _out174; - readIdents = _188_recIdents; - r = ((_186_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); - RAST._IExpr _out175; - Defs._IOwnership _out176; - (this).FromOwned(r, expectedOwnership, out _out175, out _out176); - r = _out175; - resultingOwnership = _out176; + RAST._IExpr _191_recursiveGen; + Defs._IOwnership _192___v105; + Dafny.ISet> _193_recIdents; + RAST._IExpr _out174; + Defs._IOwnership _out175; + Dafny.ISet> _out176; + (this).GenExpr(_190_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out174, out _out175, out _out176); + _191_recursiveGen = _out174; + _192___v105 = _out175; + _193_recIdents = _out176; + readIdents = _193_recIdents; + r = ((_191_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); + RAST._IExpr _out177; + Defs._IOwnership _out178; + (this).FromOwned(r, expectedOwnership, out _out177, out _out178); + r = _out177; + resultingOwnership = _out178; return ; } goto after_match0; @@ -5846,100 +5850,100 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SelectFn) { - DAST._IExpression _189_on = _source0.dtor_expr; - Dafny.ISequence _190_field = _source0.dtor_field; - bool _191_isDatatype = _source0.dtor_onDatatype; - bool _192_isStatic = _source0.dtor_isStatic; - bool _193_isConstant = _source0.dtor_isConstant; - Dafny.ISequence _194_arguments = _source0.dtor_arguments; + DAST._IExpression _194_on = _source0.dtor_expr; + Dafny.ISequence _195_field = _source0.dtor_field; + bool _196_isDatatype = _source0.dtor_onDatatype; + bool _197_isStatic = _source0.dtor_isStatic; + bool _198_isConstant = _source0.dtor_isConstant; + Dafny.ISequence _199_arguments = _source0.dtor_arguments; { - RAST._IExpr _195_onExpr; - Defs._IOwnership _196_onOwned; - Dafny.ISet> _197_recIdents; - RAST._IExpr _out177; - Defs._IOwnership _out178; - Dafny.ISet> _out179; - (this).GenExpr(_189_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out177, out _out178, out _out179); - _195_onExpr = _out177; - _196_onOwned = _out178; - _197_recIdents = _out179; - Dafny.ISequence _198_onString; - _198_onString = (_195_onExpr)._ToString(Defs.__default.IND); - Defs._IEnvironment _199_lEnv; - _199_lEnv = env; - Dafny.ISequence<_System._ITuple2, RAST._IType>> _200_args; - _200_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(); - Dafny.ISequence _201_parameters; - _201_parameters = Dafny.Sequence.FromElements(); - BigInteger _hi7 = new BigInteger((_194_arguments).Count); - for (BigInteger _202_i = BigInteger.Zero; _202_i < _hi7; _202_i++) { - RAST._IType _203_ty; - RAST._IType _out180; - _out180 = (this).GenType((_194_arguments).Select(_202_i), Defs.GenTypeContext.@default()); - _203_ty = _out180; - RAST._IType _204_bTy; - _204_bTy = RAST.Type.create_Borrowed(_203_ty); - Dafny.ISequence _205_name; - _205_name = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("x"), Std.Strings.__default.OfInt(_202_i)); - _199_lEnv = (_199_lEnv).AddAssigned(_205_name, _204_bTy); - _201_parameters = Dafny.Sequence.Concat(_201_parameters, Dafny.Sequence.FromElements(RAST.Formal.create(_205_name, _204_bTy))); - _200_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.Concat(_200_args, Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(_System.Tuple2, RAST._IType>.create(_205_name, _203_ty))); - } - RAST._IExpr _206_body; - if (_192_isStatic) { - _206_body = (_195_onExpr).FSel(Defs.__default.escapeVar(_190_field)); + RAST._IExpr _200_onExpr; + Defs._IOwnership _201_onOwned; + Dafny.ISet> _202_recIdents; + RAST._IExpr _out179; + Defs._IOwnership _out180; + Dafny.ISet> _out181; + (this).GenExpr(_194_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out179, out _out180, out _out181); + _200_onExpr = _out179; + _201_onOwned = _out180; + _202_recIdents = _out181; + Dafny.ISequence _203_onString; + _203_onString = (_200_onExpr)._ToString(Defs.__default.IND); + Defs._IEnvironment _204_lEnv; + _204_lEnv = env; + Dafny.ISequence<_System._ITuple2, RAST._IType>> _205_args; + _205_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(); + Dafny.ISequence _206_parameters; + _206_parameters = Dafny.Sequence.FromElements(); + BigInteger _hi9 = new BigInteger((_199_arguments).Count); + for (BigInteger _207_i = BigInteger.Zero; _207_i < _hi9; _207_i++) { + RAST._IType _208_ty; + RAST._IType _out182; + _out182 = (this).GenType((_199_arguments).Select(_207_i), Defs.GenTypeContext.@default()); + _208_ty = _out182; + RAST._IType _209_bTy; + _209_bTy = RAST.Type.create_Borrowed(_208_ty); + Dafny.ISequence _210_name; + _210_name = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("x"), Std.Strings.__default.OfInt(_207_i)); + _204_lEnv = (_204_lEnv).AddAssigned(_210_name, _209_bTy); + _206_parameters = Dafny.Sequence.Concat(_206_parameters, Dafny.Sequence.FromElements(RAST.Formal.create(_210_name, _209_bTy))); + _205_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.Concat(_205_args, Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(_System.Tuple2, RAST._IType>.create(_210_name, _208_ty))); + } + RAST._IExpr _211_body; + if (_197_isStatic) { + _211_body = (_200_onExpr).FSel(Defs.__default.escapeVar(_195_field)); } else { - _206_body = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("callTarget"))).Sel(Defs.__default.escapeVar(_190_field)); - } - if (_193_isConstant) { - _206_body = (_206_body).Apply0(); - } - Dafny.ISequence _207_onExprArgs; - _207_onExprArgs = Dafny.Sequence.FromElements(); - BigInteger _hi8 = new BigInteger((_200_args).Count); - for (BigInteger _208_i = BigInteger.Zero; _208_i < _hi8; _208_i++) { - _System._ITuple2, RAST._IType> _let_tmp_rhs1 = (_200_args).Select(_208_i); - Dafny.ISequence _209_name = _let_tmp_rhs1.dtor__0; - RAST._IType _210_ty = _let_tmp_rhs1.dtor__1; - RAST._IExpr _211_rIdent; - Defs._IOwnership _212___v106; - Dafny.ISet> _213___v107; - RAST._IExpr _out181; - Defs._IOwnership _out182; - Dafny.ISet> _out183; - (this).GenIdent(_209_name, selfIdent, _199_lEnv, (((!(_193_isConstant)) && ((_210_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out181, out _out182, out _out183); - _211_rIdent = _out181; - _212___v106 = _out182; - _213___v107 = _out183; - _207_onExprArgs = Dafny.Sequence.Concat(_207_onExprArgs, Dafny.Sequence.FromElements(_211_rIdent)); - } - _206_body = (_206_body).Apply(_207_onExprArgs); - r = RAST.Expr.create_Lambda(_201_parameters, Std.Wrappers.Option.create_None(), _206_body); - if (_192_isStatic) { + _211_body = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("callTarget"))).Sel(Defs.__default.escapeVar(_195_field)); + } + if (_198_isConstant) { + _211_body = (_211_body).Apply0(); + } + Dafny.ISequence _212_onExprArgs; + _212_onExprArgs = Dafny.Sequence.FromElements(); + BigInteger _hi10 = new BigInteger((_205_args).Count); + for (BigInteger _213_i = BigInteger.Zero; _213_i < _hi10; _213_i++) { + _System._ITuple2, RAST._IType> _let_tmp_rhs1 = (_205_args).Select(_213_i); + Dafny.ISequence _214_name = _let_tmp_rhs1.dtor__0; + RAST._IType _215_ty = _let_tmp_rhs1.dtor__1; + RAST._IExpr _216_rIdent; + Defs._IOwnership _217___v106; + Dafny.ISet> _218___v107; + RAST._IExpr _out183; + Defs._IOwnership _out184; + Dafny.ISet> _out185; + (this).GenIdent(_214_name, selfIdent, _204_lEnv, (((!(_198_isConstant)) && ((_215_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out183, out _out184, out _out185); + _216_rIdent = _out183; + _217___v106 = _out184; + _218___v107 = _out185; + _212_onExprArgs = Dafny.Sequence.Concat(_212_onExprArgs, Dafny.Sequence.FromElements(_216_rIdent)); + } + _211_body = (_211_body).Apply(_212_onExprArgs); + r = RAST.Expr.create_Lambda(_206_parameters, Std.Wrappers.Option.create_None(), _211_body); + if (_197_isStatic) { } else { - RAST._IExpr _214_target; - if (object.Equals(_196_onOwned, Defs.Ownership.create_OwnershipOwned())) { - _214_target = _195_onExpr; + RAST._IExpr _219_target; + if (object.Equals(_201_onOwned, Defs.Ownership.create_OwnershipOwned())) { + _219_target = _200_onExpr; } else { - _214_target = (_195_onExpr).Clone(); + _219_target = (_200_onExpr).Clone(); } - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("callTarget"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_214_target))).Then(r)); - } - Dafny.ISequence _215_typeShapeArgs; - _215_typeShapeArgs = Dafny.Sequence.FromElements(); - BigInteger _hi9 = new BigInteger((_194_arguments).Count); - for (BigInteger _216_i = BigInteger.Zero; _216_i < _hi9; _216_i++) { - _215_typeShapeArgs = Dafny.Sequence.Concat(_215_typeShapeArgs, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))); - } - RAST._IType _217_typeShape; - _217_typeShape = RAST.Type.create_DynType(RAST.Type.create_FnType(_215_typeShapeArgs, RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_")))); - r = RAST.Expr.create_TypeAscription((RAST.__default.std__rc__Rc__new).Apply1(r), ((RAST.__default.std__rc__Rc).AsType()).Apply(Dafny.Sequence.FromElements(_217_typeShape))); - RAST._IExpr _out184; - Defs._IOwnership _out185; - (this).FromOwned(r, expectedOwnership, out _out184, out _out185); - r = _out184; - resultingOwnership = _out185; - readIdents = _197_recIdents; + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("callTarget"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_219_target))).Then(r)); + } + Dafny.ISequence _220_typeShapeArgs; + _220_typeShapeArgs = Dafny.Sequence.FromElements(); + BigInteger _hi11 = new BigInteger((_199_arguments).Count); + for (BigInteger _221_i = BigInteger.Zero; _221_i < _hi11; _221_i++) { + _220_typeShapeArgs = Dafny.Sequence.Concat(_220_typeShapeArgs, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))); + } + RAST._IType _222_typeShape; + _222_typeShape = RAST.Type.create_DynType(RAST.Type.create_FnType(_220_typeShapeArgs, RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_")))); + r = RAST.Expr.create_TypeAscription((RAST.__default.std__rc__Rc__new).Apply1(r), ((RAST.__default.std__rc__Rc).AsType()).Apply(Dafny.Sequence.FromElements(_222_typeShape))); + RAST._IExpr _out186; + Defs._IOwnership _out187; + (this).FromOwned(r, expectedOwnership, out _out186, out _out187); + r = _out186; + resultingOwnership = _out187; + readIdents = _202_recIdents; return ; } goto after_match0; @@ -5947,46 +5951,46 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Select) { - DAST._IExpression _218_on = _source0.dtor_expr; - Dafny.ISequence _219_field = _source0.dtor_field; - DAST._IFieldMutability _220_fieldMutability = _source0.dtor_fieldMutability; - DAST._ISelectContext _221_selectContext = _source0.dtor_selectContext; - DAST._IType _222_fieldType = _source0.dtor_isfieldType; + DAST._IExpression _223_on = _source0.dtor_expr; + Dafny.ISequence _224_field = _source0.dtor_field; + DAST._IFieldMutability _225_fieldMutability = _source0.dtor_fieldMutability; + DAST._ISelectContext _226_selectContext = _source0.dtor_selectContext; + DAST._IType _227_fieldType = _source0.dtor_isfieldType; { - if (((_218_on).is_Companion) || ((_218_on).is_ExternCompanion)) { - RAST._IExpr _223_onExpr; - Defs._IOwnership _224_onOwned; - Dafny.ISet> _225_recIdents; - RAST._IExpr _out186; - Defs._IOwnership _out187; - Dafny.ISet> _out188; - (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out186, out _out187, out _out188); - _223_onExpr = _out186; - _224_onOwned = _out187; - _225_recIdents = _out188; - r = ((_223_onExpr).FSel(Defs.__default.escapeVar(_219_field))).Apply0(); - RAST._IExpr _out189; - Defs._IOwnership _out190; - (this).FromOwned(r, expectedOwnership, out _out189, out _out190); - r = _out189; - resultingOwnership = _out190; - readIdents = _225_recIdents; - return ; - } else if ((_221_selectContext).is_SelectContextDatatype) { - RAST._IExpr _226_onExpr; - Defs._IOwnership _227_onOwned; - Dafny.ISet> _228_recIdents; + if (((_223_on).is_Companion) || ((_223_on).is_ExternCompanion)) { + RAST._IExpr _228_onExpr; + Defs._IOwnership _229_onOwned; + Dafny.ISet> _230_recIdents; + RAST._IExpr _out188; + Defs._IOwnership _out189; + Dafny.ISet> _out190; + (this).GenExpr(_223_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out188, out _out189, out _out190); + _228_onExpr = _out188; + _229_onOwned = _out189; + _230_recIdents = _out190; + r = ((_228_onExpr).FSel(Defs.__default.escapeVar(_224_field))).Apply0(); RAST._IExpr _out191; Defs._IOwnership _out192; - Dafny.ISet> _out193; - (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out191, out _out192, out _out193); - _226_onExpr = _out191; - _227_onOwned = _out192; - _228_recIdents = _out193; - r = ((_226_onExpr).Sel(Defs.__default.escapeVar(_219_field))).Apply0(); - Defs._IOwnership _229_originalMutability; - _229_originalMutability = Defs.Ownership.create_OwnershipOwned(); - DAST._IFieldMutability _source2 = _220_fieldMutability; + (this).FromOwned(r, expectedOwnership, out _out191, out _out192); + r = _out191; + resultingOwnership = _out192; + readIdents = _230_recIdents; + return ; + } else if ((_226_selectContext).is_SelectContextDatatype) { + RAST._IExpr _231_onExpr; + Defs._IOwnership _232_onOwned; + Dafny.ISet> _233_recIdents; + RAST._IExpr _out193; + Defs._IOwnership _out194; + Dafny.ISet> _out195; + (this).GenExpr(_223_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out193, out _out194, out _out195); + _231_onExpr = _out193; + _232_onOwned = _out194; + _233_recIdents = _out195; + r = ((_231_onExpr).Sel(Defs.__default.escapeVar(_224_field))).Apply0(); + Defs._IOwnership _234_originalMutability; + _234_originalMutability = Defs.Ownership.create_OwnershipOwned(); + DAST._IFieldMutability _source2 = _225_fieldMutability; { if (_source2.is_ConstantField) { goto after_match2; @@ -5994,67 +5998,67 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source2.is_InternalClassConstantFieldOrDatatypeDestructor) { - _229_originalMutability = Defs.Ownership.create_OwnershipBorrowed(); + _234_originalMutability = Defs.Ownership.create_OwnershipBorrowed(); goto after_match2; } } { - RAST._IExpr _out194; - _out194 = (this).Error(Dafny.Sequence.UnicodeFromString("datatypes don't have mutable fields"), (this).InitEmptyExpr()); - r = _out194; + RAST._IExpr _out196; + _out196 = (this).Error(Dafny.Sequence.UnicodeFromString("datatypes don't have mutable fields"), (this).InitEmptyExpr()); + r = _out196; } after_match2: ; - RAST._IType _230_typ; - RAST._IType _out195; - _out195 = (this).GenType(_222_fieldType, Defs.GenTypeContext.@default()); - _230_typ = _out195; - RAST._IExpr _out196; - Defs._IOwnership _out197; - (this).FromOwnership(r, _229_originalMutability, expectedOwnership, out _out196, out _out197); - r = _out196; - resultingOwnership = _out197; - readIdents = _228_recIdents; - } else if ((_221_selectContext).is_SelectContextGeneralTrait) { - Defs._IOwnership _231_onOwned = Defs.Ownership.Default(); - Dafny.ISet> _232_recIdents = Dafny.Set>.Empty; + RAST._IType _235_typ; + RAST._IType _out197; + _out197 = (this).GenType(_227_fieldType, Defs.GenTypeContext.@default()); + _235_typ = _out197; + RAST._IExpr _out198; + Defs._IOwnership _out199; + (this).FromOwnership(r, _234_originalMutability, expectedOwnership, out _out198, out _out199); + r = _out198; + resultingOwnership = _out199; + readIdents = _233_recIdents; + } else if ((_226_selectContext).is_SelectContextGeneralTrait) { + Defs._IOwnership _236_onOwned = Defs.Ownership.Default(); + Dafny.ISet> _237_recIdents = Dafny.Set>.Empty; readIdents = Dafny.Set>.FromElements(); - if ((_218_on).IsThisUpcast()) { + if ((_223_on).IsThisUpcast()) { r = RAST.__default.self; - _232_recIdents = Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self")); + _237_recIdents = Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self")); } else { - RAST._IExpr _out198; - Defs._IOwnership _out199; - Dafny.ISet> _out200; - (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out198, out _out199, out _out200); - r = _out198; - _231_onOwned = _out199; - _232_recIdents = _out200; + RAST._IExpr _out200; + Defs._IOwnership _out201; + Dafny.ISet> _out202; + (this).GenExpr(_223_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out200, out _out201, out _out202); + r = _out200; + _236_onOwned = _out201; + _237_recIdents = _out202; if (!object.Equals(r, RAST.__default.self)) { r = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(r); } } - readIdents = Dafny.Set>.Union(readIdents, _232_recIdents); - r = ((r).Sel(Defs.__default.escapeVar(_219_field))).Apply0(); - RAST._IExpr _out201; - Defs._IOwnership _out202; - (this).FromOwned(r, expectedOwnership, out _out201, out _out202); - r = _out201; - resultingOwnership = _out202; - readIdents = _232_recIdents; - } else { - RAST._IExpr _233_onExpr; - Defs._IOwnership _234_onOwned; - Dafny.ISet> _235_recIdents; + readIdents = Dafny.Set>.Union(readIdents, _237_recIdents); + r = ((r).Sel(Defs.__default.escapeVar(_224_field))).Apply0(); RAST._IExpr _out203; Defs._IOwnership _out204; - Dafny.ISet> _out205; - (this).GenExpr(_218_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out203, out _out204, out _out205); - _233_onExpr = _out203; - _234_onOwned = _out204; - _235_recIdents = _out205; - r = _233_onExpr; - if (!object.Equals(_233_onExpr, RAST.__default.self)) { - RAST._IExpr _source3 = _233_onExpr; + (this).FromOwned(r, expectedOwnership, out _out203, out _out204); + r = _out203; + resultingOwnership = _out204; + readIdents = _237_recIdents; + } else { + RAST._IExpr _238_onExpr; + Defs._IOwnership _239_onOwned; + Dafny.ISet> _240_recIdents; + RAST._IExpr _out205; + Defs._IOwnership _out206; + Dafny.ISet> _out207; + (this).GenExpr(_223_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out205, out _out206, out _out207); + _238_onExpr = _out205; + _239_onOwned = _out206; + _240_recIdents = _out207; + r = _238_onExpr; + if (!object.Equals(_238_onExpr, RAST.__default.self)) { + RAST._IExpr _source3 = _238_onExpr; { if (_source3.is_UnaryOp) { Dafny.ISequence op10 = _source3.dtor_op1; @@ -6078,8 +6082,8 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } r = ((this).read__macro).Apply1(r); } - r = (r).Sel(Defs.__default.escapeVar(_219_field)); - DAST._IFieldMutability _source4 = _220_fieldMutability; + r = (r).Sel(Defs.__default.escapeVar(_224_field)); + DAST._IFieldMutability _source4 = _225_fieldMutability; { if (_source4.is_ConstantField) { r = (r).Apply0(); @@ -6097,12 +6101,12 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir r = ((this).read__mutable__field__macro).Apply1(r); } after_match4: ; - RAST._IExpr _out206; - Defs._IOwnership _out207; - (this).FromOwned(r, expectedOwnership, out _out206, out _out207); - r = _out206; - resultingOwnership = _out207; - readIdents = _235_recIdents; + RAST._IExpr _out208; + Defs._IOwnership _out209; + (this).FromOwned(r, expectedOwnership, out _out208, out _out209); + r = _out208; + resultingOwnership = _out209; + readIdents = _240_recIdents; } return ; } @@ -6111,70 +6115,70 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Index) { - DAST._IExpression _236_on = _source0.dtor_expr; - DAST._ICollKind _237_collKind = _source0.dtor_collKind; - Dafny.ISequence _238_indices = _source0.dtor_indices; + DAST._IExpression _241_on = _source0.dtor_expr; + DAST._ICollKind _242_collKind = _source0.dtor_collKind; + Dafny.ISequence _243_indices = _source0.dtor_indices; { - RAST._IExpr _239_onExpr; - Defs._IOwnership _240_onOwned; - Dafny.ISet> _241_recIdents; - RAST._IExpr _out208; - Defs._IOwnership _out209; - Dafny.ISet> _out210; - (this).GenExpr(_236_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out208, out _out209, out _out210); - _239_onExpr = _out208; - _240_onOwned = _out209; - _241_recIdents = _out210; - readIdents = _241_recIdents; - r = _239_onExpr; - bool _242_hadArray; - _242_hadArray = false; - if (object.Equals(_237_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _244_onExpr; + Defs._IOwnership _245_onOwned; + Dafny.ISet> _246_recIdents; + RAST._IExpr _out210; + Defs._IOwnership _out211; + Dafny.ISet> _out212; + (this).GenExpr(_241_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out210, out _out211, out _out212); + _244_onExpr = _out210; + _245_onOwned = _out211; + _246_recIdents = _out212; + readIdents = _246_recIdents; + r = _244_onExpr; + bool _247_hadArray; + _247_hadArray = false; + if (object.Equals(_242_collKind, DAST.CollKind.create_Array())) { r = ((this).read__macro).Apply1(r); - _242_hadArray = true; - if ((new BigInteger((_238_indices).Count)) > (BigInteger.One)) { + _247_hadArray = true; + if ((new BigInteger((_243_indices).Count)) > (BigInteger.One)) { r = (r).Sel(Dafny.Sequence.UnicodeFromString("data")); } } - BigInteger _hi10 = new BigInteger((_238_indices).Count); - for (BigInteger _243_i = BigInteger.Zero; _243_i < _hi10; _243_i++) { - if (object.Equals(_237_collKind, DAST.CollKind.create_Array())) { - RAST._IExpr _244_idx; - Defs._IOwnership _245_idxOwned; - Dafny.ISet> _246_recIdentsIdx; - RAST._IExpr _out211; - Defs._IOwnership _out212; - Dafny.ISet> _out213; - (this).GenExpr((_238_indices).Select(_243_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out211, out _out212, out _out213); - _244_idx = _out211; - _245_idxOwned = _out212; - _246_recIdentsIdx = _out213; - _244_idx = RAST.__default.IntoUsize(_244_idx); - r = RAST.Expr.create_SelectIndex(r, _244_idx); - readIdents = Dafny.Set>.Union(readIdents, _246_recIdentsIdx); + BigInteger _hi12 = new BigInteger((_243_indices).Count); + for (BigInteger _248_i = BigInteger.Zero; _248_i < _hi12; _248_i++) { + if (object.Equals(_242_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _249_idx; + Defs._IOwnership _250_idxOwned; + Dafny.ISet> _251_recIdentsIdx; + RAST._IExpr _out213; + Defs._IOwnership _out214; + Dafny.ISet> _out215; + (this).GenExpr((_243_indices).Select(_248_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out213, out _out214, out _out215); + _249_idx = _out213; + _250_idxOwned = _out214; + _251_recIdentsIdx = _out215; + _249_idx = RAST.__default.IntoUsize(_249_idx); + r = RAST.Expr.create_SelectIndex(r, _249_idx); + readIdents = Dafny.Set>.Union(readIdents, _251_recIdentsIdx); } else { - RAST._IExpr _247_idx; - Defs._IOwnership _248_idxOwned; - Dafny.ISet> _249_recIdentsIdx; - RAST._IExpr _out214; - Defs._IOwnership _out215; - Dafny.ISet> _out216; - (this).GenExpr((_238_indices).Select(_243_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out214, out _out215, out _out216); - _247_idx = _out214; - _248_idxOwned = _out215; - _249_recIdentsIdx = _out216; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_247_idx); - readIdents = Dafny.Set>.Union(readIdents, _249_recIdentsIdx); + RAST._IExpr _252_idx; + Defs._IOwnership _253_idxOwned; + Dafny.ISet> _254_recIdentsIdx; + RAST._IExpr _out216; + Defs._IOwnership _out217; + Dafny.ISet> _out218; + (this).GenExpr((_243_indices).Select(_248_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out216, out _out217, out _out218); + _252_idx = _out216; + _253_idxOwned = _out217; + _254_recIdentsIdx = _out218; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_252_idx); + readIdents = Dafny.Set>.Union(readIdents, _254_recIdentsIdx); } } - if (_242_hadArray) { + if (_247_hadArray) { r = (r).Clone(); } - RAST._IExpr _out217; - Defs._IOwnership _out218; - (this).FromOwned(r, expectedOwnership, out _out217, out _out218); - r = _out217; - resultingOwnership = _out218; + RAST._IExpr _out219; + Defs._IOwnership _out220; + (this).FromOwned(r, expectedOwnership, out _out219, out _out220); + r = _out219; + resultingOwnership = _out220; return ; } goto after_match0; @@ -6182,63 +6186,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IndexRange) { - DAST._IExpression _250_on = _source0.dtor_expr; - bool _251_isArray = _source0.dtor_isArray; - Std.Wrappers._IOption _252_low = _source0.dtor_low; - Std.Wrappers._IOption _253_high = _source0.dtor_high; + DAST._IExpression _255_on = _source0.dtor_expr; + bool _256_isArray = _source0.dtor_isArray; + Std.Wrappers._IOption _257_low = _source0.dtor_low; + Std.Wrappers._IOption _258_high = _source0.dtor_high; { - Defs._IOwnership _254_onExpectedOwnership; - if (_251_isArray) { + Defs._IOwnership _259_onExpectedOwnership; + if (_256_isArray) { if (((this).pointerType).is_Raw) { - _254_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); + _259_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); } else { - _254_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); + _259_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); } } else { - _254_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); - } - RAST._IExpr _255_onExpr; - Defs._IOwnership _256_onOwned; - Dafny.ISet> _257_recIdents; - RAST._IExpr _out219; - Defs._IOwnership _out220; - Dafny.ISet> _out221; - (this).GenExpr(_250_on, selfIdent, env, _254_onExpectedOwnership, out _out219, out _out220, out _out221); - _255_onExpr = _out219; - _256_onOwned = _out220; - _257_recIdents = _out221; - readIdents = _257_recIdents; - Dafny.ISequence _258_methodName; - if ((_252_low).is_Some) { - if ((_253_high).is_Some) { - _258_methodName = Dafny.Sequence.UnicodeFromString("slice"); + _259_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); + } + RAST._IExpr _260_onExpr; + Defs._IOwnership _261_onOwned; + Dafny.ISet> _262_recIdents; + RAST._IExpr _out221; + Defs._IOwnership _out222; + Dafny.ISet> _out223; + (this).GenExpr(_255_on, selfIdent, env, _259_onExpectedOwnership, out _out221, out _out222, out _out223); + _260_onExpr = _out221; + _261_onOwned = _out222; + _262_recIdents = _out223; + readIdents = _262_recIdents; + Dafny.ISequence _263_methodName; + if ((_257_low).is_Some) { + if ((_258_high).is_Some) { + _263_methodName = Dafny.Sequence.UnicodeFromString("slice"); } else { - _258_methodName = Dafny.Sequence.UnicodeFromString("drop"); + _263_methodName = Dafny.Sequence.UnicodeFromString("drop"); } - } else if ((_253_high).is_Some) { - _258_methodName = Dafny.Sequence.UnicodeFromString("take"); + } else if ((_258_high).is_Some) { + _263_methodName = Dafny.Sequence.UnicodeFromString("take"); } else { - _258_methodName = Dafny.Sequence.UnicodeFromString(""); + _263_methodName = Dafny.Sequence.UnicodeFromString(""); } - Dafny.ISequence _259_arguments; - _259_arguments = Dafny.Sequence.FromElements(); - Std.Wrappers._IOption _source5 = _252_low; + Dafny.ISequence _264_arguments; + _264_arguments = Dafny.Sequence.FromElements(); + Std.Wrappers._IOption _source5 = _257_low; { if (_source5.is_Some) { - DAST._IExpression _260_l = _source5.dtor_value; + DAST._IExpression _265_l = _source5.dtor_value; { - RAST._IExpr _261_lExpr; - Defs._IOwnership _262___v110; - Dafny.ISet> _263_recIdentsL; - RAST._IExpr _out222; - Defs._IOwnership _out223; - Dafny.ISet> _out224; - (this).GenExpr(_260_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out222, out _out223, out _out224); - _261_lExpr = _out222; - _262___v110 = _out223; - _263_recIdentsL = _out224; - _259_arguments = Dafny.Sequence.Concat(_259_arguments, Dafny.Sequence.FromElements(_261_lExpr)); - readIdents = Dafny.Set>.Union(readIdents, _263_recIdentsL); + RAST._IExpr _266_lExpr; + Defs._IOwnership _267___v110; + Dafny.ISet> _268_recIdentsL; + RAST._IExpr _out224; + Defs._IOwnership _out225; + Dafny.ISet> _out226; + (this).GenExpr(_265_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out224, out _out225, out _out226); + _266_lExpr = _out224; + _267___v110 = _out225; + _268_recIdentsL = _out226; + _264_arguments = Dafny.Sequence.Concat(_264_arguments, Dafny.Sequence.FromElements(_266_lExpr)); + readIdents = Dafny.Set>.Union(readIdents, _268_recIdentsL); } goto after_match5; } @@ -6246,23 +6250,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match5: ; - Std.Wrappers._IOption _source6 = _253_high; + Std.Wrappers._IOption _source6 = _258_high; { if (_source6.is_Some) { - DAST._IExpression _264_h = _source6.dtor_value; + DAST._IExpression _269_h = _source6.dtor_value; { - RAST._IExpr _265_hExpr; - Defs._IOwnership _266___v111; - Dafny.ISet> _267_recIdentsH; - RAST._IExpr _out225; - Defs._IOwnership _out226; - Dafny.ISet> _out227; - (this).GenExpr(_264_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out225, out _out226, out _out227); - _265_hExpr = _out225; - _266___v111 = _out226; - _267_recIdentsH = _out227; - _259_arguments = Dafny.Sequence.Concat(_259_arguments, Dafny.Sequence.FromElements(_265_hExpr)); - readIdents = Dafny.Set>.Union(readIdents, _267_recIdentsH); + RAST._IExpr _270_hExpr; + Defs._IOwnership _271___v111; + Dafny.ISet> _272_recIdentsH; + RAST._IExpr _out227; + Defs._IOwnership _out228; + Dafny.ISet> _out229; + (this).GenExpr(_269_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out227, out _out228, out _out229); + _270_hExpr = _out227; + _271___v111 = _out228; + _272_recIdentsH = _out229; + _264_arguments = Dafny.Sequence.Concat(_264_arguments, Dafny.Sequence.FromElements(_270_hExpr)); + readIdents = Dafny.Set>.Union(readIdents, _272_recIdentsH); } goto after_match6; } @@ -6270,30 +6274,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match6: ; - r = _255_onExpr; - if (_251_isArray) { - if (!(_258_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - _258_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _258_methodName); + r = _260_onExpr; + if (_256_isArray) { + if (!(_263_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + _263_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _263_methodName); } - Dafny.ISequence _268_object__suffix; + Dafny.ISequence _273_object__suffix; if (((this).pointerType).is_Raw) { - _268_object__suffix = Dafny.Sequence.UnicodeFromString(""); + _273_object__suffix = Dafny.Sequence.UnicodeFromString(""); } else { - _268_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); + _273_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); } - r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _258_methodName), _268_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_255_onExpr), _259_arguments)); + r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _263_methodName), _273_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_260_onExpr), _264_arguments)); } else { - if (!(_258_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - r = ((r).Sel(_258_methodName)).Apply(_259_arguments); + if (!(_263_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + r = ((r).Sel(_263_methodName)).Apply(_264_arguments); } else { r = (r).Clone(); } } - RAST._IExpr _out228; - Defs._IOwnership _out229; - (this).FromOwned(r, expectedOwnership, out _out228, out _out229); - r = _out228; - resultingOwnership = _out229; + RAST._IExpr _out230; + Defs._IOwnership _out231; + (this).FromOwned(r, expectedOwnership, out _out230, out _out231); + r = _out230; + resultingOwnership = _out231; return ; } goto after_match0; @@ -6301,28 +6305,28 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TupleSelect) { - DAST._IExpression _269_on = _source0.dtor_expr; - BigInteger _270_idx = _source0.dtor_index; - DAST._IType _271_fieldType = _source0.dtor_fieldType; + DAST._IExpression _274_on = _source0.dtor_expr; + BigInteger _275_idx = _source0.dtor_index; + DAST._IType _276_fieldType = _source0.dtor_fieldType; { - RAST._IExpr _272_onExpr; - Defs._IOwnership _273_onOwnership; - Dafny.ISet> _274_recIdents; - RAST._IExpr _out230; - Defs._IOwnership _out231; - Dafny.ISet> _out232; - (this).GenExpr(_269_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out230, out _out231, out _out232); - _272_onExpr = _out230; - _273_onOwnership = _out231; - _274_recIdents = _out232; - Dafny.ISequence _275_selName; - _275_selName = Std.Strings.__default.OfNat(_270_idx); - DAST._IType _source7 = _271_fieldType; + RAST._IExpr _277_onExpr; + Defs._IOwnership _278_onOwnership; + Dafny.ISet> _279_recIdents; + RAST._IExpr _out232; + Defs._IOwnership _out233; + Dafny.ISet> _out234; + (this).GenExpr(_274_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out232, out _out233, out _out234); + _277_onExpr = _out232; + _278_onOwnership = _out233; + _279_recIdents = _out234; + Dafny.ISequence _280_selName; + _280_selName = Std.Strings.__default.OfNat(_275_idx); + DAST._IType _source7 = _276_fieldType; { if (_source7.is_Tuple) { - Dafny.ISequence _276_tps = _source7.dtor_Tuple_a0; - if (((_271_fieldType).is_Tuple) && ((new BigInteger((_276_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { - _275_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _275_selName); + Dafny.ISequence _281_tps = _source7.dtor_Tuple_a0; + if (((_276_fieldType).is_Tuple) && ((new BigInteger((_281_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { + _280_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _280_selName); } goto after_match7; } @@ -6330,13 +6334,13 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match7: ; - r = ((_272_onExpr).Sel(_275_selName)).Clone(); - RAST._IExpr _out233; - Defs._IOwnership _out234; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out233, out _out234); - r = _out233; - resultingOwnership = _out234; - readIdents = _274_recIdents; + r = ((_277_onExpr).Sel(_280_selName)).Clone(); + RAST._IExpr _out235; + Defs._IOwnership _out236; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out235, out _out236); + r = _out235; + resultingOwnership = _out236; + readIdents = _279_recIdents; return ; } goto after_match0; @@ -6344,21 +6348,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Call) { - DAST._IExpression _277_on = _source0.dtor_on; - DAST._ICallName _278_name = _source0.dtor_callName; - Dafny.ISequence _279_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _280_args = _source0.dtor_args; + DAST._IExpression _282_on = _source0.dtor_on; + DAST._ICallName _283_name = _source0.dtor_callName; + Dafny.ISequence _284_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _285_args = _source0.dtor_args; { - RAST._IExpr _out235; - Dafny.ISet> _out236; - (this).GenOwnedCallPart(_277_on, selfIdent, _278_name, _279_typeArgs, _280_args, env, out _out235, out _out236); - r = _out235; - readIdents = _out236; RAST._IExpr _out237; - Defs._IOwnership _out238; - (this).FromOwned(r, expectedOwnership, out _out237, out _out238); + Dafny.ISet> _out238; + (this).GenOwnedCallPart(_282_on, selfIdent, _283_name, _284_typeArgs, _285_args, env, out _out237, out _out238); r = _out237; - resultingOwnership = _out238; + readIdents = _out238; + RAST._IExpr _out239; + Defs._IOwnership _out240; + (this).FromOwned(r, expectedOwnership, out _out239, out _out240); + r = _out239; + resultingOwnership = _out240; return ; } goto after_match0; @@ -6366,90 +6370,90 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Lambda) { - Dafny.ISequence _281_paramsDafny = _source0.dtor_params; - DAST._IType _282_retType = _source0.dtor_retType; - Dafny.ISequence _283_body = _source0.dtor_body; + Dafny.ISequence _286_paramsDafny = _source0.dtor_params; + DAST._IType _287_retType = _source0.dtor_retType; + Dafny.ISequence _288_body = _source0.dtor_body; { - Dafny.ISequence _284_params; - Dafny.ISequence _out239; - _out239 = (this).GenParams(_281_paramsDafny, _281_paramsDafny, true); - _284_params = _out239; - Dafny.ISequence> _285_paramNames; - _285_paramNames = Dafny.Sequence>.FromElements(); - Dafny.IMap,RAST._IType> _286_paramTypesMap; - _286_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); - BigInteger _hi11 = new BigInteger((_284_params).Count); - for (BigInteger _287_i = BigInteger.Zero; _287_i < _hi11; _287_i++) { - Dafny.ISequence _288_name; - _288_name = ((_284_params).Select(_287_i)).dtor_name; - _285_paramNames = Dafny.Sequence>.Concat(_285_paramNames, Dafny.Sequence>.FromElements(_288_name)); - _286_paramTypesMap = Dafny.Map, RAST._IType>.Update(_286_paramTypesMap, _288_name, ((_284_params).Select(_287_i)).dtor_tpe); - } - Defs._IEnvironment _289_subEnv; - _289_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_285_paramNames, _286_paramTypesMap, Dafny.Set>.FromElements())); - RAST._IExpr _290_recursiveGen; - Dafny.ISet> _291_recIdents; - Defs._IEnvironment _292___v113; - RAST._IExpr _out240; - Dafny.ISet> _out241; - Defs._IEnvironment _out242; - (this).GenStmts(_283_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _289_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out240, out _out241, out _out242); - _290_recursiveGen = _out240; - _291_recIdents = _out241; - _292___v113 = _out242; + Dafny.ISequence _289_params; + Dafny.ISequence _out241; + _out241 = (this).GenParams(_286_paramsDafny, _286_paramsDafny, true); + _289_params = _out241; + Dafny.ISequence> _290_paramNames; + _290_paramNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _291_paramTypesMap; + _291_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); + BigInteger _hi13 = new BigInteger((_289_params).Count); + for (BigInteger _292_i = BigInteger.Zero; _292_i < _hi13; _292_i++) { + Dafny.ISequence _293_name; + _293_name = ((_289_params).Select(_292_i)).dtor_name; + _290_paramNames = Dafny.Sequence>.Concat(_290_paramNames, Dafny.Sequence>.FromElements(_293_name)); + _291_paramTypesMap = Dafny.Map, RAST._IType>.Update(_291_paramTypesMap, _293_name, ((_289_params).Select(_292_i)).dtor_tpe); + } + Defs._IEnvironment _294_subEnv; + _294_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_290_paramNames, _291_paramTypesMap, Dafny.Set>.FromElements())); + RAST._IExpr _295_recursiveGen; + Dafny.ISet> _296_recIdents; + Defs._IEnvironment _297___v113; + RAST._IExpr _out242; + Dafny.ISet> _out243; + Defs._IEnvironment _out244; + (this).GenStmts(_288_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _294_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out242, out _out243, out _out244); + _295_recursiveGen = _out242; + _296_recIdents = _out243; + _297___v113 = _out244; readIdents = Dafny.Set>.FromElements(); - _291_recIdents = Dafny.Set>.Difference(_291_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_293_paramNames) => ((System.Func>>)(() => { + _296_recIdents = Dafny.Set>.Difference(_296_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_298_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); - foreach (Dafny.ISequence _compr_0 in (_293_paramNames).CloneAsArray()) { - Dafny.ISequence _294_name = (Dafny.ISequence)_compr_0; - if ((_293_paramNames).Contains(_294_name)) { - _coll0.Add(_294_name); + foreach (Dafny.ISequence _compr_0 in (_298_paramNames).CloneAsArray()) { + Dafny.ISequence _299_name = (Dafny.ISequence)_compr_0; + if ((_298_paramNames).Contains(_299_name)) { + _coll0.Add(_299_name); } } return Dafny.Set>.FromCollection(_coll0); - }))())(_285_paramNames)); - RAST._IExpr _295_allReadCloned; - _295_allReadCloned = (this).InitEmptyExpr(); - while (!(_291_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _296_next; - foreach (Dafny.ISequence _assign_such_that_1 in (_291_recIdents).Elements) { - _296_next = (Dafny.ISequence)_assign_such_that_1; - if ((_291_recIdents).Contains(_296_next)) { + }))())(_290_paramNames)); + RAST._IExpr _300_allReadCloned; + _300_allReadCloned = (this).InitEmptyExpr(); + while (!(_296_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _301_next; + foreach (Dafny.ISequence _assign_such_that_1 in (_296_recIdents).Elements) { + _301_next = (Dafny.ISequence)_assign_such_that_1; + if ((_296_recIdents).Contains(_301_next)) { goto after__ASSIGN_SUCH_THAT_1; } } throw new System.Exception("assign-such-that search produced no value"); after__ASSIGN_SUCH_THAT_1: ; - if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_296_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { - RAST._IExpr _297_selfCloned; - Defs._IOwnership _298___v114; - Dafny.ISet> _299___v115; - RAST._IExpr _out243; - Defs._IOwnership _out244; - Dafny.ISet> _out245; - (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out243, out _out244, out _out245); - _297_selfCloned = _out243; - _298___v114 = _out244; - _299___v115 = _out245; - _295_allReadCloned = (_295_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_297_selfCloned))); - } else if (!((_285_paramNames).Contains(_296_next))) { - RAST._IExpr _300_copy; - _300_copy = (RAST.Expr.create_Identifier(_296_next)).Clone(); - _295_allReadCloned = (_295_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _296_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_300_copy))); - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_296_next)); + if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_301_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { + RAST._IExpr _302_selfCloned; + Defs._IOwnership _303___v114; + Dafny.ISet> _304___v115; + RAST._IExpr _out245; + Defs._IOwnership _out246; + Dafny.ISet> _out247; + (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out245, out _out246, out _out247); + _302_selfCloned = _out245; + _303___v114 = _out246; + _304___v115 = _out247; + _300_allReadCloned = (_300_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_302_selfCloned))); + } else if (!((_290_paramNames).Contains(_301_next))) { + RAST._IExpr _305_copy; + _305_copy = (RAST.Expr.create_Identifier(_301_next)).Clone(); + _300_allReadCloned = (_300_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _301_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_305_copy))); + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_301_next)); } - _291_recIdents = Dafny.Set>.Difference(_291_recIdents, Dafny.Set>.FromElements(_296_next)); - } - RAST._IType _301_retTypeGen; - RAST._IType _out246; - _out246 = (this).GenType(_282_retType, Defs.GenTypeContext.@default()); - _301_retTypeGen = _out246; - r = RAST.Expr.create_Block((_295_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_284_params, Std.Wrappers.Option.create_Some(_301_retTypeGen), RAST.Expr.create_Block(_290_recursiveGen))))); - RAST._IExpr _out247; - Defs._IOwnership _out248; - (this).FromOwned(r, expectedOwnership, out _out247, out _out248); - r = _out247; - resultingOwnership = _out248; + _296_recIdents = Dafny.Set>.Difference(_296_recIdents, Dafny.Set>.FromElements(_301_next)); + } + RAST._IType _306_retTypeGen; + RAST._IType _out248; + _out248 = (this).GenType(_287_retType, Defs.GenTypeContext.@default()); + _306_retTypeGen = _out248; + r = RAST.Expr.create_Block((_300_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_289_params, Std.Wrappers.Option.create_Some(_306_retTypeGen), RAST.Expr.create_Block(_295_recursiveGen))))); + RAST._IExpr _out249; + Defs._IOwnership _out250; + (this).FromOwned(r, expectedOwnership, out _out249, out _out250); + r = _out249; + resultingOwnership = _out250; return ; } goto after_match0; @@ -6457,74 +6461,74 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_BetaRedex) { - Dafny.ISequence<_System._ITuple2> _302_values = _source0.dtor_values; - DAST._IType _303_retType = _source0.dtor_retType; - DAST._IExpression _304_expr = _source0.dtor_expr; + Dafny.ISequence<_System._ITuple2> _307_values = _source0.dtor_values; + DAST._IType _308_retType = _source0.dtor_retType; + DAST._IExpression _309_expr = _source0.dtor_expr; { - Dafny.ISequence> _305_paramNames; - _305_paramNames = Dafny.Sequence>.FromElements(); - Dafny.ISequence _306_paramFormals; - Dafny.ISequence _out249; - _out249 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_307_value) => { - return (_307_value).dtor__0; - })), _302_values), Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_307_value) => { - return (_307_value).dtor__0; - })), _302_values), false); - _306_paramFormals = _out249; - Dafny.IMap,RAST._IType> _308_paramTypes; - _308_paramTypes = Dafny.Map, RAST._IType>.FromElements(); - Dafny.ISet> _309_paramNamesSet; - _309_paramNamesSet = Dafny.Set>.FromElements(); - BigInteger _hi12 = new BigInteger((_302_values).Count); - for (BigInteger _310_i = BigInteger.Zero; _310_i < _hi12; _310_i++) { - Dafny.ISequence _311_name; - _311_name = (((_302_values).Select(_310_i)).dtor__0).dtor_name; - Dafny.ISequence _312_rName; - _312_rName = Defs.__default.escapeVar(_311_name); - _305_paramNames = Dafny.Sequence>.Concat(_305_paramNames, Dafny.Sequence>.FromElements(_312_rName)); - _308_paramTypes = Dafny.Map, RAST._IType>.Update(_308_paramTypes, _312_rName, ((_306_paramFormals).Select(_310_i)).dtor_tpe); - _309_paramNamesSet = Dafny.Set>.Union(_309_paramNamesSet, Dafny.Set>.FromElements(_312_rName)); + Dafny.ISequence> _310_paramNames; + _310_paramNames = Dafny.Sequence>.FromElements(); + Dafny.ISequence _311_paramFormals; + Dafny.ISequence _out251; + _out251 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_312_value) => { + return (_312_value).dtor__0; + })), _307_values), Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_312_value) => { + return (_312_value).dtor__0; + })), _307_values), false); + _311_paramFormals = _out251; + Dafny.IMap,RAST._IType> _313_paramTypes; + _313_paramTypes = Dafny.Map, RAST._IType>.FromElements(); + Dafny.ISet> _314_paramNamesSet; + _314_paramNamesSet = Dafny.Set>.FromElements(); + BigInteger _hi14 = new BigInteger((_307_values).Count); + for (BigInteger _315_i = BigInteger.Zero; _315_i < _hi14; _315_i++) { + Dafny.ISequence _316_name; + _316_name = (((_307_values).Select(_315_i)).dtor__0).dtor_name; + Dafny.ISequence _317_rName; + _317_rName = Defs.__default.escapeVar(_316_name); + _310_paramNames = Dafny.Sequence>.Concat(_310_paramNames, Dafny.Sequence>.FromElements(_317_rName)); + _313_paramTypes = Dafny.Map, RAST._IType>.Update(_313_paramTypes, _317_rName, ((_311_paramFormals).Select(_315_i)).dtor_tpe); + _314_paramNamesSet = Dafny.Set>.Union(_314_paramNamesSet, Dafny.Set>.FromElements(_317_rName)); } readIdents = Dafny.Set>.FromElements(); r = (this).InitEmptyExpr(); - BigInteger _hi13 = new BigInteger((_302_values).Count); - for (BigInteger _313_i = BigInteger.Zero; _313_i < _hi13; _313_i++) { - RAST._IType _314_typeGen; - RAST._IType _out250; - _out250 = (this).GenType((((_302_values).Select(_313_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); - _314_typeGen = _out250; - RAST._IExpr _315_valueGen; - Defs._IOwnership _316___v116; - Dafny.ISet> _317_recIdents; - RAST._IExpr _out251; - Defs._IOwnership _out252; - Dafny.ISet> _out253; - (this).GenExpr(((_302_values).Select(_313_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out251, out _out252, out _out253); - _315_valueGen = _out251; - _316___v116 = _out252; - _317_recIdents = _out253; - r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_302_values).Select(_313_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_314_typeGen), Std.Wrappers.Option.create_Some(_315_valueGen))); - readIdents = Dafny.Set>.Union(readIdents, _317_recIdents); - } - Defs._IEnvironment _318_newEnv; - _318_newEnv = Defs.Environment.create(_305_paramNames, _308_paramTypes, Dafny.Set>.FromElements()); - RAST._IExpr _319_recGen; - Defs._IOwnership _320_recOwned; - Dafny.ISet> _321_recIdents; - RAST._IExpr _out254; - Defs._IOwnership _out255; - Dafny.ISet> _out256; - (this).GenExpr(_304_expr, selfIdent, _318_newEnv, expectedOwnership, out _out254, out _out255, out _out256); - _319_recGen = _out254; - _320_recOwned = _out255; - _321_recIdents = _out256; - readIdents = Dafny.Set>.Difference(_321_recIdents, _309_paramNamesSet); - r = RAST.Expr.create_Block((r).Then(_319_recGen)); - RAST._IExpr _out257; - Defs._IOwnership _out258; - (this).FromOwnership(r, _320_recOwned, expectedOwnership, out _out257, out _out258); - r = _out257; - resultingOwnership = _out258; + BigInteger _hi15 = new BigInteger((_307_values).Count); + for (BigInteger _318_i = BigInteger.Zero; _318_i < _hi15; _318_i++) { + RAST._IType _319_typeGen; + RAST._IType _out252; + _out252 = (this).GenType((((_307_values).Select(_318_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); + _319_typeGen = _out252; + RAST._IExpr _320_valueGen; + Defs._IOwnership _321___v116; + Dafny.ISet> _322_recIdents; + RAST._IExpr _out253; + Defs._IOwnership _out254; + Dafny.ISet> _out255; + (this).GenExpr(((_307_values).Select(_318_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out253, out _out254, out _out255); + _320_valueGen = _out253; + _321___v116 = _out254; + _322_recIdents = _out255; + r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_307_values).Select(_318_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_319_typeGen), Std.Wrappers.Option.create_Some(_320_valueGen))); + readIdents = Dafny.Set>.Union(readIdents, _322_recIdents); + } + Defs._IEnvironment _323_newEnv; + _323_newEnv = Defs.Environment.create(_310_paramNames, _313_paramTypes, Dafny.Set>.FromElements()); + RAST._IExpr _324_recGen; + Defs._IOwnership _325_recOwned; + Dafny.ISet> _326_recIdents; + RAST._IExpr _out256; + Defs._IOwnership _out257; + Dafny.ISet> _out258; + (this).GenExpr(_309_expr, selfIdent, _323_newEnv, expectedOwnership, out _out256, out _out257, out _out258); + _324_recGen = _out256; + _325_recOwned = _out257; + _326_recIdents = _out258; + readIdents = Dafny.Set>.Difference(_326_recIdents, _314_paramNamesSet); + r = RAST.Expr.create_Block((r).Then(_324_recGen)); + RAST._IExpr _out259; + Defs._IOwnership _out260; + (this).FromOwnership(r, _325_recOwned, expectedOwnership, out _out259, out _out260); + r = _out259; + resultingOwnership = _out260; return ; } goto after_match0; @@ -6532,45 +6536,45 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IIFE) { - Dafny.ISequence _322_name = _source0.dtor_ident; - DAST._IType _323_tpe = _source0.dtor_typ; - DAST._IExpression _324_value = _source0.dtor_value; - DAST._IExpression _325_iifeBody = _source0.dtor_iifeBody; + Dafny.ISequence _327_name = _source0.dtor_ident; + DAST._IType _328_tpe = _source0.dtor_typ; + DAST._IExpression _329_value = _source0.dtor_value; + DAST._IExpression _330_iifeBody = _source0.dtor_iifeBody; { - RAST._IExpr _326_valueGen; - Defs._IOwnership _327___v117; - Dafny.ISet> _328_recIdents; - RAST._IExpr _out259; - Defs._IOwnership _out260; - Dafny.ISet> _out261; - (this).GenExpr(_324_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out259, out _out260, out _out261); - _326_valueGen = _out259; - _327___v117 = _out260; - _328_recIdents = _out261; - readIdents = _328_recIdents; - RAST._IType _329_valueTypeGen; - RAST._IType _out262; - _out262 = (this).GenType(_323_tpe, Defs.GenTypeContext.@default()); - _329_valueTypeGen = _out262; - Dafny.ISequence _330_iifeVar; - _330_iifeVar = Defs.__default.escapeVar(_322_name); - RAST._IExpr _331_bodyGen; - Defs._IOwnership _332___v118; - Dafny.ISet> _333_bodyIdents; - RAST._IExpr _out263; - Defs._IOwnership _out264; - Dafny.ISet> _out265; - (this).GenExpr(_325_iifeBody, selfIdent, (env).AddAssigned(_330_iifeVar, _329_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out263, out _out264, out _out265); - _331_bodyGen = _out263; - _332___v118 = _out264; - _333_bodyIdents = _out265; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_333_bodyIdents, Dafny.Set>.FromElements(_330_iifeVar))); - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _330_iifeVar, Std.Wrappers.Option.create_Some(_329_valueTypeGen), Std.Wrappers.Option.create_Some(_326_valueGen))).Then(_331_bodyGen)); - RAST._IExpr _out266; - Defs._IOwnership _out267; - (this).FromOwned(r, expectedOwnership, out _out266, out _out267); - r = _out266; - resultingOwnership = _out267; + RAST._IExpr _331_valueGen; + Defs._IOwnership _332___v117; + Dafny.ISet> _333_recIdents; + RAST._IExpr _out261; + Defs._IOwnership _out262; + Dafny.ISet> _out263; + (this).GenExpr(_329_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out261, out _out262, out _out263); + _331_valueGen = _out261; + _332___v117 = _out262; + _333_recIdents = _out263; + readIdents = _333_recIdents; + RAST._IType _334_valueTypeGen; + RAST._IType _out264; + _out264 = (this).GenType(_328_tpe, Defs.GenTypeContext.@default()); + _334_valueTypeGen = _out264; + Dafny.ISequence _335_iifeVar; + _335_iifeVar = Defs.__default.escapeVar(_327_name); + RAST._IExpr _336_bodyGen; + Defs._IOwnership _337___v118; + Dafny.ISet> _338_bodyIdents; + RAST._IExpr _out265; + Defs._IOwnership _out266; + Dafny.ISet> _out267; + (this).GenExpr(_330_iifeBody, selfIdent, (env).AddAssigned(_335_iifeVar, _334_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out265, out _out266, out _out267); + _336_bodyGen = _out265; + _337___v118 = _out266; + _338_bodyIdents = _out267; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_338_bodyIdents, Dafny.Set>.FromElements(_335_iifeVar))); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _335_iifeVar, Std.Wrappers.Option.create_Some(_334_valueTypeGen), Std.Wrappers.Option.create_Some(_331_valueGen))).Then(_336_bodyGen)); + RAST._IExpr _out268; + Defs._IOwnership _out269; + (this).FromOwned(r, expectedOwnership, out _out268, out _out269); + r = _out268; + resultingOwnership = _out269; return ; } goto after_match0; @@ -6578,43 +6582,43 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Apply) { - DAST._IExpression _334_func = _source0.dtor_expr; - Dafny.ISequence _335_args = _source0.dtor_args; + DAST._IExpression _339_func = _source0.dtor_expr; + Dafny.ISequence _340_args = _source0.dtor_args; { - RAST._IExpr _336_funcExpr; - Defs._IOwnership _337___v119; - Dafny.ISet> _338_recIdents; - RAST._IExpr _out268; - Defs._IOwnership _out269; - Dafny.ISet> _out270; - (this).GenExpr(_334_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out268, out _out269, out _out270); - _336_funcExpr = _out268; - _337___v119 = _out269; - _338_recIdents = _out270; - readIdents = _338_recIdents; - Dafny.ISequence _339_rArgs; - _339_rArgs = Dafny.Sequence.FromElements(); - BigInteger _hi14 = new BigInteger((_335_args).Count); - for (BigInteger _340_i = BigInteger.Zero; _340_i < _hi14; _340_i++) { - RAST._IExpr _341_argExpr; - Defs._IOwnership _342_argOwned; - Dafny.ISet> _343_argIdents; - RAST._IExpr _out271; - Defs._IOwnership _out272; - Dafny.ISet> _out273; - (this).GenExpr((_335_args).Select(_340_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out271, out _out272, out _out273); - _341_argExpr = _out271; - _342_argOwned = _out272; - _343_argIdents = _out273; - _339_rArgs = Dafny.Sequence.Concat(_339_rArgs, Dafny.Sequence.FromElements(_341_argExpr)); - readIdents = Dafny.Set>.Union(readIdents, _343_argIdents); - } - r = (_336_funcExpr).Apply(_339_rArgs); - RAST._IExpr _out274; - Defs._IOwnership _out275; - (this).FromOwned(r, expectedOwnership, out _out274, out _out275); - r = _out274; - resultingOwnership = _out275; + RAST._IExpr _341_funcExpr; + Defs._IOwnership _342___v119; + Dafny.ISet> _343_recIdents; + RAST._IExpr _out270; + Defs._IOwnership _out271; + Dafny.ISet> _out272; + (this).GenExpr(_339_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out270, out _out271, out _out272); + _341_funcExpr = _out270; + _342___v119 = _out271; + _343_recIdents = _out272; + readIdents = _343_recIdents; + Dafny.ISequence _344_rArgs; + _344_rArgs = Dafny.Sequence.FromElements(); + BigInteger _hi16 = new BigInteger((_340_args).Count); + for (BigInteger _345_i = BigInteger.Zero; _345_i < _hi16; _345_i++) { + RAST._IExpr _346_argExpr; + Defs._IOwnership _347_argOwned; + Dafny.ISet> _348_argIdents; + RAST._IExpr _out273; + Defs._IOwnership _out274; + Dafny.ISet> _out275; + (this).GenExpr((_340_args).Select(_345_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out273, out _out274, out _out275); + _346_argExpr = _out273; + _347_argOwned = _out274; + _348_argIdents = _out275; + _344_rArgs = Dafny.Sequence.Concat(_344_rArgs, Dafny.Sequence.FromElements(_346_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _348_argIdents); + } + r = (_341_funcExpr).Apply(_344_rArgs); + RAST._IExpr _out276; + Defs._IOwnership _out277; + (this).FromOwned(r, expectedOwnership, out _out276, out _out277); + r = _out276; + resultingOwnership = _out277; return ; } goto after_match0; @@ -6622,31 +6626,31 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TypeTest) { - DAST._IExpression _344_on = _source0.dtor_on; - Dafny.ISequence> _345_dType = _source0.dtor_dType; - Dafny.ISequence _346_variant = _source0.dtor_variant; + DAST._IExpression _349_on = _source0.dtor_on; + Dafny.ISequence> _350_dType = _source0.dtor_dType; + Dafny.ISequence _351_variant = _source0.dtor_variant; { - RAST._IExpr _347_exprGen; - Defs._IOwnership _348___v120; - Dafny.ISet> _349_recIdents; - RAST._IExpr _out276; - Defs._IOwnership _out277; - Dafny.ISet> _out278; - (this).GenExpr(_344_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out276, out _out277, out _out278); - _347_exprGen = _out276; - _348___v120 = _out277; - _349_recIdents = _out278; - RAST._IExpr _350_variantExprPath; - RAST._IExpr _out279; - _out279 = (this).GenPathExpr(Dafny.Sequence>.Concat(_345_dType, Dafny.Sequence>.FromElements(_346_variant)), true); - _350_variantExprPath = _out279; - r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_347_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _350_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); - RAST._IExpr _out280; - Defs._IOwnership _out281; - (this).FromOwned(r, expectedOwnership, out _out280, out _out281); - r = _out280; - resultingOwnership = _out281; - readIdents = _349_recIdents; + RAST._IExpr _352_exprGen; + Defs._IOwnership _353___v120; + Dafny.ISet> _354_recIdents; + RAST._IExpr _out278; + Defs._IOwnership _out279; + Dafny.ISet> _out280; + (this).GenExpr(_349_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out278, out _out279, out _out280); + _352_exprGen = _out278; + _353___v120 = _out279; + _354_recIdents = _out280; + RAST._IExpr _355_variantExprPath; + RAST._IExpr _out281; + _out281 = (this).GenPathExpr(Dafny.Sequence>.Concat(_350_dType, Dafny.Sequence>.FromElements(_351_variant)), true); + _355_variantExprPath = _out281; + r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_352_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _355_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); + RAST._IExpr _out282; + Defs._IOwnership _out283; + (this).FromOwned(r, expectedOwnership, out _out282, out _out283); + r = _out282; + resultingOwnership = _out283; + readIdents = _354_recIdents; return ; } goto after_match0; @@ -6654,95 +6658,95 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Is) { - DAST._IExpression _351_expr = _source0.dtor_expr; - DAST._IType _352_fromTyp = _source0.dtor_fromType; - DAST._IType _353_toTyp = _source0.dtor_toType; + DAST._IExpression _356_expr = _source0.dtor_expr; + DAST._IType _357_fromTyp = _source0.dtor_fromType; + DAST._IType _358_toTyp = _source0.dtor_toType; { - RAST._IType _354_fromTpe; - RAST._IType _out282; - _out282 = (this).GenType(_352_fromTyp, Defs.GenTypeContext.@default()); - _354_fromTpe = _out282; - RAST._IType _355_toTpe; - RAST._IType _out283; - _out283 = (this).GenType(_353_toTyp, Defs.GenTypeContext.@default()); - _355_toTpe = _out283; - if (((_354_fromTpe).IsObjectOrPointer()) && ((_355_toTpe).IsObjectOrPointer())) { - RAST._IExpr _356_expr; - Defs._IOwnership _357_recOwned; - Dafny.ISet> _358_recIdents; - RAST._IExpr _out284; - Defs._IOwnership _out285; - Dafny.ISet> _out286; - (this).GenExpr(_351_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out284, out _out285, out _out286); - _356_expr = _out284; - _357_recOwned = _out285; - _358_recIdents = _out286; - r = (((_356_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_355_toTpe).ObjectOrPointerUnderlying()))).Apply0(); - RAST._IExpr _out287; - Defs._IOwnership _out288; - (this).FromOwnership(r, _357_recOwned, expectedOwnership, out _out287, out _out288); - r = _out287; - resultingOwnership = _out288; - readIdents = _358_recIdents; - } else { - RAST._IExpr _359_expr; - Defs._IOwnership _360_recOwned; - Dafny.ISet> _361_recIdents; + RAST._IType _359_fromTpe; + RAST._IType _out284; + _out284 = (this).GenType(_357_fromTyp, Defs.GenTypeContext.@default()); + _359_fromTpe = _out284; + RAST._IType _360_toTpe; + RAST._IType _out285; + _out285 = (this).GenType(_358_toTyp, Defs.GenTypeContext.@default()); + _360_toTpe = _out285; + if (((_359_fromTpe).IsObjectOrPointer()) && ((_360_toTpe).IsObjectOrPointer())) { + RAST._IExpr _361_expr; + Defs._IOwnership _362_recOwned; + Dafny.ISet> _363_recIdents; + RAST._IExpr _out286; + Defs._IOwnership _out287; + Dafny.ISet> _out288; + (this).GenExpr(_356_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out286, out _out287, out _out288); + _361_expr = _out286; + _362_recOwned = _out287; + _363_recIdents = _out288; + r = (((_361_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_360_toTpe).ObjectOrPointerUnderlying()))).Apply0(); RAST._IExpr _out289; Defs._IOwnership _out290; - Dafny.ISet> _out291; - (this).GenExpr(_351_expr, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out289, out _out290, out _out291); - _359_expr = _out289; - _360_recOwned = _out290; - _361_recIdents = _out291; - bool _362_isDatatype; - _362_isDatatype = (_353_toTyp).IsDatatype(); - bool _363_isGeneralTrait; - _363_isGeneralTrait = (!(_362_isDatatype)) && ((_353_toTyp).IsGeneralTrait()); - if ((_362_isDatatype) || (_363_isGeneralTrait)) { - bool _364_isDowncast; - _364_isDowncast = (_353_toTyp).Extends(_352_fromTyp); - if (_364_isDowncast) { - DAST._IType _365_underlyingType; - if (_362_isDatatype) { - _365_underlyingType = (_353_toTyp).GetDatatypeType(); + (this).FromOwnership(r, _362_recOwned, expectedOwnership, out _out289, out _out290); + r = _out289; + resultingOwnership = _out290; + readIdents = _363_recIdents; + } else { + RAST._IExpr _364_expr; + Defs._IOwnership _365_recOwned; + Dafny.ISet> _366_recIdents; + RAST._IExpr _out291; + Defs._IOwnership _out292; + Dafny.ISet> _out293; + (this).GenExpr(_356_expr, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out291, out _out292, out _out293); + _364_expr = _out291; + _365_recOwned = _out292; + _366_recIdents = _out293; + bool _367_isDatatype; + _367_isDatatype = (_358_toTyp).IsDatatype(); + bool _368_isGeneralTrait; + _368_isGeneralTrait = (!(_367_isDatatype)) && ((_358_toTyp).IsGeneralTrait()); + if ((_367_isDatatype) || (_368_isGeneralTrait)) { + bool _369_isDowncast; + _369_isDowncast = (_358_toTyp).Extends(_357_fromTyp); + if (_369_isDowncast) { + DAST._IType _370_underlyingType; + if (_367_isDatatype) { + _370_underlyingType = (_358_toTyp).GetDatatypeType(); } else { - _365_underlyingType = (_353_toTyp).GetGeneralTraitType(); + _370_underlyingType = (_358_toTyp).GetGeneralTraitType(); } - RAST._IType _366_toTpeRaw; - RAST._IType _out292; - _out292 = (this).GenType(_365_underlyingType, Defs.GenTypeContext.@default()); - _366_toTpeRaw = _out292; - Std.Wrappers._IOption _367_toTpeRawDowncastOpt; - _367_toTpeRawDowncastOpt = (_366_toTpeRaw).ToDowncastExpr(); - if ((_367_toTpeRawDowncastOpt).is_Some) { - _359_expr = (this).FromGeneralBorrowToSelfBorrow(_359_expr, Defs.Ownership.create_OwnershipBorrowed(), env); - if (_362_isDatatype) { - _359_expr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_359_expr); + RAST._IType _371_toTpeRaw; + RAST._IType _out294; + _out294 = (this).GenType(_370_underlyingType, Defs.GenTypeContext.@default()); + _371_toTpeRaw = _out294; + Std.Wrappers._IOption _372_toTpeRawDowncastOpt; + _372_toTpeRawDowncastOpt = (_371_toTpeRaw).ToDowncastExpr(); + if ((_372_toTpeRawDowncastOpt).is_Some) { + _364_expr = (this).FromGeneralBorrowToSelfBorrow(_364_expr, Defs.Ownership.create_OwnershipBorrowed(), env); + if (_367_isDatatype) { + _364_expr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_364_expr); } - r = (((_367_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_359_expr); - _360_recOwned = Defs.Ownership.create_OwnershipOwned(); + r = (((_372_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_364_expr); + _365_recOwned = Defs.Ownership.create_OwnershipOwned(); } else { - RAST._IExpr _out293; - _out293 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_366_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); - r = _out293; + RAST._IExpr _out295; + _out295 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_371_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); + r = _out295; } } else { - RAST._IExpr _out294; - _out294 = (this).Error(Dafny.Sequence.UnicodeFromString("Needs support for upcasting general traits"), (this).InitEmptyExpr()); - r = _out294; + RAST._IExpr _out296; + _out296 = (this).Error(Dafny.Sequence.UnicodeFromString("Needs support for upcasting general traits"), (this).InitEmptyExpr()); + r = _out296; } } else { - RAST._IExpr _out295; - _out295 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"), (this).InitEmptyExpr()); - r = _out295; + RAST._IExpr _out297; + _out297 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types of type test is/are not Object, Ptr, General trait or Datatype"), (this).InitEmptyExpr()); + r = _out297; } - RAST._IExpr _out296; - Defs._IOwnership _out297; - (this).FromOwnership(r, _360_recOwned, expectedOwnership, out _out296, out _out297); - r = _out296; - resultingOwnership = _out297; - readIdents = _361_recIdents; + RAST._IExpr _out298; + Defs._IOwnership _out299; + (this).FromOwnership(r, _365_recOwned, expectedOwnership, out _out298, out _out299); + r = _out298; + resultingOwnership = _out299; + readIdents = _366_recIdents; } return ; } @@ -6753,67 +6757,37 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_BoolBoundedPool) { { r = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("[false, true]")); - RAST._IExpr _out298; - Defs._IOwnership _out299; - (this).FromOwned(r, expectedOwnership, out _out298, out _out299); - r = _out298; - resultingOwnership = _out299; - readIdents = Dafny.Set>.FromElements(); - return ; - } - goto after_match0; - } - } - { - if (_source0.is_SetBoundedPool) { - DAST._IExpression _368_of = _source0.dtor_of; - { - RAST._IExpr _369_exprGen; - Defs._IOwnership _370___v121; - Dafny.ISet> _371_recIdents; RAST._IExpr _out300; Defs._IOwnership _out301; - Dafny.ISet> _out302; - (this).GenExpr(_368_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out300, out _out301, out _out302); - _369_exprGen = _out300; - _370___v121 = _out301; - _371_recIdents = _out302; - r = ((_369_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - RAST._IExpr _out303; - Defs._IOwnership _out304; - (this).FromOwned(r, expectedOwnership, out _out303, out _out304); - r = _out303; - resultingOwnership = _out304; - readIdents = _371_recIdents; + (this).FromOwned(r, expectedOwnership, out _out300, out _out301); + r = _out300; + resultingOwnership = _out301; + readIdents = Dafny.Set>.FromElements(); return ; } goto after_match0; } } { - if (_source0.is_SeqBoundedPool) { - DAST._IExpression _372_of = _source0.dtor_of; - bool _373_includeDuplicates = _source0.dtor_includeDuplicates; + if (_source0.is_SetBoundedPool) { + DAST._IExpression _373_of = _source0.dtor_of; { RAST._IExpr _374_exprGen; - Defs._IOwnership _375___v122; + Defs._IOwnership _375___v121; Dafny.ISet> _376_recIdents; + RAST._IExpr _out302; + Defs._IOwnership _out303; + Dafny.ISet> _out304; + (this).GenExpr(_373_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); + _374_exprGen = _out302; + _375___v121 = _out303; + _376_recIdents = _out304; + r = ((_374_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out305; Defs._IOwnership _out306; - Dafny.ISet> _out307; - (this).GenExpr(_372_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out305, out _out306, out _out307); - _374_exprGen = _out305; - _375___v122 = _out306; - _376_recIdents = _out307; - r = ((_374_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_373_includeDuplicates)) { - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); - } - RAST._IExpr _out308; - Defs._IOwnership _out309; - (this).FromOwned(r, expectedOwnership, out _out308, out _out309); - r = _out308; - resultingOwnership = _out309; + (this).FromOwned(r, expectedOwnership, out _out305, out _out306); + r = _out305; + resultingOwnership = _out306; readIdents = _376_recIdents; return ; } @@ -6821,29 +6795,29 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } } { - if (_source0.is_MultisetBoundedPool) { + if (_source0.is_SeqBoundedPool) { DAST._IExpression _377_of = _source0.dtor_of; bool _378_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _379_exprGen; - Defs._IOwnership _380___v123; + Defs._IOwnership _380___v122; Dafny.ISet> _381_recIdents; - RAST._IExpr _out310; - Defs._IOwnership _out311; - Dafny.ISet> _out312; - (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out310, out _out311, out _out312); - _379_exprGen = _out310; - _380___v123 = _out311; - _381_recIdents = _out312; + RAST._IExpr _out307; + Defs._IOwnership _out308; + Dafny.ISet> _out309; + (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out307, out _out308, out _out309); + _379_exprGen = _out307; + _380___v122 = _out308; + _381_recIdents = _out309; r = ((_379_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_378_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } - RAST._IExpr _out313; - Defs._IOwnership _out314; - (this).FromOwned(r, expectedOwnership, out _out313, out _out314); - r = _out313; - resultingOwnership = _out314; + RAST._IExpr _out310; + Defs._IOwnership _out311; + (this).FromOwned(r, expectedOwnership, out _out310, out _out311); + r = _out310; + resultingOwnership = _out311; readIdents = _381_recIdents; return ; } @@ -6851,100 +6825,130 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } } { - if (_source0.is_MapBoundedPool) { + if (_source0.is_MultisetBoundedPool) { DAST._IExpression _382_of = _source0.dtor_of; + bool _383_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _383_exprGen; - Defs._IOwnership _384___v124; - Dafny.ISet> _385_recIdents; + RAST._IExpr _384_exprGen; + Defs._IOwnership _385___v123; + Dafny.ISet> _386_recIdents; + RAST._IExpr _out312; + Defs._IOwnership _out313; + Dafny.ISet> _out314; + (this).GenExpr(_382_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out312, out _out313, out _out314); + _384_exprGen = _out312; + _385___v123 = _out313; + _386_recIdents = _out314; + r = ((_384_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_383_includeDuplicates)) { + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); + } RAST._IExpr _out315; Defs._IOwnership _out316; - Dafny.ISet> _out317; - (this).GenExpr(_382_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out315, out _out316, out _out317); - _383_exprGen = _out315; - _384___v124 = _out316; - _385_recIdents = _out317; - r = ((((_383_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - readIdents = _385_recIdents; - RAST._IExpr _out318; - Defs._IOwnership _out319; - (this).FromOwned(r, expectedOwnership, out _out318, out _out319); - r = _out318; - resultingOwnership = _out319; + (this).FromOwned(r, expectedOwnership, out _out315, out _out316); + r = _out315; + resultingOwnership = _out316; + readIdents = _386_recIdents; + return ; } goto after_match0; } } { - if (_source0.is_ExactBoundedPool) { - DAST._IExpression _386_of = _source0.dtor_of; + if (_source0.is_MapBoundedPool) { + DAST._IExpression _387_of = _source0.dtor_of; { - RAST._IExpr _387_exprGen; - Defs._IOwnership _388___v125; - Dafny.ISet> _389_recIdents; + RAST._IExpr _388_exprGen; + Defs._IOwnership _389___v124; + Dafny.ISet> _390_recIdents; + RAST._IExpr _out317; + Defs._IOwnership _out318; + Dafny.ISet> _out319; + (this).GenExpr(_387_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out317, out _out318, out _out319); + _388_exprGen = _out317; + _389___v124 = _out318; + _390_recIdents = _out319; + r = ((((_388_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + readIdents = _390_recIdents; RAST._IExpr _out320; Defs._IOwnership _out321; - Dafny.ISet> _out322; - (this).GenExpr(_386_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out320, out _out321, out _out322); - _387_exprGen = _out320; - _388___v125 = _out321; - _389_recIdents = _out322; - r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_387_exprGen); - readIdents = _389_recIdents; - RAST._IExpr _out323; - Defs._IOwnership _out324; - (this).FromOwned(r, expectedOwnership, out _out323, out _out324); - r = _out323; - resultingOwnership = _out324; + (this).FromOwned(r, expectedOwnership, out _out320, out _out321); + r = _out320; + resultingOwnership = _out321; } goto after_match0; } } { - if (_source0.is_IntRange) { - DAST._IType _390_typ = _source0.dtor_elemType; - DAST._IExpression _391_lo = _source0.dtor_lo; - DAST._IExpression _392_hi = _source0.dtor_hi; - bool _393_up = _source0.dtor_up; + if (_source0.is_ExactBoundedPool) { + DAST._IExpression _391_of = _source0.dtor_of; { - RAST._IExpr _394_lo; - Defs._IOwnership _395___v126; - Dafny.ISet> _396_recIdentsLo; + RAST._IExpr _392_exprGen; + Defs._IOwnership _393___v125; + Dafny.ISet> _394_recIdents; + RAST._IExpr _out322; + Defs._IOwnership _out323; + Dafny.ISet> _out324; + (this).GenExpr(_391_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out322, out _out323, out _out324); + _392_exprGen = _out322; + _393___v125 = _out323; + _394_recIdents = _out324; + r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_392_exprGen); + readIdents = _394_recIdents; RAST._IExpr _out325; Defs._IOwnership _out326; - Dafny.ISet> _out327; - (this).GenExpr(_391_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out325, out _out326, out _out327); - _394_lo = _out325; - _395___v126 = _out326; - _396_recIdentsLo = _out327; - RAST._IExpr _397_hi; - Defs._IOwnership _398___v127; - Dafny.ISet> _399_recIdentsHi; - RAST._IExpr _out328; - Defs._IOwnership _out329; - Dafny.ISet> _out330; - (this).GenExpr(_392_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out328, out _out329, out _out330); - _397_hi = _out328; - _398___v127 = _out329; - _399_recIdentsHi = _out330; - if (_393_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_394_lo, _397_hi)); + (this).FromOwned(r, expectedOwnership, out _out325, out _out326); + r = _out325; + resultingOwnership = _out326; + } + goto after_match0; + } + } + { + if (_source0.is_IntRange) { + DAST._IType _395_typ = _source0.dtor_elemType; + DAST._IExpression _396_lo = _source0.dtor_lo; + DAST._IExpression _397_hi = _source0.dtor_hi; + bool _398_up = _source0.dtor_up; + { + RAST._IExpr _399_lo; + Defs._IOwnership _400___v126; + Dafny.ISet> _401_recIdentsLo; + RAST._IExpr _out327; + Defs._IOwnership _out328; + Dafny.ISet> _out329; + (this).GenExpr(_396_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out327, out _out328, out _out329); + _399_lo = _out327; + _400___v126 = _out328; + _401_recIdentsLo = _out329; + RAST._IExpr _402_hi; + Defs._IOwnership _403___v127; + Dafny.ISet> _404_recIdentsHi; + RAST._IExpr _out330; + Defs._IOwnership _out331; + Dafny.ISet> _out332; + (this).GenExpr(_397_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out330, out _out331, out _out332); + _402_hi = _out330; + _403___v127 = _out331; + _404_recIdentsHi = _out332; + if (_398_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_399_lo, _402_hi)); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_397_hi, _394_lo)); - } - if (!((_390_typ).is_Primitive)) { - RAST._IType _400_tpe; - RAST._IType _out331; - _out331 = (this).GenType(_390_typ, Defs.GenTypeContext.@default()); - _400_tpe = _out331; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_400_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); - } - RAST._IExpr _out332; - Defs._IOwnership _out333; - (this).FromOwned(r, expectedOwnership, out _out332, out _out333); - r = _out332; - resultingOwnership = _out333; - readIdents = Dafny.Set>.Union(_396_recIdentsLo, _399_recIdentsHi); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_402_hi, _399_lo)); + } + if (!((_395_typ).is_Primitive)) { + RAST._IType _405_tpe; + RAST._IType _out333; + _out333 = (this).GenType(_395_typ, Defs.GenTypeContext.@default()); + _405_tpe = _out333; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_405_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); + } + RAST._IExpr _out334; + Defs._IOwnership _out335; + (this).FromOwned(r, expectedOwnership, out _out334, out _out335); + r = _out334; + resultingOwnership = _out335; + readIdents = Dafny.Set>.Union(_401_recIdentsLo, _404_recIdentsHi); return ; } goto after_match0; @@ -6952,30 +6956,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_UnboundedIntRange) { - DAST._IExpression _401_start = _source0.dtor_start; - bool _402_up = _source0.dtor_up; + DAST._IExpression _406_start = _source0.dtor_start; + bool _407_up = _source0.dtor_up; { - RAST._IExpr _403_start; - Defs._IOwnership _404___v128; - Dafny.ISet> _405_recIdentStart; - RAST._IExpr _out334; - Defs._IOwnership _out335; - Dafny.ISet> _out336; - (this).GenExpr(_401_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out334, out _out335, out _out336); - _403_start = _out334; - _404___v128 = _out335; - _405_recIdentStart = _out336; - if (_402_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_403_start); + RAST._IExpr _408_start; + Defs._IOwnership _409___v128; + Dafny.ISet> _410_recIdentStart; + RAST._IExpr _out336; + Defs._IOwnership _out337; + Dafny.ISet> _out338; + (this).GenExpr(_406_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out336, out _out337, out _out338); + _408_start = _out336; + _409___v128 = _out337; + _410_recIdentStart = _out338; + if (_407_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_408_start); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_403_start); - } - RAST._IExpr _out337; - Defs._IOwnership _out338; - (this).FromOwned(r, expectedOwnership, out _out337, out _out338); - r = _out337; - resultingOwnership = _out338; - readIdents = _405_recIdentStart; + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_408_start); + } + RAST._IExpr _out339; + Defs._IOwnership _out340; + (this).FromOwned(r, expectedOwnership, out _out339, out _out340); + r = _out339; + resultingOwnership = _out340; + readIdents = _410_recIdentStart; return ; } goto after_match0; @@ -6983,23 +6987,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBuilder) { - DAST._IType _406_keyType = _source0.dtor_keyType; - DAST._IType _407_valueType = _source0.dtor_valueType; + DAST._IType _411_keyType = _source0.dtor_keyType; + DAST._IType _412_valueType = _source0.dtor_valueType; { - RAST._IType _408_kType; - RAST._IType _out339; - _out339 = (this).GenType(_406_keyType, Defs.GenTypeContext.@default()); - _408_kType = _out339; - RAST._IType _409_vType; - RAST._IType _out340; - _out340 = (this).GenType(_407_valueType, Defs.GenTypeContext.@default()); - _409_vType = _out340; - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_408_kType, _409_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out341; - Defs._IOwnership _out342; - (this).FromOwned(r, expectedOwnership, out _out341, out _out342); - r = _out341; - resultingOwnership = _out342; + RAST._IType _413_kType; + RAST._IType _out341; + _out341 = (this).GenType(_411_keyType, Defs.GenTypeContext.@default()); + _413_kType = _out341; + RAST._IType _414_vType; + RAST._IType _out342; + _out342 = (this).GenType(_412_valueType, Defs.GenTypeContext.@default()); + _414_vType = _out342; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_413_kType, _414_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out343; + Defs._IOwnership _out344; + (this).FromOwned(r, expectedOwnership, out _out343, out _out344); + r = _out343; + resultingOwnership = _out344; readIdents = Dafny.Set>.FromElements(); return ; } @@ -7008,93 +7012,93 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBuilder) { - DAST._IType _410_elemType = _source0.dtor_elemType; + DAST._IType _415_elemType = _source0.dtor_elemType; { - RAST._IType _411_eType; - RAST._IType _out343; - _out343 = (this).GenType(_410_elemType, Defs.GenTypeContext.@default()); - _411_eType = _out343; + RAST._IType _416_eType; + RAST._IType _out345; + _out345 = (this).GenType(_415_elemType, Defs.GenTypeContext.@default()); + _416_eType = _out345; readIdents = Dafny.Set>.FromElements(); - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_411_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); - RAST._IExpr _out344; - Defs._IOwnership _out345; - (this).FromOwned(r, expectedOwnership, out _out344, out _out345); - r = _out344; - resultingOwnership = _out345; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_416_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + RAST._IExpr _out346; + Defs._IOwnership _out347; + (this).FromOwned(r, expectedOwnership, out _out346, out _out347); + r = _out346; + resultingOwnership = _out347; return ; } goto after_match0; } } { - DAST._IType _412_elemType = _source0.dtor_elemType; - DAST._IExpression _413_collection = _source0.dtor_collection; - bool _414_is__forall = _source0.dtor_is__forall; - DAST._IExpression _415_lambda = _source0.dtor_lambda; + DAST._IType _417_elemType = _source0.dtor_elemType; + DAST._IExpression _418_collection = _source0.dtor_collection; + bool _419_is__forall = _source0.dtor_is__forall; + DAST._IExpression _420_lambda = _source0.dtor_lambda; { - RAST._IType _416_tpe; - RAST._IType _out346; - _out346 = (this).GenType(_412_elemType, Defs.GenTypeContext.@default()); - _416_tpe = _out346; - RAST._IExpr _417_collectionGen; - Defs._IOwnership _418___v129; - Dafny.ISet> _419_recIdents; - RAST._IExpr _out347; - Defs._IOwnership _out348; - Dafny.ISet> _out349; - (this).GenExpr(_413_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out347, out _out348, out _out349); - _417_collectionGen = _out347; - _418___v129 = _out348; - _419_recIdents = _out349; - Dafny.ISequence _420_extraAttributes; - _420_extraAttributes = Dafny.Sequence.FromElements(); - if ((((((_413_collection).is_IntRange) || ((_413_collection).is_UnboundedIntRange)) || ((_413_collection).is_SeqBoundedPool)) || ((_413_collection).is_ExactBoundedPool)) || ((_413_collection).is_MultisetBoundedPool)) { - _420_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); - } - if ((_415_lambda).is_Lambda) { - Dafny.ISequence _421_formals; - _421_formals = (_415_lambda).dtor_params; - Dafny.ISequence _422_newFormals; - _422_newFormals = Dafny.Sequence.FromElements(); - BigInteger _hi15 = new BigInteger((_421_formals).Count); - for (BigInteger _423_i = BigInteger.Zero; _423_i < _hi15; _423_i++) { - var _pat_let_tv0 = _420_extraAttributes; - var _pat_let_tv1 = _421_formals; - _422_newFormals = Dafny.Sequence.Concat(_422_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_421_formals).Select(_423_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _424_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_423_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _425_dt__update_hattributes_h0 => DAST.Formal.create((_424_dt__update__tmp_h0).dtor_name, (_424_dt__update__tmp_h0).dtor_typ, _425_dt__update_hattributes_h0))))))); - } - DAST._IExpression _426_newLambda; - DAST._IExpression _427_dt__update__tmp_h1 = _415_lambda; - Dafny.ISequence _428_dt__update_hparams_h0 = _422_newFormals; - _426_newLambda = DAST.Expression.create_Lambda(_428_dt__update_hparams_h0, (_427_dt__update__tmp_h1).dtor_retType, (_427_dt__update__tmp_h1).dtor_body); - RAST._IExpr _429_lambdaGen; - Defs._IOwnership _430___v130; - Dafny.ISet> _431_recLambdaIdents; - RAST._IExpr _out350; - Defs._IOwnership _out351; - Dafny.ISet> _out352; - (this).GenExpr(_426_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out350, out _out351, out _out352); - _429_lambdaGen = _out350; - _430___v130 = _out351; - _431_recLambdaIdents = _out352; - Dafny.ISequence _432_fn; - if (_414_is__forall) { - _432_fn = Dafny.Sequence.UnicodeFromString("all"); + RAST._IType _421_tpe; + RAST._IType _out348; + _out348 = (this).GenType(_417_elemType, Defs.GenTypeContext.@default()); + _421_tpe = _out348; + RAST._IExpr _422_collectionGen; + Defs._IOwnership _423___v129; + Dafny.ISet> _424_recIdents; + RAST._IExpr _out349; + Defs._IOwnership _out350; + Dafny.ISet> _out351; + (this).GenExpr(_418_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out349, out _out350, out _out351); + _422_collectionGen = _out349; + _423___v129 = _out350; + _424_recIdents = _out351; + Dafny.ISequence _425_extraAttributes; + _425_extraAttributes = Dafny.Sequence.FromElements(); + if ((((((_418_collection).is_IntRange) || ((_418_collection).is_UnboundedIntRange)) || ((_418_collection).is_SeqBoundedPool)) || ((_418_collection).is_ExactBoundedPool)) || ((_418_collection).is_MultisetBoundedPool)) { + _425_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); + } + if ((_420_lambda).is_Lambda) { + Dafny.ISequence _426_formals; + _426_formals = (_420_lambda).dtor_params; + Dafny.ISequence _427_newFormals; + _427_newFormals = Dafny.Sequence.FromElements(); + BigInteger _hi17 = new BigInteger((_426_formals).Count); + for (BigInteger _428_i = BigInteger.Zero; _428_i < _hi17; _428_i++) { + var _pat_let_tv0 = _425_extraAttributes; + var _pat_let_tv1 = _426_formals; + _427_newFormals = Dafny.Sequence.Concat(_427_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_426_formals).Select(_428_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _429_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_428_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _430_dt__update_hattributes_h0 => DAST.Formal.create((_429_dt__update__tmp_h0).dtor_name, (_429_dt__update__tmp_h0).dtor_typ, _430_dt__update_hattributes_h0))))))); + } + DAST._IExpression _431_newLambda; + DAST._IExpression _432_dt__update__tmp_h1 = _420_lambda; + Dafny.ISequence _433_dt__update_hparams_h0 = _427_newFormals; + _431_newLambda = DAST.Expression.create_Lambda(_433_dt__update_hparams_h0, (_432_dt__update__tmp_h1).dtor_retType, (_432_dt__update__tmp_h1).dtor_body); + RAST._IExpr _434_lambdaGen; + Defs._IOwnership _435___v130; + Dafny.ISet> _436_recLambdaIdents; + RAST._IExpr _out352; + Defs._IOwnership _out353; + Dafny.ISet> _out354; + (this).GenExpr(_431_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out352, out _out353, out _out354); + _434_lambdaGen = _out352; + _435___v130 = _out353; + _436_recLambdaIdents = _out354; + Dafny.ISequence _437_fn; + if (_419_is__forall) { + _437_fn = Dafny.Sequence.UnicodeFromString("all"); } else { - _432_fn = Dafny.Sequence.UnicodeFromString("any"); + _437_fn = Dafny.Sequence.UnicodeFromString("any"); } - r = ((_417_collectionGen).Sel(_432_fn)).Apply1(((_429_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); - readIdents = Dafny.Set>.Union(_419_recIdents, _431_recLambdaIdents); + r = ((_422_collectionGen).Sel(_437_fn)).Apply1(((_434_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); + readIdents = Dafny.Set>.Union(_424_recIdents, _436_recLambdaIdents); } else { - RAST._IExpr _out353; - _out353 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); - r = _out353; + RAST._IExpr _out355; + _out355 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); + r = _out355; readIdents = Dafny.Set>.FromElements(); } - RAST._IExpr _out354; - Defs._IOwnership _out355; - (this).FromOwned(r, expectedOwnership, out _out354, out _out355); - r = _out354; - resultingOwnership = _out355; + RAST._IExpr _out356; + Defs._IOwnership _out357; + (this).FromOwned(r, expectedOwnership, out _out356, out _out357); + r = _out356; + resultingOwnership = _out357; } } after_match0: ; diff --git a/Source/DafnyCore/GeneratedFromDafny/RAST.cs b/Source/DafnyCore/GeneratedFromDafny/RAST.cs index eede8991622..bc75960ad21 100644 --- a/Source/DafnyCore/GeneratedFromDafny/RAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/RAST.cs @@ -1819,7 +1819,7 @@ public static RAST._IAttribute Name(Dafny.ISequence name) { Dafny.ISequence> _1_derived = _source0.dtor_derived; Dafny.ISequence _2_arguments = (((new BigInteger((_1_derived).Count)).Sign != 0) ? (Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), RAST.__default.SeqToString>(_1_derived, ((System.Func, Dafny.ISequence>)((_3_derived) => { return _3_derived; - })), Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(")"))) : (Dafny.Sequence.UnicodeFromString(""))); + })), Dafny.Sequence.UnicodeFromString(", "))), Dafny.Sequence.UnicodeFromString(")"))) : (Dafny.Sequence.UnicodeFromString(""))); return Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("#["), _0_name), _2_arguments), Dafny.Sequence.UnicodeFromString("]")); } } @@ -8037,6 +8037,11 @@ public RAST._IPrintingInfo printingInfo { get { } } } + { + if (object.Equals(_source2, Dafny.Sequence.UnicodeFromString("=>"))) { + return RAST.PrintingInfo.create_PrecedenceAssociativity(new BigInteger(120), RAST.Associativity.create_RightToLeft()); + } + } { return RAST.PrintingInfo.create_PrecedenceAssociativity(BigInteger.Zero, RAST.Associativity.create_RequiresParentheses()); } diff --git a/Source/DafnyCore/Resolver/ModuleResolver.cs b/Source/DafnyCore/Resolver/ModuleResolver.cs index 9121265f277..df9011e98b3 100644 --- a/Source/DafnyCore/Resolver/ModuleResolver.cs +++ b/Source/DafnyCore/Resolver/ModuleResolver.cs @@ -2926,15 +2926,27 @@ void MarkSCCAsNotSupportingEquality() { } } + public static bool SurelyNeverSupportEqualityTypeParameters(IndDatatypeDecl.ES equalitySupport, List typeParams, List typeArgs) { + return + equalitySupport == IndDatatypeDecl.ES.Never || + equalitySupport == IndDatatypeDecl.ES.ConsultTypeArguments && + typeArgs.Zip(typeParams).Any(tt => + tt.Item2.NecessaryForEqualitySupportOfSurroundingInductiveDatatype && SurelyNeverSupportEquality(tt.Item1)); + } + // If returns true, the given type never supports equality // If return false, then the type must support equality if type parameters support equality // It is unsound for a type to make this function return false when there is no type parameter // assignment that makes this type support equality public static bool SurelyNeverSupportEquality(Type type) { - type = type.Normalize(); + type = type.NormalizeExpand(); return - type.AsNewtype is { EqualitySupport: IndDatatypeDecl.ES.Never } || - type.AsIndDatatype is { EqualitySupport: IndDatatypeDecl.ES.Never } || + type.AsNewtype is { EqualitySupport: var equalitySupport, TypeArgs: var typeParams } + && SurelyNeverSupportEqualityTypeParameters(equalitySupport, typeParams, type.TypeArgs) + || + type.AsIndDatatype is { EqualitySupport: var equalitySupport2, TypeArgs: var typeParams2 } + && SurelyNeverSupportEqualityTypeParameters(equalitySupport2, typeParams2, type.TypeArgs) + || type.IsCoDatatype || type.IsArrowType || type.AsSeqType is { Arg: var argType } && SurelyNeverSupportEquality(argType) || type.AsMapType is { Range: var rangeType } && SurelyNeverSupportEquality(rangeType); From e56ddd7ae7856bf1209b8d73b8161ef5fd9645ba Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Tue, 17 Dec 2024 15:20:04 -0600 Subject: [PATCH 32/69] Fixed newtype and seq update and coerce patterns as well --- Source/DafnyCore/Backends/Dafny/AST.dfy | 4 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 4 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 16 +- Source/DafnyCore/GeneratedFromDafny/DAST.cs | 64 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 1614 +++++++++-------- 5 files changed, 870 insertions(+), 832 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index 7d11362b43e..c4088556818 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -497,8 +497,8 @@ module {:extern "DAST"} DAST { MultisetValue(elements: seq) | MapValue(mapElems: seq<(Expression, Expression)>, domainType: Type, rangeType: Type) | MapBuilder(keyType: Type, valueType: Type) | - SeqUpdate(expr: Expression, indexExpr: Expression, value: Expression) | - MapUpdate(expr: Expression, indexExpr: Expression, value: Expression) | + SeqUpdate(expr: Expression, indexExpr: Expression, value: Expression, collectionType: Type, exprType: Type) | + MapUpdate(expr: Expression, indexExpr: Expression, value: Expression, collectionType: Type, exprType: Type) | SetBuilder(elemType: Type) | ToMultiset(Expression) | This() | diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 8bb1171ec17..85e3b94c654 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -2428,11 +2428,11 @@ protected override void EmitIndexCollectionUpdate(Expression source, Expression if (GetExprConverter(wr, wStmts, out var builder, out var convert)) { if (resultCollectionType.AsSeqType is { }) { builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_SeqUpdate( - convert(source), convert(index), convert(value) + convert(source), convert(index), convert(value), GenType(resultCollectionType), GenType(source.Type) )); } else if (resultCollectionType.AsMapType is { }) { builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_MapUpdate( - convert(source), convert(index), convert(value) + convert(source), convert(index), convert(value), GenType(resultCollectionType), GenType(source.Type) )); } else { AddUnsupported(source.tok, "EmitIndexCollectionUpdate for " + resultCollectionType.ToString() + ""); diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index f901d966114..e986ade29ab 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -1385,7 +1385,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Block(partialEqRhs)) ]; coerceImplBodyCases := coerceImplBodyCases + [ - R.MatchCase(R.RawPattern(datatypeName + "::" + ctorMatch), + R.MatchCase(R.RawPattern(datatypeName + "::" + pattern), R.Block(coerceRhs)) ]; } @@ -3184,7 +3184,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } } else { - r := Error("Source and/or target types is/are not Object, Ptr, General trait or Datatype"); + r := Error("Conversion from " + fromTpeGen.ToString("") + " to " + toTpeGen.ToString("") + " not yet supported. Currently supported are Object, Ptr, General trait, Datatype or newtype"); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } @@ -3736,21 +3736,25 @@ module {:extern "DCOMP"} DafnyToRustCompiler { r, resultingOwnership := FromOwned(r, expectedOwnership); return; } - case SeqUpdate(expr, index, value) => { + case SeqUpdate(expr, index, value, collectionType, exprType) => { var exprR, _, exprIdents := GenExpr(expr, selfIdent, env, OwnershipAutoBorrowed); var indexR, indexOwnership, indexIdents := GenExpr(index, selfIdent, env, OwnershipBorrowed); var valueR, valueOwnership, valueIdents := GenExpr(value, selfIdent, env, OwnershipBorrowed); r := exprR.Sel("update_index").Apply([indexR, valueR]); - r, resultingOwnership := FromOwned(r, expectedOwnership); + // if exprType is a newtype, autoderef will take care of calling this method + // However, we need to convert the result back to the newtype + r, resultingOwnership := GenExprConvertTo(r, OwnershipOwned, collectionType, exprType, env, expectedOwnership); readIdents := exprIdents + indexIdents + valueIdents; return; } - case MapUpdate(expr, index, value) => { + case MapUpdate(expr, index, value, collectionType, exprType) => { var exprR, _, exprIdents := GenExpr(expr, selfIdent, env, OwnershipAutoBorrowed); var indexR, indexOwnership, indexIdents := GenExpr(index, selfIdent, env, OwnershipBorrowed); var valueR, valueOwnership, valueIdents := GenExpr(value, selfIdent, env, OwnershipBorrowed); r := exprR.Sel("update_index").Apply([indexR, valueR]); - r, resultingOwnership := FromOwned(r, expectedOwnership); + // if exprType is a newtype, autoderef will take care of calling this method + // However, we need to convert the result back to the newtype + r, resultingOwnership := GenExprConvertTo(r, OwnershipOwned, collectionType, exprType, env, expectedOwnership); readIdents := exprIdents + indexIdents + valueIdents; return; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DAST.cs b/Source/DafnyCore/GeneratedFromDafny/DAST.cs index 168904aecc5..41d40189a07 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DAST.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DAST.cs @@ -7055,6 +7055,8 @@ public interface _IExpression { DAST._IType dtor_valueType { get; } DAST._IExpression dtor_expr { get; } DAST._IExpression dtor_indexExpr { get; } + DAST._IType dtor_collectionType { get; } + DAST._IType dtor_exprType { get; } DAST._IType dtor_elemType { get; } DAST._IExpression dtor_ToMultiset_a0 { get; } DAST._IExpression dtor_cond { get; } @@ -7066,7 +7068,6 @@ public interface _IExpression { DAST._IExpression dtor_left { get; } DAST._IExpression dtor_right { get; } DAST.Format._IBinaryOpFormat dtor_format2 { get; } - DAST._IType dtor_exprType { get; } BigInteger dtor_dim { get; } bool dtor_native { get; } Dafny.ISequence dtor_field { get; } @@ -7169,11 +7170,11 @@ public static _IExpression create_MapValue(Dafny.ISequence<_System._ITuple2 s, bool final) _87_printImplBodyCases = Dafny.Sequence.Concat(_87_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _114_pattern), RAST.Expr.create_Block(_96_printRhs)))); _88_hashImplBodyCases = Dafny.Sequence.Concat(_88_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _114_pattern), RAST.Expr.create_Block(_97_hashRhs)))); _90_partialEqImplBodyCases = Dafny.Sequence.Concat(_90_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _114_pattern), Dafny.Sequence.UnicodeFromString(", ")), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _115_pattern2), Dafny.Sequence.UnicodeFromString(")")), RAST.Expr.create_Block(_98_partialEqRhs)))); - _89_coerceImplBodyCases = Dafny.Sequence.Concat(_89_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _93_ctorMatch), RAST.Expr.create_Block(_113_coerceRhs)))); + _89_coerceImplBodyCases = Dafny.Sequence.Concat(_89_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _114_pattern), RAST.Expr.create_Block(_113_coerceRhs)))); } _90_partialEqImplBodyCases = Dafny.Sequence.Concat(_90_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.UnicodeFromString("_"), RAST.Expr.create_Block(RAST.Expr.create_LiteralBool(false))))); if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { @@ -4425,7 +4425,7 @@ public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership } } else { RAST._IExpr _out12; - _out12 = (this).Error(Dafny.Sequence.UnicodeFromString("Source and/or target types is/are not Object, Ptr, General trait or Datatype"), (this).InitEmptyExpr()); + _out12 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Conversion from "), (_0_fromTpeGen)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_1_toTpeGen)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" not yet supported. Currently supported are Object, Ptr, General trait, Datatype or newtype")), (this).InitEmptyExpr()); r = _out12; RAST._IExpr _out13; Defs._IOwnership _out14; @@ -5437,44 +5437,46 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _119_expr = _source0.dtor_expr; DAST._IExpression _120_index = _source0.dtor_indexExpr; DAST._IExpression _121_value = _source0.dtor_value; + DAST._IType _122_collectionType = _source0.dtor_collectionType; + DAST._IType _123_exprType = _source0.dtor_exprType; { - RAST._IExpr _122_exprR; - Defs._IOwnership _123___v92; - Dafny.ISet> _124_exprIdents; + RAST._IExpr _124_exprR; + Defs._IOwnership _125___v92; + Dafny.ISet> _126_exprIdents; RAST._IExpr _out100; Defs._IOwnership _out101; Dafny.ISet> _out102; (this).GenExpr(_119_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out100, out _out101, out _out102); - _122_exprR = _out100; - _123___v92 = _out101; - _124_exprIdents = _out102; - RAST._IExpr _125_indexR; - Defs._IOwnership _126_indexOwnership; - Dafny.ISet> _127_indexIdents; + _124_exprR = _out100; + _125___v92 = _out101; + _126_exprIdents = _out102; + RAST._IExpr _127_indexR; + Defs._IOwnership _128_indexOwnership; + Dafny.ISet> _129_indexIdents; RAST._IExpr _out103; Defs._IOwnership _out104; Dafny.ISet> _out105; (this).GenExpr(_120_index, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out103, out _out104, out _out105); - _125_indexR = _out103; - _126_indexOwnership = _out104; - _127_indexIdents = _out105; - RAST._IExpr _128_valueR; - Defs._IOwnership _129_valueOwnership; - Dafny.ISet> _130_valueIdents; + _127_indexR = _out103; + _128_indexOwnership = _out104; + _129_indexIdents = _out105; + RAST._IExpr _130_valueR; + Defs._IOwnership _131_valueOwnership; + Dafny.ISet> _132_valueIdents; RAST._IExpr _out106; Defs._IOwnership _out107; Dafny.ISet> _out108; (this).GenExpr(_121_value, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out106, out _out107, out _out108); - _128_valueR = _out106; - _129_valueOwnership = _out107; - _130_valueIdents = _out108; - r = ((_122_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_125_indexR, _128_valueR)); + _130_valueR = _out106; + _131_valueOwnership = _out107; + _132_valueIdents = _out108; + r = ((_124_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_127_indexR, _130_valueR)); RAST._IExpr _out109; Defs._IOwnership _out110; - (this).FromOwned(r, expectedOwnership, out _out109, out _out110); + (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), _122_collectionType, _123_exprType, env, expectedOwnership, out _out109, out _out110); r = _out109; resultingOwnership = _out110; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_124_exprIdents, _127_indexIdents), _130_valueIdents); + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_126_exprIdents, _129_indexIdents), _132_valueIdents); return ; } goto after_match0; @@ -5482,47 +5484,49 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapUpdate) { - DAST._IExpression _131_expr = _source0.dtor_expr; - DAST._IExpression _132_index = _source0.dtor_indexExpr; - DAST._IExpression _133_value = _source0.dtor_value; + DAST._IExpression _133_expr = _source0.dtor_expr; + DAST._IExpression _134_index = _source0.dtor_indexExpr; + DAST._IExpression _135_value = _source0.dtor_value; + DAST._IType _136_collectionType = _source0.dtor_collectionType; + DAST._IType _137_exprType = _source0.dtor_exprType; { - RAST._IExpr _134_exprR; - Defs._IOwnership _135___v93; - Dafny.ISet> _136_exprIdents; + RAST._IExpr _138_exprR; + Defs._IOwnership _139___v93; + Dafny.ISet> _140_exprIdents; RAST._IExpr _out111; Defs._IOwnership _out112; Dafny.ISet> _out113; - (this).GenExpr(_131_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out111, out _out112, out _out113); - _134_exprR = _out111; - _135___v93 = _out112; - _136_exprIdents = _out113; - RAST._IExpr _137_indexR; - Defs._IOwnership _138_indexOwnership; - Dafny.ISet> _139_indexIdents; + (this).GenExpr(_133_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out111, out _out112, out _out113); + _138_exprR = _out111; + _139___v93 = _out112; + _140_exprIdents = _out113; + RAST._IExpr _141_indexR; + Defs._IOwnership _142_indexOwnership; + Dafny.ISet> _143_indexIdents; RAST._IExpr _out114; Defs._IOwnership _out115; Dafny.ISet> _out116; - (this).GenExpr(_132_index, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out114, out _out115, out _out116); - _137_indexR = _out114; - _138_indexOwnership = _out115; - _139_indexIdents = _out116; - RAST._IExpr _140_valueR; - Defs._IOwnership _141_valueOwnership; - Dafny.ISet> _142_valueIdents; + (this).GenExpr(_134_index, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out114, out _out115, out _out116); + _141_indexR = _out114; + _142_indexOwnership = _out115; + _143_indexIdents = _out116; + RAST._IExpr _144_valueR; + Defs._IOwnership _145_valueOwnership; + Dafny.ISet> _146_valueIdents; RAST._IExpr _out117; Defs._IOwnership _out118; Dafny.ISet> _out119; - (this).GenExpr(_133_value, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out117, out _out118, out _out119); - _140_valueR = _out117; - _141_valueOwnership = _out118; - _142_valueIdents = _out119; - r = ((_134_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_137_indexR, _140_valueR)); + (this).GenExpr(_135_value, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out117, out _out118, out _out119); + _144_valueR = _out117; + _145_valueOwnership = _out118; + _146_valueIdents = _out119; + r = ((_138_exprR).Sel(Dafny.Sequence.UnicodeFromString("update_index"))).Apply(Dafny.Sequence.FromElements(_141_indexR, _144_valueR)); RAST._IExpr _out120; Defs._IOwnership _out121; - (this).FromOwned(r, expectedOwnership, out _out120, out _out121); + (this).GenExprConvertTo(r, Defs.Ownership.create_OwnershipOwned(), _136_collectionType, _137_exprType, env, expectedOwnership, out _out120, out _out121); r = _out120; resultingOwnership = _out121; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_136_exprIdents, _139_indexIdents), _142_valueIdents); + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_140_exprIdents, _143_indexIdents), _146_valueIdents); return ; } goto after_match0; @@ -5534,13 +5538,13 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Defs._ISelfInfo _source1 = selfIdent; { if (_source1.is_ThisTyped) { - Dafny.ISequence _143_id = _source1.dtor_rSelfName; - DAST._IType _144_dafnyType = _source1.dtor_dafnyType; + Dafny.ISequence _147_id = _source1.dtor_rSelfName; + DAST._IType _148_dafnyType = _source1.dtor_dafnyType; { RAST._IExpr _out122; Defs._IOwnership _out123; Dafny.ISet> _out124; - (this).GenIdent(_143_id, selfIdent, env, expectedOwnership, out _out122, out _out123, out _out124); + (this).GenIdent(_147_id, selfIdent, env, expectedOwnership, out _out122, out _out123, out _out124); r = _out122; resultingOwnership = _out123; readIdents = _out124; @@ -5549,7 +5553,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } } { - Defs._ISelfInfo _145_None = _source1; + Defs._ISelfInfo _149_None = _source1; { RAST._IExpr _out125; _out125 = (this).Error(Dafny.Sequence.UnicodeFromString("this outside of a method"), (this).InitEmptyExpr()); @@ -5570,47 +5574,47 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Ite) { - DAST._IExpression _146_cond = _source0.dtor_cond; - DAST._IExpression _147_t = _source0.dtor_thn; - DAST._IExpression _148_f = _source0.dtor_els; + DAST._IExpression _150_cond = _source0.dtor_cond; + DAST._IExpression _151_t = _source0.dtor_thn; + DAST._IExpression _152_f = _source0.dtor_els; { - RAST._IExpr _149_cond; - Defs._IOwnership _150___v94; - Dafny.ISet> _151_recIdentsCond; + RAST._IExpr _153_cond; + Defs._IOwnership _154___v94; + Dafny.ISet> _155_recIdentsCond; RAST._IExpr _out128; Defs._IOwnership _out129; Dafny.ISet> _out130; - (this).GenExpr(_146_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out128, out _out129, out _out130); - _149_cond = _out128; - _150___v94 = _out129; - _151_recIdentsCond = _out130; - RAST._IExpr _152_fExpr; - Defs._IOwnership _153_fOwned; - Dafny.ISet> _154_recIdentsF; + (this).GenExpr(_150_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out128, out _out129, out _out130); + _153_cond = _out128; + _154___v94 = _out129; + _155_recIdentsCond = _out130; + RAST._IExpr _156_fExpr; + Defs._IOwnership _157_fOwned; + Dafny.ISet> _158_recIdentsF; RAST._IExpr _out131; Defs._IOwnership _out132; Dafny.ISet> _out133; - (this).GenExpr(_148_f, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out131, out _out132, out _out133); - _152_fExpr = _out131; - _153_fOwned = _out132; - _154_recIdentsF = _out133; - RAST._IExpr _155_tExpr; - Defs._IOwnership _156___v95; - Dafny.ISet> _157_recIdentsT; + (this).GenExpr(_152_f, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out131, out _out132, out _out133); + _156_fExpr = _out131; + _157_fOwned = _out132; + _158_recIdentsF = _out133; + RAST._IExpr _159_tExpr; + Defs._IOwnership _160___v95; + Dafny.ISet> _161_recIdentsT; RAST._IExpr _out134; Defs._IOwnership _out135; Dafny.ISet> _out136; - (this).GenExpr(_147_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out134, out _out135, out _out136); - _155_tExpr = _out134; - _156___v95 = _out135; - _157_recIdentsT = _out136; - r = RAST.Expr.create_IfExpr(_149_cond, _155_tExpr, _152_fExpr); + (this).GenExpr(_151_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out134, out _out135, out _out136); + _159_tExpr = _out134; + _160___v95 = _out135; + _161_recIdentsT = _out136; + r = RAST.Expr.create_IfExpr(_153_cond, _159_tExpr, _156_fExpr); RAST._IExpr _out137; Defs._IOwnership _out138; (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out137, out _out138); r = _out137; resultingOwnership = _out138; - readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_151_recIdentsCond, _157_recIdentsT), _154_recIdentsF); + readIdents = Dafny.Set>.Union(Dafny.Set>.Union(_155_recIdentsCond, _161_recIdentsT), _158_recIdentsF); return ; } goto after_match0; @@ -5620,26 +5624,26 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_UnOp) { DAST._IUnaryOp unOp0 = _source0.dtor_unOp; if (unOp0.is_Not) { - DAST._IExpression _158_e = _source0.dtor_expr; - DAST.Format._IUnaryOpFormat _159_format = _source0.dtor_format1; + DAST._IExpression _162_e = _source0.dtor_expr; + DAST.Format._IUnaryOpFormat _163_format = _source0.dtor_format1; { - RAST._IExpr _160_recursiveGen; - Defs._IOwnership _161___v96; - Dafny.ISet> _162_recIdents; + RAST._IExpr _164_recursiveGen; + Defs._IOwnership _165___v96; + Dafny.ISet> _166_recIdents; RAST._IExpr _out139; Defs._IOwnership _out140; Dafny.ISet> _out141; - (this).GenExpr(_158_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out139, out _out140, out _out141); - _160_recursiveGen = _out139; - _161___v96 = _out140; - _162_recIdents = _out141; - r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _160_recursiveGen, _159_format); + (this).GenExpr(_162_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out139, out _out140, out _out141); + _164_recursiveGen = _out139; + _165___v96 = _out140; + _166_recIdents = _out141; + r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _164_recursiveGen, _163_format); RAST._IExpr _out142; Defs._IOwnership _out143; (this).FromOwned(r, expectedOwnership, out _out142, out _out143); r = _out142; resultingOwnership = _out143; - readIdents = _162_recIdents; + readIdents = _166_recIdents; return ; } goto after_match0; @@ -5650,26 +5654,26 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_UnOp) { DAST._IUnaryOp unOp1 = _source0.dtor_unOp; if (unOp1.is_BitwiseNot) { - DAST._IExpression _163_e = _source0.dtor_expr; - DAST.Format._IUnaryOpFormat _164_format = _source0.dtor_format1; + DAST._IExpression _167_e = _source0.dtor_expr; + DAST.Format._IUnaryOpFormat _168_format = _source0.dtor_format1; { - RAST._IExpr _165_recursiveGen; - Defs._IOwnership _166___v97; - Dafny.ISet> _167_recIdents; + RAST._IExpr _169_recursiveGen; + Defs._IOwnership _170___v97; + Dafny.ISet> _171_recIdents; RAST._IExpr _out144; Defs._IOwnership _out145; Dafny.ISet> _out146; - (this).GenExpr(_163_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out144, out _out145, out _out146); - _165_recursiveGen = _out144; - _166___v97 = _out145; - _167_recIdents = _out146; - r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _165_recursiveGen, _164_format); + (this).GenExpr(_167_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out144, out _out145, out _out146); + _169_recursiveGen = _out144; + _170___v97 = _out145; + _171_recIdents = _out146; + r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _169_recursiveGen, _168_format); RAST._IExpr _out147; Defs._IOwnership _out148; (this).FromOwned(r, expectedOwnership, out _out147, out _out148); r = _out147; resultingOwnership = _out148; - readIdents = _167_recIdents; + readIdents = _171_recIdents; return ; } goto after_match0; @@ -5680,26 +5684,26 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir if (_source0.is_UnOp) { DAST._IUnaryOp unOp2 = _source0.dtor_unOp; if (unOp2.is_Cardinality) { - DAST._IExpression _168_e = _source0.dtor_expr; - DAST.Format._IUnaryOpFormat _169_format = _source0.dtor_format1; + DAST._IExpression _172_e = _source0.dtor_expr; + DAST.Format._IUnaryOpFormat _173_format = _source0.dtor_format1; { - RAST._IExpr _170_recursiveGen; - Defs._IOwnership _171_recOwned; - Dafny.ISet> _172_recIdents; + RAST._IExpr _174_recursiveGen; + Defs._IOwnership _175_recOwned; + Dafny.ISet> _176_recIdents; RAST._IExpr _out149; Defs._IOwnership _out150; Dafny.ISet> _out151; - (this).GenExpr(_168_e, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out149, out _out150, out _out151); - _170_recursiveGen = _out149; - _171_recOwned = _out150; - _172_recIdents = _out151; - r = ((_170_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("cardinality"))).Apply0(); + (this).GenExpr(_172_e, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out149, out _out150, out _out151); + _174_recursiveGen = _out149; + _175_recOwned = _out150; + _176_recIdents = _out151; + r = ((_174_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("cardinality"))).Apply0(); RAST._IExpr _out152; Defs._IOwnership _out153; (this).FromOwned(r, expectedOwnership, out _out152, out _out153); r = _out152; resultingOwnership = _out153; - readIdents = _172_recIdents; + readIdents = _176_recIdents; return ; } goto after_match0; @@ -5720,42 +5724,42 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_ArrayLen) { - DAST._IExpression _173_expr = _source0.dtor_expr; - DAST._IType _174_exprType = _source0.dtor_exprType; - BigInteger _175_dim = _source0.dtor_dim; - bool _176_native = _source0.dtor_native; + DAST._IExpression _177_expr = _source0.dtor_expr; + DAST._IType _178_exprType = _source0.dtor_exprType; + BigInteger _179_dim = _source0.dtor_dim; + bool _180_native = _source0.dtor_native; { - RAST._IExpr _177_recursiveGen; - Defs._IOwnership _178___v102; - Dafny.ISet> _179_recIdents; + RAST._IExpr _181_recursiveGen; + Defs._IOwnership _182___v102; + Dafny.ISet> _183_recIdents; RAST._IExpr _out157; Defs._IOwnership _out158; Dafny.ISet> _out159; - (this).GenExpr(_173_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out157, out _out158, out _out159); - _177_recursiveGen = _out157; - _178___v102 = _out158; - _179_recIdents = _out159; - RAST._IType _180_arrayType; + (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out157, out _out158, out _out159); + _181_recursiveGen = _out157; + _182___v102 = _out158; + _183_recIdents = _out159; + RAST._IType _184_arrayType; RAST._IType _out160; - _out160 = (this).GenType(_174_exprType, Defs.GenTypeContext.@default()); - _180_arrayType = _out160; - if (!((_180_arrayType).IsObjectOrPointer())) { + _out160 = (this).GenType(_178_exprType, Defs.GenTypeContext.@default()); + _184_arrayType = _out160; + if (!((_184_arrayType).IsObjectOrPointer())) { RAST._IExpr _out161; - _out161 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array length of something not an array but "), (_180_arrayType)._ToString(Defs.__default.IND)), (this).InitEmptyExpr()); + _out161 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Array length of something not an array but "), (_184_arrayType)._ToString(Defs.__default.IND)), (this).InitEmptyExpr()); r = _out161; } else { - RAST._IType _181_underlying; - _181_underlying = (_180_arrayType).ObjectOrPointerUnderlying(); - if (((_175_dim).Sign == 0) && ((_181_underlying).is_Array)) { - r = ((((this).read__macro).Apply1(_177_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); + RAST._IType _185_underlying; + _185_underlying = (_184_arrayType).ObjectOrPointerUnderlying(); + if (((_179_dim).Sign == 0) && ((_185_underlying).is_Array)) { + r = ((((this).read__macro).Apply1(_181_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); } else { - if ((_175_dim).Sign == 0) { - r = (((((this).read__macro).Apply1(_177_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("data"))).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); + if ((_179_dim).Sign == 0) { + r = (((((this).read__macro).Apply1(_181_recursiveGen)).Sel(Dafny.Sequence.UnicodeFromString("data"))).Sel(Dafny.Sequence.UnicodeFromString("len"))).Apply0(); } else { - r = ((((this).read__macro).Apply1(_177_recursiveGen)).Sel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("length"), Std.Strings.__default.OfNat(_175_dim)), Dafny.Sequence.UnicodeFromString("_usize")))).Apply0(); + r = ((((this).read__macro).Apply1(_181_recursiveGen)).Sel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("length"), Std.Strings.__default.OfNat(_179_dim)), Dafny.Sequence.UnicodeFromString("_usize")))).Apply0(); } } - if (!(_176_native)) { + if (!(_180_native)) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(r); } } @@ -5764,7 +5768,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir (this).FromOwned(r, expectedOwnership, out _out162, out _out163); r = _out162; resultingOwnership = _out163; - readIdents = _179_recIdents; + readIdents = _183_recIdents; return ; } goto after_match0; @@ -5772,20 +5776,20 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapKeys) { - DAST._IExpression _182_expr = _source0.dtor_expr; + DAST._IExpression _186_expr = _source0.dtor_expr; { - RAST._IExpr _183_recursiveGen; - Defs._IOwnership _184___v103; - Dafny.ISet> _185_recIdents; + RAST._IExpr _187_recursiveGen; + Defs._IOwnership _188___v103; + Dafny.ISet> _189_recIdents; RAST._IExpr _out164; Defs._IOwnership _out165; Dafny.ISet> _out166; - (this).GenExpr(_182_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out164, out _out165, out _out166); - _183_recursiveGen = _out164; - _184___v103 = _out165; - _185_recIdents = _out166; - readIdents = _185_recIdents; - r = ((_183_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); + (this).GenExpr(_186_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out164, out _out165, out _out166); + _187_recursiveGen = _out164; + _188___v103 = _out165; + _189_recIdents = _out166; + readIdents = _189_recIdents; + r = ((_187_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); RAST._IExpr _out167; Defs._IOwnership _out168; (this).FromOwned(r, expectedOwnership, out _out167, out _out168); @@ -5798,20 +5802,20 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapValues) { - DAST._IExpression _186_expr = _source0.dtor_expr; + DAST._IExpression _190_expr = _source0.dtor_expr; { - RAST._IExpr _187_recursiveGen; - Defs._IOwnership _188___v104; - Dafny.ISet> _189_recIdents; + RAST._IExpr _191_recursiveGen; + Defs._IOwnership _192___v104; + Dafny.ISet> _193_recIdents; RAST._IExpr _out169; Defs._IOwnership _out170; Dafny.ISet> _out171; - (this).GenExpr(_186_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out169, out _out170, out _out171); - _187_recursiveGen = _out169; - _188___v104 = _out170; - _189_recIdents = _out171; - readIdents = _189_recIdents; - r = ((_187_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); + (this).GenExpr(_190_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out169, out _out170, out _out171); + _191_recursiveGen = _out169; + _192___v104 = _out170; + _193_recIdents = _out171; + readIdents = _193_recIdents; + r = ((_191_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); RAST._IExpr _out172; Defs._IOwnership _out173; (this).FromOwned(r, expectedOwnership, out _out172, out _out173); @@ -5824,20 +5828,20 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapItems) { - DAST._IExpression _190_expr = _source0.dtor_expr; + DAST._IExpression _194_expr = _source0.dtor_expr; { - RAST._IExpr _191_recursiveGen; - Defs._IOwnership _192___v105; - Dafny.ISet> _193_recIdents; + RAST._IExpr _195_recursiveGen; + Defs._IOwnership _196___v105; + Dafny.ISet> _197_recIdents; RAST._IExpr _out174; Defs._IOwnership _out175; Dafny.ISet> _out176; - (this).GenExpr(_190_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out174, out _out175, out _out176); - _191_recursiveGen = _out174; - _192___v105 = _out175; - _193_recIdents = _out176; - readIdents = _193_recIdents; - r = ((_191_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); + (this).GenExpr(_194_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out174, out _out175, out _out176); + _195_recursiveGen = _out174; + _196___v105 = _out175; + _197_recIdents = _out176; + readIdents = _197_recIdents; + r = ((_195_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); RAST._IExpr _out177; Defs._IOwnership _out178; (this).FromOwned(r, expectedOwnership, out _out177, out _out178); @@ -5850,100 +5854,100 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SelectFn) { - DAST._IExpression _194_on = _source0.dtor_expr; - Dafny.ISequence _195_field = _source0.dtor_field; - bool _196_isDatatype = _source0.dtor_onDatatype; - bool _197_isStatic = _source0.dtor_isStatic; - bool _198_isConstant = _source0.dtor_isConstant; - Dafny.ISequence _199_arguments = _source0.dtor_arguments; + DAST._IExpression _198_on = _source0.dtor_expr; + Dafny.ISequence _199_field = _source0.dtor_field; + bool _200_isDatatype = _source0.dtor_onDatatype; + bool _201_isStatic = _source0.dtor_isStatic; + bool _202_isConstant = _source0.dtor_isConstant; + Dafny.ISequence _203_arguments = _source0.dtor_arguments; { - RAST._IExpr _200_onExpr; - Defs._IOwnership _201_onOwned; - Dafny.ISet> _202_recIdents; + RAST._IExpr _204_onExpr; + Defs._IOwnership _205_onOwned; + Dafny.ISet> _206_recIdents; RAST._IExpr _out179; Defs._IOwnership _out180; Dafny.ISet> _out181; - (this).GenExpr(_194_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out179, out _out180, out _out181); - _200_onExpr = _out179; - _201_onOwned = _out180; - _202_recIdents = _out181; - Dafny.ISequence _203_onString; - _203_onString = (_200_onExpr)._ToString(Defs.__default.IND); - Defs._IEnvironment _204_lEnv; - _204_lEnv = env; - Dafny.ISequence<_System._ITuple2, RAST._IType>> _205_args; - _205_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(); - Dafny.ISequence _206_parameters; - _206_parameters = Dafny.Sequence.FromElements(); - BigInteger _hi9 = new BigInteger((_199_arguments).Count); - for (BigInteger _207_i = BigInteger.Zero; _207_i < _hi9; _207_i++) { - RAST._IType _208_ty; + (this).GenExpr(_198_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out179, out _out180, out _out181); + _204_onExpr = _out179; + _205_onOwned = _out180; + _206_recIdents = _out181; + Dafny.ISequence _207_onString; + _207_onString = (_204_onExpr)._ToString(Defs.__default.IND); + Defs._IEnvironment _208_lEnv; + _208_lEnv = env; + Dafny.ISequence<_System._ITuple2, RAST._IType>> _209_args; + _209_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(); + Dafny.ISequence _210_parameters; + _210_parameters = Dafny.Sequence.FromElements(); + BigInteger _hi9 = new BigInteger((_203_arguments).Count); + for (BigInteger _211_i = BigInteger.Zero; _211_i < _hi9; _211_i++) { + RAST._IType _212_ty; RAST._IType _out182; - _out182 = (this).GenType((_199_arguments).Select(_207_i), Defs.GenTypeContext.@default()); - _208_ty = _out182; - RAST._IType _209_bTy; - _209_bTy = RAST.Type.create_Borrowed(_208_ty); - Dafny.ISequence _210_name; - _210_name = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("x"), Std.Strings.__default.OfInt(_207_i)); - _204_lEnv = (_204_lEnv).AddAssigned(_210_name, _209_bTy); - _206_parameters = Dafny.Sequence.Concat(_206_parameters, Dafny.Sequence.FromElements(RAST.Formal.create(_210_name, _209_bTy))); - _205_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.Concat(_205_args, Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(_System.Tuple2, RAST._IType>.create(_210_name, _208_ty))); - } - RAST._IExpr _211_body; - if (_197_isStatic) { - _211_body = (_200_onExpr).FSel(Defs.__default.escapeVar(_195_field)); + _out182 = (this).GenType((_203_arguments).Select(_211_i), Defs.GenTypeContext.@default()); + _212_ty = _out182; + RAST._IType _213_bTy; + _213_bTy = RAST.Type.create_Borrowed(_212_ty); + Dafny.ISequence _214_name; + _214_name = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("x"), Std.Strings.__default.OfInt(_211_i)); + _208_lEnv = (_208_lEnv).AddAssigned(_214_name, _213_bTy); + _210_parameters = Dafny.Sequence.Concat(_210_parameters, Dafny.Sequence.FromElements(RAST.Formal.create(_214_name, _213_bTy))); + _209_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.Concat(_209_args, Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(_System.Tuple2, RAST._IType>.create(_214_name, _212_ty))); + } + RAST._IExpr _215_body; + if (_201_isStatic) { + _215_body = (_204_onExpr).FSel(Defs.__default.escapeVar(_199_field)); } else { - _211_body = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("callTarget"))).Sel(Defs.__default.escapeVar(_195_field)); - } - if (_198_isConstant) { - _211_body = (_211_body).Apply0(); - } - Dafny.ISequence _212_onExprArgs; - _212_onExprArgs = Dafny.Sequence.FromElements(); - BigInteger _hi10 = new BigInteger((_205_args).Count); - for (BigInteger _213_i = BigInteger.Zero; _213_i < _hi10; _213_i++) { - _System._ITuple2, RAST._IType> _let_tmp_rhs1 = (_205_args).Select(_213_i); - Dafny.ISequence _214_name = _let_tmp_rhs1.dtor__0; - RAST._IType _215_ty = _let_tmp_rhs1.dtor__1; - RAST._IExpr _216_rIdent; - Defs._IOwnership _217___v106; - Dafny.ISet> _218___v107; + _215_body = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("callTarget"))).Sel(Defs.__default.escapeVar(_199_field)); + } + if (_202_isConstant) { + _215_body = (_215_body).Apply0(); + } + Dafny.ISequence _216_onExprArgs; + _216_onExprArgs = Dafny.Sequence.FromElements(); + BigInteger _hi10 = new BigInteger((_209_args).Count); + for (BigInteger _217_i = BigInteger.Zero; _217_i < _hi10; _217_i++) { + _System._ITuple2, RAST._IType> _let_tmp_rhs1 = (_209_args).Select(_217_i); + Dafny.ISequence _218_name = _let_tmp_rhs1.dtor__0; + RAST._IType _219_ty = _let_tmp_rhs1.dtor__1; + RAST._IExpr _220_rIdent; + Defs._IOwnership _221___v106; + Dafny.ISet> _222___v107; RAST._IExpr _out183; Defs._IOwnership _out184; Dafny.ISet> _out185; - (this).GenIdent(_214_name, selfIdent, _204_lEnv, (((!(_198_isConstant)) && ((_215_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out183, out _out184, out _out185); - _216_rIdent = _out183; - _217___v106 = _out184; - _218___v107 = _out185; - _212_onExprArgs = Dafny.Sequence.Concat(_212_onExprArgs, Dafny.Sequence.FromElements(_216_rIdent)); - } - _211_body = (_211_body).Apply(_212_onExprArgs); - r = RAST.Expr.create_Lambda(_206_parameters, Std.Wrappers.Option.create_None(), _211_body); - if (_197_isStatic) { + (this).GenIdent(_218_name, selfIdent, _208_lEnv, (((!(_202_isConstant)) && ((_219_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out183, out _out184, out _out185); + _220_rIdent = _out183; + _221___v106 = _out184; + _222___v107 = _out185; + _216_onExprArgs = Dafny.Sequence.Concat(_216_onExprArgs, Dafny.Sequence.FromElements(_220_rIdent)); + } + _215_body = (_215_body).Apply(_216_onExprArgs); + r = RAST.Expr.create_Lambda(_210_parameters, Std.Wrappers.Option.create_None(), _215_body); + if (_201_isStatic) { } else { - RAST._IExpr _219_target; - if (object.Equals(_201_onOwned, Defs.Ownership.create_OwnershipOwned())) { - _219_target = _200_onExpr; + RAST._IExpr _223_target; + if (object.Equals(_205_onOwned, Defs.Ownership.create_OwnershipOwned())) { + _223_target = _204_onExpr; } else { - _219_target = (_200_onExpr).Clone(); + _223_target = (_204_onExpr).Clone(); } - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("callTarget"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_219_target))).Then(r)); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("callTarget"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_223_target))).Then(r)); } - Dafny.ISequence _220_typeShapeArgs; - _220_typeShapeArgs = Dafny.Sequence.FromElements(); - BigInteger _hi11 = new BigInteger((_199_arguments).Count); - for (BigInteger _221_i = BigInteger.Zero; _221_i < _hi11; _221_i++) { - _220_typeShapeArgs = Dafny.Sequence.Concat(_220_typeShapeArgs, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))); + Dafny.ISequence _224_typeShapeArgs; + _224_typeShapeArgs = Dafny.Sequence.FromElements(); + BigInteger _hi11 = new BigInteger((_203_arguments).Count); + for (BigInteger _225_i = BigInteger.Zero; _225_i < _hi11; _225_i++) { + _224_typeShapeArgs = Dafny.Sequence.Concat(_224_typeShapeArgs, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))); } - RAST._IType _222_typeShape; - _222_typeShape = RAST.Type.create_DynType(RAST.Type.create_FnType(_220_typeShapeArgs, RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_")))); - r = RAST.Expr.create_TypeAscription((RAST.__default.std__rc__Rc__new).Apply1(r), ((RAST.__default.std__rc__Rc).AsType()).Apply(Dafny.Sequence.FromElements(_222_typeShape))); + RAST._IType _226_typeShape; + _226_typeShape = RAST.Type.create_DynType(RAST.Type.create_FnType(_224_typeShapeArgs, RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_")))); + r = RAST.Expr.create_TypeAscription((RAST.__default.std__rc__Rc__new).Apply1(r), ((RAST.__default.std__rc__Rc).AsType()).Apply(Dafny.Sequence.FromElements(_226_typeShape))); RAST._IExpr _out186; Defs._IOwnership _out187; (this).FromOwned(r, expectedOwnership, out _out186, out _out187); r = _out186; resultingOwnership = _out187; - readIdents = _202_recIdents; + readIdents = _206_recIdents; return ; } goto after_match0; @@ -5951,46 +5955,46 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Select) { - DAST._IExpression _223_on = _source0.dtor_expr; - Dafny.ISequence _224_field = _source0.dtor_field; - DAST._IFieldMutability _225_fieldMutability = _source0.dtor_fieldMutability; - DAST._ISelectContext _226_selectContext = _source0.dtor_selectContext; - DAST._IType _227_fieldType = _source0.dtor_isfieldType; + DAST._IExpression _227_on = _source0.dtor_expr; + Dafny.ISequence _228_field = _source0.dtor_field; + DAST._IFieldMutability _229_fieldMutability = _source0.dtor_fieldMutability; + DAST._ISelectContext _230_selectContext = _source0.dtor_selectContext; + DAST._IType _231_fieldType = _source0.dtor_isfieldType; { - if (((_223_on).is_Companion) || ((_223_on).is_ExternCompanion)) { - RAST._IExpr _228_onExpr; - Defs._IOwnership _229_onOwned; - Dafny.ISet> _230_recIdents; + if (((_227_on).is_Companion) || ((_227_on).is_ExternCompanion)) { + RAST._IExpr _232_onExpr; + Defs._IOwnership _233_onOwned; + Dafny.ISet> _234_recIdents; RAST._IExpr _out188; Defs._IOwnership _out189; Dafny.ISet> _out190; - (this).GenExpr(_223_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out188, out _out189, out _out190); - _228_onExpr = _out188; - _229_onOwned = _out189; - _230_recIdents = _out190; - r = ((_228_onExpr).FSel(Defs.__default.escapeVar(_224_field))).Apply0(); + (this).GenExpr(_227_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out188, out _out189, out _out190); + _232_onExpr = _out188; + _233_onOwned = _out189; + _234_recIdents = _out190; + r = ((_232_onExpr).FSel(Defs.__default.escapeVar(_228_field))).Apply0(); RAST._IExpr _out191; Defs._IOwnership _out192; (this).FromOwned(r, expectedOwnership, out _out191, out _out192); r = _out191; resultingOwnership = _out192; - readIdents = _230_recIdents; + readIdents = _234_recIdents; return ; - } else if ((_226_selectContext).is_SelectContextDatatype) { - RAST._IExpr _231_onExpr; - Defs._IOwnership _232_onOwned; - Dafny.ISet> _233_recIdents; + } else if ((_230_selectContext).is_SelectContextDatatype) { + RAST._IExpr _235_onExpr; + Defs._IOwnership _236_onOwned; + Dafny.ISet> _237_recIdents; RAST._IExpr _out193; Defs._IOwnership _out194; Dafny.ISet> _out195; - (this).GenExpr(_223_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out193, out _out194, out _out195); - _231_onExpr = _out193; - _232_onOwned = _out194; - _233_recIdents = _out195; - r = ((_231_onExpr).Sel(Defs.__default.escapeVar(_224_field))).Apply0(); - Defs._IOwnership _234_originalMutability; - _234_originalMutability = Defs.Ownership.create_OwnershipOwned(); - DAST._IFieldMutability _source2 = _225_fieldMutability; + (this).GenExpr(_227_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out193, out _out194, out _out195); + _235_onExpr = _out193; + _236_onOwned = _out194; + _237_recIdents = _out195; + r = ((_235_onExpr).Sel(Defs.__default.escapeVar(_228_field))).Apply0(); + Defs._IOwnership _238_originalMutability; + _238_originalMutability = Defs.Ownership.create_OwnershipOwned(); + DAST._IFieldMutability _source2 = _229_fieldMutability; { if (_source2.is_ConstantField) { goto after_match2; @@ -5998,7 +6002,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source2.is_InternalClassConstantFieldOrDatatypeDestructor) { - _234_originalMutability = Defs.Ownership.create_OwnershipBorrowed(); + _238_originalMutability = Defs.Ownership.create_OwnershipBorrowed(); goto after_match2; } } @@ -6008,57 +6012,57 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir r = _out196; } after_match2: ; - RAST._IType _235_typ; + RAST._IType _239_typ; RAST._IType _out197; - _out197 = (this).GenType(_227_fieldType, Defs.GenTypeContext.@default()); - _235_typ = _out197; + _out197 = (this).GenType(_231_fieldType, Defs.GenTypeContext.@default()); + _239_typ = _out197; RAST._IExpr _out198; Defs._IOwnership _out199; - (this).FromOwnership(r, _234_originalMutability, expectedOwnership, out _out198, out _out199); + (this).FromOwnership(r, _238_originalMutability, expectedOwnership, out _out198, out _out199); r = _out198; resultingOwnership = _out199; - readIdents = _233_recIdents; - } else if ((_226_selectContext).is_SelectContextGeneralTrait) { - Defs._IOwnership _236_onOwned = Defs.Ownership.Default(); - Dafny.ISet> _237_recIdents = Dafny.Set>.Empty; + readIdents = _237_recIdents; + } else if ((_230_selectContext).is_SelectContextGeneralTrait) { + Defs._IOwnership _240_onOwned = Defs.Ownership.Default(); + Dafny.ISet> _241_recIdents = Dafny.Set>.Empty; readIdents = Dafny.Set>.FromElements(); - if ((_223_on).IsThisUpcast()) { + if ((_227_on).IsThisUpcast()) { r = RAST.__default.self; - _237_recIdents = Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self")); + _241_recIdents = Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self")); } else { RAST._IExpr _out200; Defs._IOwnership _out201; Dafny.ISet> _out202; - (this).GenExpr(_223_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out200, out _out201, out _out202); + (this).GenExpr(_227_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out200, out _out201, out _out202); r = _out200; - _236_onOwned = _out201; - _237_recIdents = _out202; + _240_onOwned = _out201; + _241_recIdents = _out202; if (!object.Equals(r, RAST.__default.self)) { r = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(r); } } - readIdents = Dafny.Set>.Union(readIdents, _237_recIdents); - r = ((r).Sel(Defs.__default.escapeVar(_224_field))).Apply0(); + readIdents = Dafny.Set>.Union(readIdents, _241_recIdents); + r = ((r).Sel(Defs.__default.escapeVar(_228_field))).Apply0(); RAST._IExpr _out203; Defs._IOwnership _out204; (this).FromOwned(r, expectedOwnership, out _out203, out _out204); r = _out203; resultingOwnership = _out204; - readIdents = _237_recIdents; + readIdents = _241_recIdents; } else { - RAST._IExpr _238_onExpr; - Defs._IOwnership _239_onOwned; - Dafny.ISet> _240_recIdents; + RAST._IExpr _242_onExpr; + Defs._IOwnership _243_onOwned; + Dafny.ISet> _244_recIdents; RAST._IExpr _out205; Defs._IOwnership _out206; Dafny.ISet> _out207; - (this).GenExpr(_223_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out205, out _out206, out _out207); - _238_onExpr = _out205; - _239_onOwned = _out206; - _240_recIdents = _out207; - r = _238_onExpr; - if (!object.Equals(_238_onExpr, RAST.__default.self)) { - RAST._IExpr _source3 = _238_onExpr; + (this).GenExpr(_227_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out205, out _out206, out _out207); + _242_onExpr = _out205; + _243_onOwned = _out206; + _244_recIdents = _out207; + r = _242_onExpr; + if (!object.Equals(_242_onExpr, RAST.__default.self)) { + RAST._IExpr _source3 = _242_onExpr; { if (_source3.is_UnaryOp) { Dafny.ISequence op10 = _source3.dtor_op1; @@ -6082,8 +6086,8 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } r = ((this).read__macro).Apply1(r); } - r = (r).Sel(Defs.__default.escapeVar(_224_field)); - DAST._IFieldMutability _source4 = _225_fieldMutability; + r = (r).Sel(Defs.__default.escapeVar(_228_field)); + DAST._IFieldMutability _source4 = _229_fieldMutability; { if (_source4.is_ConstantField) { r = (r).Apply0(); @@ -6106,7 +6110,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir (this).FromOwned(r, expectedOwnership, out _out208, out _out209); r = _out208; resultingOwnership = _out209; - readIdents = _240_recIdents; + readIdents = _244_recIdents; } return ; } @@ -6115,63 +6119,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Index) { - DAST._IExpression _241_on = _source0.dtor_expr; - DAST._ICollKind _242_collKind = _source0.dtor_collKind; - Dafny.ISequence _243_indices = _source0.dtor_indices; + DAST._IExpression _245_on = _source0.dtor_expr; + DAST._ICollKind _246_collKind = _source0.dtor_collKind; + Dafny.ISequence _247_indices = _source0.dtor_indices; { - RAST._IExpr _244_onExpr; - Defs._IOwnership _245_onOwned; - Dafny.ISet> _246_recIdents; + RAST._IExpr _248_onExpr; + Defs._IOwnership _249_onOwned; + Dafny.ISet> _250_recIdents; RAST._IExpr _out210; Defs._IOwnership _out211; Dafny.ISet> _out212; - (this).GenExpr(_241_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out210, out _out211, out _out212); - _244_onExpr = _out210; - _245_onOwned = _out211; - _246_recIdents = _out212; - readIdents = _246_recIdents; - r = _244_onExpr; - bool _247_hadArray; - _247_hadArray = false; - if (object.Equals(_242_collKind, DAST.CollKind.create_Array())) { + (this).GenExpr(_245_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out210, out _out211, out _out212); + _248_onExpr = _out210; + _249_onOwned = _out211; + _250_recIdents = _out212; + readIdents = _250_recIdents; + r = _248_onExpr; + bool _251_hadArray; + _251_hadArray = false; + if (object.Equals(_246_collKind, DAST.CollKind.create_Array())) { r = ((this).read__macro).Apply1(r); - _247_hadArray = true; - if ((new BigInteger((_243_indices).Count)) > (BigInteger.One)) { + _251_hadArray = true; + if ((new BigInteger((_247_indices).Count)) > (BigInteger.One)) { r = (r).Sel(Dafny.Sequence.UnicodeFromString("data")); } } - BigInteger _hi12 = new BigInteger((_243_indices).Count); - for (BigInteger _248_i = BigInteger.Zero; _248_i < _hi12; _248_i++) { - if (object.Equals(_242_collKind, DAST.CollKind.create_Array())) { - RAST._IExpr _249_idx; - Defs._IOwnership _250_idxOwned; - Dafny.ISet> _251_recIdentsIdx; + BigInteger _hi12 = new BigInteger((_247_indices).Count); + for (BigInteger _252_i = BigInteger.Zero; _252_i < _hi12; _252_i++) { + if (object.Equals(_246_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _253_idx; + Defs._IOwnership _254_idxOwned; + Dafny.ISet> _255_recIdentsIdx; RAST._IExpr _out213; Defs._IOwnership _out214; Dafny.ISet> _out215; - (this).GenExpr((_243_indices).Select(_248_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out213, out _out214, out _out215); - _249_idx = _out213; - _250_idxOwned = _out214; - _251_recIdentsIdx = _out215; - _249_idx = RAST.__default.IntoUsize(_249_idx); - r = RAST.Expr.create_SelectIndex(r, _249_idx); - readIdents = Dafny.Set>.Union(readIdents, _251_recIdentsIdx); + (this).GenExpr((_247_indices).Select(_252_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out213, out _out214, out _out215); + _253_idx = _out213; + _254_idxOwned = _out214; + _255_recIdentsIdx = _out215; + _253_idx = RAST.__default.IntoUsize(_253_idx); + r = RAST.Expr.create_SelectIndex(r, _253_idx); + readIdents = Dafny.Set>.Union(readIdents, _255_recIdentsIdx); } else { - RAST._IExpr _252_idx; - Defs._IOwnership _253_idxOwned; - Dafny.ISet> _254_recIdentsIdx; + RAST._IExpr _256_idx; + Defs._IOwnership _257_idxOwned; + Dafny.ISet> _258_recIdentsIdx; RAST._IExpr _out216; Defs._IOwnership _out217; Dafny.ISet> _out218; - (this).GenExpr((_243_indices).Select(_248_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out216, out _out217, out _out218); - _252_idx = _out216; - _253_idxOwned = _out217; - _254_recIdentsIdx = _out218; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_252_idx); - readIdents = Dafny.Set>.Union(readIdents, _254_recIdentsIdx); + (this).GenExpr((_247_indices).Select(_252_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out216, out _out217, out _out218); + _256_idx = _out216; + _257_idxOwned = _out217; + _258_recIdentsIdx = _out218; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_256_idx); + readIdents = Dafny.Set>.Union(readIdents, _258_recIdentsIdx); } } - if (_247_hadArray) { + if (_251_hadArray) { r = (r).Clone(); } RAST._IExpr _out219; @@ -6186,63 +6190,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IndexRange) { - DAST._IExpression _255_on = _source0.dtor_expr; - bool _256_isArray = _source0.dtor_isArray; - Std.Wrappers._IOption _257_low = _source0.dtor_low; - Std.Wrappers._IOption _258_high = _source0.dtor_high; + DAST._IExpression _259_on = _source0.dtor_expr; + bool _260_isArray = _source0.dtor_isArray; + Std.Wrappers._IOption _261_low = _source0.dtor_low; + Std.Wrappers._IOption _262_high = _source0.dtor_high; { - Defs._IOwnership _259_onExpectedOwnership; - if (_256_isArray) { + Defs._IOwnership _263_onExpectedOwnership; + if (_260_isArray) { if (((this).pointerType).is_Raw) { - _259_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); + _263_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); } else { - _259_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); + _263_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); } } else { - _259_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); + _263_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); } - RAST._IExpr _260_onExpr; - Defs._IOwnership _261_onOwned; - Dafny.ISet> _262_recIdents; + RAST._IExpr _264_onExpr; + Defs._IOwnership _265_onOwned; + Dafny.ISet> _266_recIdents; RAST._IExpr _out221; Defs._IOwnership _out222; Dafny.ISet> _out223; - (this).GenExpr(_255_on, selfIdent, env, _259_onExpectedOwnership, out _out221, out _out222, out _out223); - _260_onExpr = _out221; - _261_onOwned = _out222; - _262_recIdents = _out223; - readIdents = _262_recIdents; - Dafny.ISequence _263_methodName; - if ((_257_low).is_Some) { - if ((_258_high).is_Some) { - _263_methodName = Dafny.Sequence.UnicodeFromString("slice"); + (this).GenExpr(_259_on, selfIdent, env, _263_onExpectedOwnership, out _out221, out _out222, out _out223); + _264_onExpr = _out221; + _265_onOwned = _out222; + _266_recIdents = _out223; + readIdents = _266_recIdents; + Dafny.ISequence _267_methodName; + if ((_261_low).is_Some) { + if ((_262_high).is_Some) { + _267_methodName = Dafny.Sequence.UnicodeFromString("slice"); } else { - _263_methodName = Dafny.Sequence.UnicodeFromString("drop"); + _267_methodName = Dafny.Sequence.UnicodeFromString("drop"); } - } else if ((_258_high).is_Some) { - _263_methodName = Dafny.Sequence.UnicodeFromString("take"); + } else if ((_262_high).is_Some) { + _267_methodName = Dafny.Sequence.UnicodeFromString("take"); } else { - _263_methodName = Dafny.Sequence.UnicodeFromString(""); + _267_methodName = Dafny.Sequence.UnicodeFromString(""); } - Dafny.ISequence _264_arguments; - _264_arguments = Dafny.Sequence.FromElements(); - Std.Wrappers._IOption _source5 = _257_low; + Dafny.ISequence _268_arguments; + _268_arguments = Dafny.Sequence.FromElements(); + Std.Wrappers._IOption _source5 = _261_low; { if (_source5.is_Some) { - DAST._IExpression _265_l = _source5.dtor_value; + DAST._IExpression _269_l = _source5.dtor_value; { - RAST._IExpr _266_lExpr; - Defs._IOwnership _267___v110; - Dafny.ISet> _268_recIdentsL; + RAST._IExpr _270_lExpr; + Defs._IOwnership _271___v110; + Dafny.ISet> _272_recIdentsL; RAST._IExpr _out224; Defs._IOwnership _out225; Dafny.ISet> _out226; - (this).GenExpr(_265_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out224, out _out225, out _out226); - _266_lExpr = _out224; - _267___v110 = _out225; - _268_recIdentsL = _out226; - _264_arguments = Dafny.Sequence.Concat(_264_arguments, Dafny.Sequence.FromElements(_266_lExpr)); - readIdents = Dafny.Set>.Union(readIdents, _268_recIdentsL); + (this).GenExpr(_269_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out224, out _out225, out _out226); + _270_lExpr = _out224; + _271___v110 = _out225; + _272_recIdentsL = _out226; + _268_arguments = Dafny.Sequence.Concat(_268_arguments, Dafny.Sequence.FromElements(_270_lExpr)); + readIdents = Dafny.Set>.Union(readIdents, _272_recIdentsL); } goto after_match5; } @@ -6250,23 +6254,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match5: ; - Std.Wrappers._IOption _source6 = _258_high; + Std.Wrappers._IOption _source6 = _262_high; { if (_source6.is_Some) { - DAST._IExpression _269_h = _source6.dtor_value; + DAST._IExpression _273_h = _source6.dtor_value; { - RAST._IExpr _270_hExpr; - Defs._IOwnership _271___v111; - Dafny.ISet> _272_recIdentsH; + RAST._IExpr _274_hExpr; + Defs._IOwnership _275___v111; + Dafny.ISet> _276_recIdentsH; RAST._IExpr _out227; Defs._IOwnership _out228; Dafny.ISet> _out229; - (this).GenExpr(_269_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out227, out _out228, out _out229); - _270_hExpr = _out227; - _271___v111 = _out228; - _272_recIdentsH = _out229; - _264_arguments = Dafny.Sequence.Concat(_264_arguments, Dafny.Sequence.FromElements(_270_hExpr)); - readIdents = Dafny.Set>.Union(readIdents, _272_recIdentsH); + (this).GenExpr(_273_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out227, out _out228, out _out229); + _274_hExpr = _out227; + _275___v111 = _out228; + _276_recIdentsH = _out229; + _268_arguments = Dafny.Sequence.Concat(_268_arguments, Dafny.Sequence.FromElements(_274_hExpr)); + readIdents = Dafny.Set>.Union(readIdents, _276_recIdentsH); } goto after_match6; } @@ -6274,21 +6278,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match6: ; - r = _260_onExpr; - if (_256_isArray) { - if (!(_263_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - _263_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _263_methodName); + r = _264_onExpr; + if (_260_isArray) { + if (!(_267_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + _267_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _267_methodName); } - Dafny.ISequence _273_object__suffix; + Dafny.ISequence _277_object__suffix; if (((this).pointerType).is_Raw) { - _273_object__suffix = Dafny.Sequence.UnicodeFromString(""); + _277_object__suffix = Dafny.Sequence.UnicodeFromString(""); } else { - _273_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); + _277_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); } - r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _263_methodName), _273_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_260_onExpr), _264_arguments)); + r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _267_methodName), _277_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_264_onExpr), _268_arguments)); } else { - if (!(_263_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - r = ((r).Sel(_263_methodName)).Apply(_264_arguments); + if (!(_267_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + r = ((r).Sel(_267_methodName)).Apply(_268_arguments); } else { r = (r).Clone(); } @@ -6305,28 +6309,28 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TupleSelect) { - DAST._IExpression _274_on = _source0.dtor_expr; - BigInteger _275_idx = _source0.dtor_index; - DAST._IType _276_fieldType = _source0.dtor_fieldType; + DAST._IExpression _278_on = _source0.dtor_expr; + BigInteger _279_idx = _source0.dtor_index; + DAST._IType _280_fieldType = _source0.dtor_fieldType; { - RAST._IExpr _277_onExpr; - Defs._IOwnership _278_onOwnership; - Dafny.ISet> _279_recIdents; + RAST._IExpr _281_onExpr; + Defs._IOwnership _282_onOwnership; + Dafny.ISet> _283_recIdents; RAST._IExpr _out232; Defs._IOwnership _out233; Dafny.ISet> _out234; - (this).GenExpr(_274_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out232, out _out233, out _out234); - _277_onExpr = _out232; - _278_onOwnership = _out233; - _279_recIdents = _out234; - Dafny.ISequence _280_selName; - _280_selName = Std.Strings.__default.OfNat(_275_idx); - DAST._IType _source7 = _276_fieldType; + (this).GenExpr(_278_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out232, out _out233, out _out234); + _281_onExpr = _out232; + _282_onOwnership = _out233; + _283_recIdents = _out234; + Dafny.ISequence _284_selName; + _284_selName = Std.Strings.__default.OfNat(_279_idx); + DAST._IType _source7 = _280_fieldType; { if (_source7.is_Tuple) { - Dafny.ISequence _281_tps = _source7.dtor_Tuple_a0; - if (((_276_fieldType).is_Tuple) && ((new BigInteger((_281_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { - _280_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _280_selName); + Dafny.ISequence _285_tps = _source7.dtor_Tuple_a0; + if (((_280_fieldType).is_Tuple) && ((new BigInteger((_285_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { + _284_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _284_selName); } goto after_match7; } @@ -6334,13 +6338,13 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match7: ; - r = ((_277_onExpr).Sel(_280_selName)).Clone(); + r = ((_281_onExpr).Sel(_284_selName)).Clone(); RAST._IExpr _out235; Defs._IOwnership _out236; (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out235, out _out236); r = _out235; resultingOwnership = _out236; - readIdents = _279_recIdents; + readIdents = _283_recIdents; return ; } goto after_match0; @@ -6348,14 +6352,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Call) { - DAST._IExpression _282_on = _source0.dtor_on; - DAST._ICallName _283_name = _source0.dtor_callName; - Dafny.ISequence _284_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _285_args = _source0.dtor_args; + DAST._IExpression _286_on = _source0.dtor_on; + DAST._ICallName _287_name = _source0.dtor_callName; + Dafny.ISequence _288_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _289_args = _source0.dtor_args; { RAST._IExpr _out237; Dafny.ISet> _out238; - (this).GenOwnedCallPart(_282_on, selfIdent, _283_name, _284_typeArgs, _285_args, env, out _out237, out _out238); + (this).GenOwnedCallPart(_286_on, selfIdent, _287_name, _288_typeArgs, _289_args, env, out _out237, out _out238); r = _out237; readIdents = _out238; RAST._IExpr _out239; @@ -6370,85 +6374,85 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Lambda) { - Dafny.ISequence _286_paramsDafny = _source0.dtor_params; - DAST._IType _287_retType = _source0.dtor_retType; - Dafny.ISequence _288_body = _source0.dtor_body; + Dafny.ISequence _290_paramsDafny = _source0.dtor_params; + DAST._IType _291_retType = _source0.dtor_retType; + Dafny.ISequence _292_body = _source0.dtor_body; { - Dafny.ISequence _289_params; + Dafny.ISequence _293_params; Dafny.ISequence _out241; - _out241 = (this).GenParams(_286_paramsDafny, _286_paramsDafny, true); - _289_params = _out241; - Dafny.ISequence> _290_paramNames; - _290_paramNames = Dafny.Sequence>.FromElements(); - Dafny.IMap,RAST._IType> _291_paramTypesMap; - _291_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); - BigInteger _hi13 = new BigInteger((_289_params).Count); - for (BigInteger _292_i = BigInteger.Zero; _292_i < _hi13; _292_i++) { - Dafny.ISequence _293_name; - _293_name = ((_289_params).Select(_292_i)).dtor_name; - _290_paramNames = Dafny.Sequence>.Concat(_290_paramNames, Dafny.Sequence>.FromElements(_293_name)); - _291_paramTypesMap = Dafny.Map, RAST._IType>.Update(_291_paramTypesMap, _293_name, ((_289_params).Select(_292_i)).dtor_tpe); - } - Defs._IEnvironment _294_subEnv; - _294_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_290_paramNames, _291_paramTypesMap, Dafny.Set>.FromElements())); - RAST._IExpr _295_recursiveGen; - Dafny.ISet> _296_recIdents; - Defs._IEnvironment _297___v113; + _out241 = (this).GenParams(_290_paramsDafny, _290_paramsDafny, true); + _293_params = _out241; + Dafny.ISequence> _294_paramNames; + _294_paramNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _295_paramTypesMap; + _295_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); + BigInteger _hi13 = new BigInteger((_293_params).Count); + for (BigInteger _296_i = BigInteger.Zero; _296_i < _hi13; _296_i++) { + Dafny.ISequence _297_name; + _297_name = ((_293_params).Select(_296_i)).dtor_name; + _294_paramNames = Dafny.Sequence>.Concat(_294_paramNames, Dafny.Sequence>.FromElements(_297_name)); + _295_paramTypesMap = Dafny.Map, RAST._IType>.Update(_295_paramTypesMap, _297_name, ((_293_params).Select(_296_i)).dtor_tpe); + } + Defs._IEnvironment _298_subEnv; + _298_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_294_paramNames, _295_paramTypesMap, Dafny.Set>.FromElements())); + RAST._IExpr _299_recursiveGen; + Dafny.ISet> _300_recIdents; + Defs._IEnvironment _301___v113; RAST._IExpr _out242; Dafny.ISet> _out243; Defs._IEnvironment _out244; - (this).GenStmts(_288_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _294_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out242, out _out243, out _out244); - _295_recursiveGen = _out242; - _296_recIdents = _out243; - _297___v113 = _out244; + (this).GenStmts(_292_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _298_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out242, out _out243, out _out244); + _299_recursiveGen = _out242; + _300_recIdents = _out243; + _301___v113 = _out244; readIdents = Dafny.Set>.FromElements(); - _296_recIdents = Dafny.Set>.Difference(_296_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_298_paramNames) => ((System.Func>>)(() => { + _300_recIdents = Dafny.Set>.Difference(_300_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_302_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); - foreach (Dafny.ISequence _compr_0 in (_298_paramNames).CloneAsArray()) { - Dafny.ISequence _299_name = (Dafny.ISequence)_compr_0; - if ((_298_paramNames).Contains(_299_name)) { - _coll0.Add(_299_name); + foreach (Dafny.ISequence _compr_0 in (_302_paramNames).CloneAsArray()) { + Dafny.ISequence _303_name = (Dafny.ISequence)_compr_0; + if ((_302_paramNames).Contains(_303_name)) { + _coll0.Add(_303_name); } } return Dafny.Set>.FromCollection(_coll0); - }))())(_290_paramNames)); - RAST._IExpr _300_allReadCloned; - _300_allReadCloned = (this).InitEmptyExpr(); - while (!(_296_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _301_next; - foreach (Dafny.ISequence _assign_such_that_1 in (_296_recIdents).Elements) { - _301_next = (Dafny.ISequence)_assign_such_that_1; - if ((_296_recIdents).Contains(_301_next)) { + }))())(_294_paramNames)); + RAST._IExpr _304_allReadCloned; + _304_allReadCloned = (this).InitEmptyExpr(); + while (!(_300_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _305_next; + foreach (Dafny.ISequence _assign_such_that_1 in (_300_recIdents).Elements) { + _305_next = (Dafny.ISequence)_assign_such_that_1; + if ((_300_recIdents).Contains(_305_next)) { goto after__ASSIGN_SUCH_THAT_1; } } throw new System.Exception("assign-such-that search produced no value"); after__ASSIGN_SUCH_THAT_1: ; - if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_301_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { - RAST._IExpr _302_selfCloned; - Defs._IOwnership _303___v114; - Dafny.ISet> _304___v115; + if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_305_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { + RAST._IExpr _306_selfCloned; + Defs._IOwnership _307___v114; + Dafny.ISet> _308___v115; RAST._IExpr _out245; Defs._IOwnership _out246; Dafny.ISet> _out247; (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out245, out _out246, out _out247); - _302_selfCloned = _out245; - _303___v114 = _out246; - _304___v115 = _out247; - _300_allReadCloned = (_300_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_302_selfCloned))); - } else if (!((_290_paramNames).Contains(_301_next))) { - RAST._IExpr _305_copy; - _305_copy = (RAST.Expr.create_Identifier(_301_next)).Clone(); - _300_allReadCloned = (_300_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _301_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_305_copy))); - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_301_next)); + _306_selfCloned = _out245; + _307___v114 = _out246; + _308___v115 = _out247; + _304_allReadCloned = (_304_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_306_selfCloned))); + } else if (!((_294_paramNames).Contains(_305_next))) { + RAST._IExpr _309_copy; + _309_copy = (RAST.Expr.create_Identifier(_305_next)).Clone(); + _304_allReadCloned = (_304_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _305_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_309_copy))); + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_305_next)); } - _296_recIdents = Dafny.Set>.Difference(_296_recIdents, Dafny.Set>.FromElements(_301_next)); + _300_recIdents = Dafny.Set>.Difference(_300_recIdents, Dafny.Set>.FromElements(_305_next)); } - RAST._IType _306_retTypeGen; + RAST._IType _310_retTypeGen; RAST._IType _out248; - _out248 = (this).GenType(_287_retType, Defs.GenTypeContext.@default()); - _306_retTypeGen = _out248; - r = RAST.Expr.create_Block((_300_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_289_params, Std.Wrappers.Option.create_Some(_306_retTypeGen), RAST.Expr.create_Block(_295_recursiveGen))))); + _out248 = (this).GenType(_291_retType, Defs.GenTypeContext.@default()); + _310_retTypeGen = _out248; + r = RAST.Expr.create_Block((_304_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_293_params, Std.Wrappers.Option.create_Some(_310_retTypeGen), RAST.Expr.create_Block(_299_recursiveGen))))); RAST._IExpr _out249; Defs._IOwnership _out250; (this).FromOwned(r, expectedOwnership, out _out249, out _out250); @@ -6461,72 +6465,72 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_BetaRedex) { - Dafny.ISequence<_System._ITuple2> _307_values = _source0.dtor_values; - DAST._IType _308_retType = _source0.dtor_retType; - DAST._IExpression _309_expr = _source0.dtor_expr; + Dafny.ISequence<_System._ITuple2> _311_values = _source0.dtor_values; + DAST._IType _312_retType = _source0.dtor_retType; + DAST._IExpression _313_expr = _source0.dtor_expr; { - Dafny.ISequence> _310_paramNames; - _310_paramNames = Dafny.Sequence>.FromElements(); - Dafny.ISequence _311_paramFormals; + Dafny.ISequence> _314_paramNames; + _314_paramNames = Dafny.Sequence>.FromElements(); + Dafny.ISequence _315_paramFormals; Dafny.ISequence _out251; - _out251 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_312_value) => { - return (_312_value).dtor__0; - })), _307_values), Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_312_value) => { - return (_312_value).dtor__0; - })), _307_values), false); - _311_paramFormals = _out251; - Dafny.IMap,RAST._IType> _313_paramTypes; - _313_paramTypes = Dafny.Map, RAST._IType>.FromElements(); - Dafny.ISet> _314_paramNamesSet; - _314_paramNamesSet = Dafny.Set>.FromElements(); - BigInteger _hi14 = new BigInteger((_307_values).Count); - for (BigInteger _315_i = BigInteger.Zero; _315_i < _hi14; _315_i++) { - Dafny.ISequence _316_name; - _316_name = (((_307_values).Select(_315_i)).dtor__0).dtor_name; - Dafny.ISequence _317_rName; - _317_rName = Defs.__default.escapeVar(_316_name); - _310_paramNames = Dafny.Sequence>.Concat(_310_paramNames, Dafny.Sequence>.FromElements(_317_rName)); - _313_paramTypes = Dafny.Map, RAST._IType>.Update(_313_paramTypes, _317_rName, ((_311_paramFormals).Select(_315_i)).dtor_tpe); - _314_paramNamesSet = Dafny.Set>.Union(_314_paramNamesSet, Dafny.Set>.FromElements(_317_rName)); + _out251 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_316_value) => { + return (_316_value).dtor__0; + })), _311_values), Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_316_value) => { + return (_316_value).dtor__0; + })), _311_values), false); + _315_paramFormals = _out251; + Dafny.IMap,RAST._IType> _317_paramTypes; + _317_paramTypes = Dafny.Map, RAST._IType>.FromElements(); + Dafny.ISet> _318_paramNamesSet; + _318_paramNamesSet = Dafny.Set>.FromElements(); + BigInteger _hi14 = new BigInteger((_311_values).Count); + for (BigInteger _319_i = BigInteger.Zero; _319_i < _hi14; _319_i++) { + Dafny.ISequence _320_name; + _320_name = (((_311_values).Select(_319_i)).dtor__0).dtor_name; + Dafny.ISequence _321_rName; + _321_rName = Defs.__default.escapeVar(_320_name); + _314_paramNames = Dafny.Sequence>.Concat(_314_paramNames, Dafny.Sequence>.FromElements(_321_rName)); + _317_paramTypes = Dafny.Map, RAST._IType>.Update(_317_paramTypes, _321_rName, ((_315_paramFormals).Select(_319_i)).dtor_tpe); + _318_paramNamesSet = Dafny.Set>.Union(_318_paramNamesSet, Dafny.Set>.FromElements(_321_rName)); } readIdents = Dafny.Set>.FromElements(); r = (this).InitEmptyExpr(); - BigInteger _hi15 = new BigInteger((_307_values).Count); - for (BigInteger _318_i = BigInteger.Zero; _318_i < _hi15; _318_i++) { - RAST._IType _319_typeGen; + BigInteger _hi15 = new BigInteger((_311_values).Count); + for (BigInteger _322_i = BigInteger.Zero; _322_i < _hi15; _322_i++) { + RAST._IType _323_typeGen; RAST._IType _out252; - _out252 = (this).GenType((((_307_values).Select(_318_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); - _319_typeGen = _out252; - RAST._IExpr _320_valueGen; - Defs._IOwnership _321___v116; - Dafny.ISet> _322_recIdents; + _out252 = (this).GenType((((_311_values).Select(_322_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); + _323_typeGen = _out252; + RAST._IExpr _324_valueGen; + Defs._IOwnership _325___v116; + Dafny.ISet> _326_recIdents; RAST._IExpr _out253; Defs._IOwnership _out254; Dafny.ISet> _out255; - (this).GenExpr(((_307_values).Select(_318_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out253, out _out254, out _out255); - _320_valueGen = _out253; - _321___v116 = _out254; - _322_recIdents = _out255; - r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_307_values).Select(_318_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_319_typeGen), Std.Wrappers.Option.create_Some(_320_valueGen))); - readIdents = Dafny.Set>.Union(readIdents, _322_recIdents); - } - Defs._IEnvironment _323_newEnv; - _323_newEnv = Defs.Environment.create(_310_paramNames, _313_paramTypes, Dafny.Set>.FromElements()); - RAST._IExpr _324_recGen; - Defs._IOwnership _325_recOwned; - Dafny.ISet> _326_recIdents; + (this).GenExpr(((_311_values).Select(_322_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out253, out _out254, out _out255); + _324_valueGen = _out253; + _325___v116 = _out254; + _326_recIdents = _out255; + r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_311_values).Select(_322_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_323_typeGen), Std.Wrappers.Option.create_Some(_324_valueGen))); + readIdents = Dafny.Set>.Union(readIdents, _326_recIdents); + } + Defs._IEnvironment _327_newEnv; + _327_newEnv = Defs.Environment.create(_314_paramNames, _317_paramTypes, Dafny.Set>.FromElements()); + RAST._IExpr _328_recGen; + Defs._IOwnership _329_recOwned; + Dafny.ISet> _330_recIdents; RAST._IExpr _out256; Defs._IOwnership _out257; Dafny.ISet> _out258; - (this).GenExpr(_309_expr, selfIdent, _323_newEnv, expectedOwnership, out _out256, out _out257, out _out258); - _324_recGen = _out256; - _325_recOwned = _out257; - _326_recIdents = _out258; - readIdents = Dafny.Set>.Difference(_326_recIdents, _314_paramNamesSet); - r = RAST.Expr.create_Block((r).Then(_324_recGen)); + (this).GenExpr(_313_expr, selfIdent, _327_newEnv, expectedOwnership, out _out256, out _out257, out _out258); + _328_recGen = _out256; + _329_recOwned = _out257; + _330_recIdents = _out258; + readIdents = Dafny.Set>.Difference(_330_recIdents, _318_paramNamesSet); + r = RAST.Expr.create_Block((r).Then(_328_recGen)); RAST._IExpr _out259; Defs._IOwnership _out260; - (this).FromOwnership(r, _325_recOwned, expectedOwnership, out _out259, out _out260); + (this).FromOwnership(r, _329_recOwned, expectedOwnership, out _out259, out _out260); r = _out259; resultingOwnership = _out260; return ; @@ -6536,40 +6540,40 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IIFE) { - Dafny.ISequence _327_name = _source0.dtor_ident; - DAST._IType _328_tpe = _source0.dtor_typ; - DAST._IExpression _329_value = _source0.dtor_value; - DAST._IExpression _330_iifeBody = _source0.dtor_iifeBody; + Dafny.ISequence _331_name = _source0.dtor_ident; + DAST._IType _332_tpe = _source0.dtor_typ; + DAST._IExpression _333_value = _source0.dtor_value; + DAST._IExpression _334_iifeBody = _source0.dtor_iifeBody; { - RAST._IExpr _331_valueGen; - Defs._IOwnership _332___v117; - Dafny.ISet> _333_recIdents; + RAST._IExpr _335_valueGen; + Defs._IOwnership _336___v117; + Dafny.ISet> _337_recIdents; RAST._IExpr _out261; Defs._IOwnership _out262; Dafny.ISet> _out263; - (this).GenExpr(_329_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out261, out _out262, out _out263); - _331_valueGen = _out261; - _332___v117 = _out262; - _333_recIdents = _out263; - readIdents = _333_recIdents; - RAST._IType _334_valueTypeGen; + (this).GenExpr(_333_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out261, out _out262, out _out263); + _335_valueGen = _out261; + _336___v117 = _out262; + _337_recIdents = _out263; + readIdents = _337_recIdents; + RAST._IType _338_valueTypeGen; RAST._IType _out264; - _out264 = (this).GenType(_328_tpe, Defs.GenTypeContext.@default()); - _334_valueTypeGen = _out264; - Dafny.ISequence _335_iifeVar; - _335_iifeVar = Defs.__default.escapeVar(_327_name); - RAST._IExpr _336_bodyGen; - Defs._IOwnership _337___v118; - Dafny.ISet> _338_bodyIdents; + _out264 = (this).GenType(_332_tpe, Defs.GenTypeContext.@default()); + _338_valueTypeGen = _out264; + Dafny.ISequence _339_iifeVar; + _339_iifeVar = Defs.__default.escapeVar(_331_name); + RAST._IExpr _340_bodyGen; + Defs._IOwnership _341___v118; + Dafny.ISet> _342_bodyIdents; RAST._IExpr _out265; Defs._IOwnership _out266; Dafny.ISet> _out267; - (this).GenExpr(_330_iifeBody, selfIdent, (env).AddAssigned(_335_iifeVar, _334_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out265, out _out266, out _out267); - _336_bodyGen = _out265; - _337___v118 = _out266; - _338_bodyIdents = _out267; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_338_bodyIdents, Dafny.Set>.FromElements(_335_iifeVar))); - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _335_iifeVar, Std.Wrappers.Option.create_Some(_334_valueTypeGen), Std.Wrappers.Option.create_Some(_331_valueGen))).Then(_336_bodyGen)); + (this).GenExpr(_334_iifeBody, selfIdent, (env).AddAssigned(_339_iifeVar, _338_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out265, out _out266, out _out267); + _340_bodyGen = _out265; + _341___v118 = _out266; + _342_bodyIdents = _out267; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_342_bodyIdents, Dafny.Set>.FromElements(_339_iifeVar))); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _339_iifeVar, Std.Wrappers.Option.create_Some(_338_valueTypeGen), Std.Wrappers.Option.create_Some(_335_valueGen))).Then(_340_bodyGen)); RAST._IExpr _out268; Defs._IOwnership _out269; (this).FromOwned(r, expectedOwnership, out _out268, out _out269); @@ -6582,38 +6586,38 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Apply) { - DAST._IExpression _339_func = _source0.dtor_expr; - Dafny.ISequence _340_args = _source0.dtor_args; + DAST._IExpression _343_func = _source0.dtor_expr; + Dafny.ISequence _344_args = _source0.dtor_args; { - RAST._IExpr _341_funcExpr; - Defs._IOwnership _342___v119; - Dafny.ISet> _343_recIdents; + RAST._IExpr _345_funcExpr; + Defs._IOwnership _346___v119; + Dafny.ISet> _347_recIdents; RAST._IExpr _out270; Defs._IOwnership _out271; Dafny.ISet> _out272; - (this).GenExpr(_339_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out270, out _out271, out _out272); - _341_funcExpr = _out270; - _342___v119 = _out271; - _343_recIdents = _out272; - readIdents = _343_recIdents; - Dafny.ISequence _344_rArgs; - _344_rArgs = Dafny.Sequence.FromElements(); - BigInteger _hi16 = new BigInteger((_340_args).Count); - for (BigInteger _345_i = BigInteger.Zero; _345_i < _hi16; _345_i++) { - RAST._IExpr _346_argExpr; - Defs._IOwnership _347_argOwned; - Dafny.ISet> _348_argIdents; + (this).GenExpr(_343_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out270, out _out271, out _out272); + _345_funcExpr = _out270; + _346___v119 = _out271; + _347_recIdents = _out272; + readIdents = _347_recIdents; + Dafny.ISequence _348_rArgs; + _348_rArgs = Dafny.Sequence.FromElements(); + BigInteger _hi16 = new BigInteger((_344_args).Count); + for (BigInteger _349_i = BigInteger.Zero; _349_i < _hi16; _349_i++) { + RAST._IExpr _350_argExpr; + Defs._IOwnership _351_argOwned; + Dafny.ISet> _352_argIdents; RAST._IExpr _out273; Defs._IOwnership _out274; Dafny.ISet> _out275; - (this).GenExpr((_340_args).Select(_345_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out273, out _out274, out _out275); - _346_argExpr = _out273; - _347_argOwned = _out274; - _348_argIdents = _out275; - _344_rArgs = Dafny.Sequence.Concat(_344_rArgs, Dafny.Sequence.FromElements(_346_argExpr)); - readIdents = Dafny.Set>.Union(readIdents, _348_argIdents); - } - r = (_341_funcExpr).Apply(_344_rArgs); + (this).GenExpr((_344_args).Select(_349_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out273, out _out274, out _out275); + _350_argExpr = _out273; + _351_argOwned = _out274; + _352_argIdents = _out275; + _348_rArgs = Dafny.Sequence.Concat(_348_rArgs, Dafny.Sequence.FromElements(_350_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _352_argIdents); + } + r = (_345_funcExpr).Apply(_348_rArgs); RAST._IExpr _out276; Defs._IOwnership _out277; (this).FromOwned(r, expectedOwnership, out _out276, out _out277); @@ -6626,31 +6630,31 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TypeTest) { - DAST._IExpression _349_on = _source0.dtor_on; - Dafny.ISequence> _350_dType = _source0.dtor_dType; - Dafny.ISequence _351_variant = _source0.dtor_variant; + DAST._IExpression _353_on = _source0.dtor_on; + Dafny.ISequence> _354_dType = _source0.dtor_dType; + Dafny.ISequence _355_variant = _source0.dtor_variant; { - RAST._IExpr _352_exprGen; - Defs._IOwnership _353___v120; - Dafny.ISet> _354_recIdents; + RAST._IExpr _356_exprGen; + Defs._IOwnership _357___v120; + Dafny.ISet> _358_recIdents; RAST._IExpr _out278; Defs._IOwnership _out279; Dafny.ISet> _out280; - (this).GenExpr(_349_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out278, out _out279, out _out280); - _352_exprGen = _out278; - _353___v120 = _out279; - _354_recIdents = _out280; - RAST._IExpr _355_variantExprPath; + (this).GenExpr(_353_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out278, out _out279, out _out280); + _356_exprGen = _out278; + _357___v120 = _out279; + _358_recIdents = _out280; + RAST._IExpr _359_variantExprPath; RAST._IExpr _out281; - _out281 = (this).GenPathExpr(Dafny.Sequence>.Concat(_350_dType, Dafny.Sequence>.FromElements(_351_variant)), true); - _355_variantExprPath = _out281; - r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_352_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _355_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); + _out281 = (this).GenPathExpr(Dafny.Sequence>.Concat(_354_dType, Dafny.Sequence>.FromElements(_355_variant)), true); + _359_variantExprPath = _out281; + r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_356_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _359_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); RAST._IExpr _out282; Defs._IOwnership _out283; (this).FromOwned(r, expectedOwnership, out _out282, out _out283); r = _out282; resultingOwnership = _out283; - readIdents = _354_recIdents; + readIdents = _358_recIdents; return ; } goto after_match0; @@ -6658,77 +6662,77 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Is) { - DAST._IExpression _356_expr = _source0.dtor_expr; - DAST._IType _357_fromTyp = _source0.dtor_fromType; - DAST._IType _358_toTyp = _source0.dtor_toType; + DAST._IExpression _360_expr = _source0.dtor_expr; + DAST._IType _361_fromTyp = _source0.dtor_fromType; + DAST._IType _362_toTyp = _source0.dtor_toType; { - RAST._IType _359_fromTpe; + RAST._IType _363_fromTpe; RAST._IType _out284; - _out284 = (this).GenType(_357_fromTyp, Defs.GenTypeContext.@default()); - _359_fromTpe = _out284; - RAST._IType _360_toTpe; + _out284 = (this).GenType(_361_fromTyp, Defs.GenTypeContext.@default()); + _363_fromTpe = _out284; + RAST._IType _364_toTpe; RAST._IType _out285; - _out285 = (this).GenType(_358_toTyp, Defs.GenTypeContext.@default()); - _360_toTpe = _out285; - if (((_359_fromTpe).IsObjectOrPointer()) && ((_360_toTpe).IsObjectOrPointer())) { - RAST._IExpr _361_expr; - Defs._IOwnership _362_recOwned; - Dafny.ISet> _363_recIdents; + _out285 = (this).GenType(_362_toTyp, Defs.GenTypeContext.@default()); + _364_toTpe = _out285; + if (((_363_fromTpe).IsObjectOrPointer()) && ((_364_toTpe).IsObjectOrPointer())) { + RAST._IExpr _365_expr; + Defs._IOwnership _366_recOwned; + Dafny.ISet> _367_recIdents; RAST._IExpr _out286; Defs._IOwnership _out287; Dafny.ISet> _out288; - (this).GenExpr(_356_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out286, out _out287, out _out288); - _361_expr = _out286; - _362_recOwned = _out287; - _363_recIdents = _out288; - r = (((_361_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_360_toTpe).ObjectOrPointerUnderlying()))).Apply0(); + (this).GenExpr(_360_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out286, out _out287, out _out288); + _365_expr = _out286; + _366_recOwned = _out287; + _367_recIdents = _out288; + r = (((_365_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_364_toTpe).ObjectOrPointerUnderlying()))).Apply0(); RAST._IExpr _out289; Defs._IOwnership _out290; - (this).FromOwnership(r, _362_recOwned, expectedOwnership, out _out289, out _out290); + (this).FromOwnership(r, _366_recOwned, expectedOwnership, out _out289, out _out290); r = _out289; resultingOwnership = _out290; - readIdents = _363_recIdents; + readIdents = _367_recIdents; } else { - RAST._IExpr _364_expr; - Defs._IOwnership _365_recOwned; - Dafny.ISet> _366_recIdents; + RAST._IExpr _368_expr; + Defs._IOwnership _369_recOwned; + Dafny.ISet> _370_recIdents; RAST._IExpr _out291; Defs._IOwnership _out292; Dafny.ISet> _out293; - (this).GenExpr(_356_expr, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out291, out _out292, out _out293); - _364_expr = _out291; - _365_recOwned = _out292; - _366_recIdents = _out293; - bool _367_isDatatype; - _367_isDatatype = (_358_toTyp).IsDatatype(); - bool _368_isGeneralTrait; - _368_isGeneralTrait = (!(_367_isDatatype)) && ((_358_toTyp).IsGeneralTrait()); - if ((_367_isDatatype) || (_368_isGeneralTrait)) { - bool _369_isDowncast; - _369_isDowncast = (_358_toTyp).Extends(_357_fromTyp); - if (_369_isDowncast) { - DAST._IType _370_underlyingType; - if (_367_isDatatype) { - _370_underlyingType = (_358_toTyp).GetDatatypeType(); + (this).GenExpr(_360_expr, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out291, out _out292, out _out293); + _368_expr = _out291; + _369_recOwned = _out292; + _370_recIdents = _out293; + bool _371_isDatatype; + _371_isDatatype = (_362_toTyp).IsDatatype(); + bool _372_isGeneralTrait; + _372_isGeneralTrait = (!(_371_isDatatype)) && ((_362_toTyp).IsGeneralTrait()); + if ((_371_isDatatype) || (_372_isGeneralTrait)) { + bool _373_isDowncast; + _373_isDowncast = (_362_toTyp).Extends(_361_fromTyp); + if (_373_isDowncast) { + DAST._IType _374_underlyingType; + if (_371_isDatatype) { + _374_underlyingType = (_362_toTyp).GetDatatypeType(); } else { - _370_underlyingType = (_358_toTyp).GetGeneralTraitType(); + _374_underlyingType = (_362_toTyp).GetGeneralTraitType(); } - RAST._IType _371_toTpeRaw; + RAST._IType _375_toTpeRaw; RAST._IType _out294; - _out294 = (this).GenType(_370_underlyingType, Defs.GenTypeContext.@default()); - _371_toTpeRaw = _out294; - Std.Wrappers._IOption _372_toTpeRawDowncastOpt; - _372_toTpeRawDowncastOpt = (_371_toTpeRaw).ToDowncastExpr(); - if ((_372_toTpeRawDowncastOpt).is_Some) { - _364_expr = (this).FromGeneralBorrowToSelfBorrow(_364_expr, Defs.Ownership.create_OwnershipBorrowed(), env); - if (_367_isDatatype) { - _364_expr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_364_expr); + _out294 = (this).GenType(_374_underlyingType, Defs.GenTypeContext.@default()); + _375_toTpeRaw = _out294; + Std.Wrappers._IOption _376_toTpeRawDowncastOpt; + _376_toTpeRawDowncastOpt = (_375_toTpeRaw).ToDowncastExpr(); + if ((_376_toTpeRawDowncastOpt).is_Some) { + _368_expr = (this).FromGeneralBorrowToSelfBorrow(_368_expr, Defs.Ownership.create_OwnershipBorrowed(), env); + if (_371_isDatatype) { + _368_expr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_368_expr); } - r = (((_372_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_364_expr); - _365_recOwned = Defs.Ownership.create_OwnershipOwned(); + r = (((_376_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_368_expr); + _369_recOwned = Defs.Ownership.create_OwnershipOwned(); } else { RAST._IExpr _out295; - _out295 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_371_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); + _out295 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_375_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); r = _out295; } } else { @@ -6743,10 +6747,10 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } RAST._IExpr _out298; Defs._IOwnership _out299; - (this).FromOwnership(r, _365_recOwned, expectedOwnership, out _out298, out _out299); + (this).FromOwnership(r, _369_recOwned, expectedOwnership, out _out298, out _out299); r = _out298; resultingOwnership = _out299; - readIdents = _366_recIdents; + readIdents = _370_recIdents; } return ; } @@ -6770,25 +6774,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBoundedPool) { - DAST._IExpression _373_of = _source0.dtor_of; + DAST._IExpression _377_of = _source0.dtor_of; { - RAST._IExpr _374_exprGen; - Defs._IOwnership _375___v121; - Dafny.ISet> _376_recIdents; + RAST._IExpr _378_exprGen; + Defs._IOwnership _379___v121; + Dafny.ISet> _380_recIdents; RAST._IExpr _out302; Defs._IOwnership _out303; Dafny.ISet> _out304; - (this).GenExpr(_373_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); - _374_exprGen = _out302; - _375___v121 = _out303; - _376_recIdents = _out304; - r = ((_374_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); + _378_exprGen = _out302; + _379___v121 = _out303; + _380_recIdents = _out304; + r = ((_378_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out305; Defs._IOwnership _out306; (this).FromOwned(r, expectedOwnership, out _out305, out _out306); r = _out305; resultingOwnership = _out306; - readIdents = _376_recIdents; + readIdents = _380_recIdents; return ; } goto after_match0; @@ -6796,21 +6800,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SeqBoundedPool) { - DAST._IExpression _377_of = _source0.dtor_of; - bool _378_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _381_of = _source0.dtor_of; + bool _382_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _379_exprGen; - Defs._IOwnership _380___v122; - Dafny.ISet> _381_recIdents; + RAST._IExpr _383_exprGen; + Defs._IOwnership _384___v122; + Dafny.ISet> _385_recIdents; RAST._IExpr _out307; Defs._IOwnership _out308; Dafny.ISet> _out309; - (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out307, out _out308, out _out309); - _379_exprGen = _out307; - _380___v122 = _out308; - _381_recIdents = _out309; - r = ((_379_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_378_includeDuplicates)) { + (this).GenExpr(_381_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out307, out _out308, out _out309); + _383_exprGen = _out307; + _384___v122 = _out308; + _385_recIdents = _out309; + r = ((_383_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_382_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } RAST._IExpr _out310; @@ -6818,7 +6822,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir (this).FromOwned(r, expectedOwnership, out _out310, out _out311); r = _out310; resultingOwnership = _out311; - readIdents = _381_recIdents; + readIdents = _385_recIdents; return ; } goto after_match0; @@ -6826,21 +6830,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MultisetBoundedPool) { - DAST._IExpression _382_of = _source0.dtor_of; - bool _383_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _386_of = _source0.dtor_of; + bool _387_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _384_exprGen; - Defs._IOwnership _385___v123; - Dafny.ISet> _386_recIdents; + RAST._IExpr _388_exprGen; + Defs._IOwnership _389___v123; + Dafny.ISet> _390_recIdents; RAST._IExpr _out312; Defs._IOwnership _out313; Dafny.ISet> _out314; - (this).GenExpr(_382_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out312, out _out313, out _out314); - _384_exprGen = _out312; - _385___v123 = _out313; - _386_recIdents = _out314; - r = ((_384_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_383_includeDuplicates)) { + (this).GenExpr(_386_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out312, out _out313, out _out314); + _388_exprGen = _out312; + _389___v123 = _out313; + _390_recIdents = _out314; + r = ((_388_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_387_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } RAST._IExpr _out315; @@ -6848,7 +6852,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir (this).FromOwned(r, expectedOwnership, out _out315, out _out316); r = _out315; resultingOwnership = _out316; - readIdents = _386_recIdents; + readIdents = _390_recIdents; return ; } goto after_match0; @@ -6856,20 +6860,20 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBoundedPool) { - DAST._IExpression _387_of = _source0.dtor_of; + DAST._IExpression _391_of = _source0.dtor_of; { - RAST._IExpr _388_exprGen; - Defs._IOwnership _389___v124; - Dafny.ISet> _390_recIdents; + RAST._IExpr _392_exprGen; + Defs._IOwnership _393___v124; + Dafny.ISet> _394_recIdents; RAST._IExpr _out317; Defs._IOwnership _out318; Dafny.ISet> _out319; - (this).GenExpr(_387_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out317, out _out318, out _out319); - _388_exprGen = _out317; - _389___v124 = _out318; - _390_recIdents = _out319; - r = ((((_388_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - readIdents = _390_recIdents; + (this).GenExpr(_391_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out317, out _out318, out _out319); + _392_exprGen = _out317; + _393___v124 = _out318; + _394_recIdents = _out319; + r = ((((_392_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + readIdents = _394_recIdents; RAST._IExpr _out320; Defs._IOwnership _out321; (this).FromOwned(r, expectedOwnership, out _out320, out _out321); @@ -6881,20 +6885,20 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_ExactBoundedPool) { - DAST._IExpression _391_of = _source0.dtor_of; + DAST._IExpression _395_of = _source0.dtor_of; { - RAST._IExpr _392_exprGen; - Defs._IOwnership _393___v125; - Dafny.ISet> _394_recIdents; + RAST._IExpr _396_exprGen; + Defs._IOwnership _397___v125; + Dafny.ISet> _398_recIdents; RAST._IExpr _out322; Defs._IOwnership _out323; Dafny.ISet> _out324; - (this).GenExpr(_391_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out322, out _out323, out _out324); - _392_exprGen = _out322; - _393___v125 = _out323; - _394_recIdents = _out324; - r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_392_exprGen); - readIdents = _394_recIdents; + (this).GenExpr(_395_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out322, out _out323, out _out324); + _396_exprGen = _out322; + _397___v125 = _out323; + _398_recIdents = _out324; + r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_396_exprGen); + readIdents = _398_recIdents; RAST._IExpr _out325; Defs._IOwnership _out326; (this).FromOwned(r, expectedOwnership, out _out325, out _out326); @@ -6906,49 +6910,49 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IntRange) { - DAST._IType _395_typ = _source0.dtor_elemType; - DAST._IExpression _396_lo = _source0.dtor_lo; - DAST._IExpression _397_hi = _source0.dtor_hi; - bool _398_up = _source0.dtor_up; + DAST._IType _399_typ = _source0.dtor_elemType; + DAST._IExpression _400_lo = _source0.dtor_lo; + DAST._IExpression _401_hi = _source0.dtor_hi; + bool _402_up = _source0.dtor_up; { - RAST._IExpr _399_lo; - Defs._IOwnership _400___v126; - Dafny.ISet> _401_recIdentsLo; + RAST._IExpr _403_lo; + Defs._IOwnership _404___v126; + Dafny.ISet> _405_recIdentsLo; RAST._IExpr _out327; Defs._IOwnership _out328; Dafny.ISet> _out329; - (this).GenExpr(_396_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out327, out _out328, out _out329); - _399_lo = _out327; - _400___v126 = _out328; - _401_recIdentsLo = _out329; - RAST._IExpr _402_hi; - Defs._IOwnership _403___v127; - Dafny.ISet> _404_recIdentsHi; + (this).GenExpr(_400_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out327, out _out328, out _out329); + _403_lo = _out327; + _404___v126 = _out328; + _405_recIdentsLo = _out329; + RAST._IExpr _406_hi; + Defs._IOwnership _407___v127; + Dafny.ISet> _408_recIdentsHi; RAST._IExpr _out330; Defs._IOwnership _out331; Dafny.ISet> _out332; - (this).GenExpr(_397_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out330, out _out331, out _out332); - _402_hi = _out330; - _403___v127 = _out331; - _404_recIdentsHi = _out332; - if (_398_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_399_lo, _402_hi)); + (this).GenExpr(_401_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out330, out _out331, out _out332); + _406_hi = _out330; + _407___v127 = _out331; + _408_recIdentsHi = _out332; + if (_402_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_403_lo, _406_hi)); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_402_hi, _399_lo)); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_406_hi, _403_lo)); } - if (!((_395_typ).is_Primitive)) { - RAST._IType _405_tpe; + if (!((_399_typ).is_Primitive)) { + RAST._IType _409_tpe; RAST._IType _out333; - _out333 = (this).GenType(_395_typ, Defs.GenTypeContext.@default()); - _405_tpe = _out333; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_405_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); + _out333 = (this).GenType(_399_typ, Defs.GenTypeContext.@default()); + _409_tpe = _out333; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_409_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); } RAST._IExpr _out334; Defs._IOwnership _out335; (this).FromOwned(r, expectedOwnership, out _out334, out _out335); r = _out334; resultingOwnership = _out335; - readIdents = Dafny.Set>.Union(_401_recIdentsLo, _404_recIdentsHi); + readIdents = Dafny.Set>.Union(_405_recIdentsLo, _408_recIdentsHi); return ; } goto after_match0; @@ -6956,30 +6960,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_UnboundedIntRange) { - DAST._IExpression _406_start = _source0.dtor_start; - bool _407_up = _source0.dtor_up; + DAST._IExpression _410_start = _source0.dtor_start; + bool _411_up = _source0.dtor_up; { - RAST._IExpr _408_start; - Defs._IOwnership _409___v128; - Dafny.ISet> _410_recIdentStart; + RAST._IExpr _412_start; + Defs._IOwnership _413___v128; + Dafny.ISet> _414_recIdentStart; RAST._IExpr _out336; Defs._IOwnership _out337; Dafny.ISet> _out338; - (this).GenExpr(_406_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out336, out _out337, out _out338); - _408_start = _out336; - _409___v128 = _out337; - _410_recIdentStart = _out338; - if (_407_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_408_start); + (this).GenExpr(_410_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out336, out _out337, out _out338); + _412_start = _out336; + _413___v128 = _out337; + _414_recIdentStart = _out338; + if (_411_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_412_start); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_408_start); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_412_start); } RAST._IExpr _out339; Defs._IOwnership _out340; (this).FromOwned(r, expectedOwnership, out _out339, out _out340); r = _out339; resultingOwnership = _out340; - readIdents = _410_recIdentStart; + readIdents = _414_recIdentStart; return ; } goto after_match0; @@ -6987,18 +6991,18 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBuilder) { - DAST._IType _411_keyType = _source0.dtor_keyType; - DAST._IType _412_valueType = _source0.dtor_valueType; + DAST._IType _415_keyType = _source0.dtor_keyType; + DAST._IType _416_valueType = _source0.dtor_valueType; { - RAST._IType _413_kType; + RAST._IType _417_kType; RAST._IType _out341; - _out341 = (this).GenType(_411_keyType, Defs.GenTypeContext.@default()); - _413_kType = _out341; - RAST._IType _414_vType; + _out341 = (this).GenType(_415_keyType, Defs.GenTypeContext.@default()); + _417_kType = _out341; + RAST._IType _418_vType; RAST._IType _out342; - _out342 = (this).GenType(_412_valueType, Defs.GenTypeContext.@default()); - _414_vType = _out342; - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_413_kType, _414_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + _out342 = (this).GenType(_416_valueType, Defs.GenTypeContext.@default()); + _418_vType = _out342; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_417_kType, _418_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); RAST._IExpr _out343; Defs._IOwnership _out344; (this).FromOwned(r, expectedOwnership, out _out343, out _out344); @@ -7012,14 +7016,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBuilder) { - DAST._IType _415_elemType = _source0.dtor_elemType; + DAST._IType _419_elemType = _source0.dtor_elemType; { - RAST._IType _416_eType; + RAST._IType _420_eType; RAST._IType _out345; - _out345 = (this).GenType(_415_elemType, Defs.GenTypeContext.@default()); - _416_eType = _out345; + _out345 = (this).GenType(_419_elemType, Defs.GenTypeContext.@default()); + _420_eType = _out345; readIdents = Dafny.Set>.FromElements(); - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_416_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_420_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); RAST._IExpr _out346; Defs._IOwnership _out347; (this).FromOwned(r, expectedOwnership, out _out346, out _out347); @@ -7031,63 +7035,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } } { - DAST._IType _417_elemType = _source0.dtor_elemType; - DAST._IExpression _418_collection = _source0.dtor_collection; - bool _419_is__forall = _source0.dtor_is__forall; - DAST._IExpression _420_lambda = _source0.dtor_lambda; + DAST._IType _421_elemType = _source0.dtor_elemType; + DAST._IExpression _422_collection = _source0.dtor_collection; + bool _423_is__forall = _source0.dtor_is__forall; + DAST._IExpression _424_lambda = _source0.dtor_lambda; { - RAST._IType _421_tpe; + RAST._IType _425_tpe; RAST._IType _out348; - _out348 = (this).GenType(_417_elemType, Defs.GenTypeContext.@default()); - _421_tpe = _out348; - RAST._IExpr _422_collectionGen; - Defs._IOwnership _423___v129; - Dafny.ISet> _424_recIdents; + _out348 = (this).GenType(_421_elemType, Defs.GenTypeContext.@default()); + _425_tpe = _out348; + RAST._IExpr _426_collectionGen; + Defs._IOwnership _427___v129; + Dafny.ISet> _428_recIdents; RAST._IExpr _out349; Defs._IOwnership _out350; Dafny.ISet> _out351; - (this).GenExpr(_418_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out349, out _out350, out _out351); - _422_collectionGen = _out349; - _423___v129 = _out350; - _424_recIdents = _out351; - Dafny.ISequence _425_extraAttributes; - _425_extraAttributes = Dafny.Sequence.FromElements(); - if ((((((_418_collection).is_IntRange) || ((_418_collection).is_UnboundedIntRange)) || ((_418_collection).is_SeqBoundedPool)) || ((_418_collection).is_ExactBoundedPool)) || ((_418_collection).is_MultisetBoundedPool)) { - _425_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); - } - if ((_420_lambda).is_Lambda) { - Dafny.ISequence _426_formals; - _426_formals = (_420_lambda).dtor_params; - Dafny.ISequence _427_newFormals; - _427_newFormals = Dafny.Sequence.FromElements(); - BigInteger _hi17 = new BigInteger((_426_formals).Count); - for (BigInteger _428_i = BigInteger.Zero; _428_i < _hi17; _428_i++) { - var _pat_let_tv0 = _425_extraAttributes; - var _pat_let_tv1 = _426_formals; - _427_newFormals = Dafny.Sequence.Concat(_427_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_426_formals).Select(_428_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _429_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_428_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _430_dt__update_hattributes_h0 => DAST.Formal.create((_429_dt__update__tmp_h0).dtor_name, (_429_dt__update__tmp_h0).dtor_typ, _430_dt__update_hattributes_h0))))))); - } - DAST._IExpression _431_newLambda; - DAST._IExpression _432_dt__update__tmp_h1 = _420_lambda; - Dafny.ISequence _433_dt__update_hparams_h0 = _427_newFormals; - _431_newLambda = DAST.Expression.create_Lambda(_433_dt__update_hparams_h0, (_432_dt__update__tmp_h1).dtor_retType, (_432_dt__update__tmp_h1).dtor_body); - RAST._IExpr _434_lambdaGen; - Defs._IOwnership _435___v130; - Dafny.ISet> _436_recLambdaIdents; + (this).GenExpr(_422_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out349, out _out350, out _out351); + _426_collectionGen = _out349; + _427___v129 = _out350; + _428_recIdents = _out351; + Dafny.ISequence _429_extraAttributes; + _429_extraAttributes = Dafny.Sequence.FromElements(); + if ((((((_422_collection).is_IntRange) || ((_422_collection).is_UnboundedIntRange)) || ((_422_collection).is_SeqBoundedPool)) || ((_422_collection).is_ExactBoundedPool)) || ((_422_collection).is_MultisetBoundedPool)) { + _429_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); + } + if ((_424_lambda).is_Lambda) { + Dafny.ISequence _430_formals; + _430_formals = (_424_lambda).dtor_params; + Dafny.ISequence _431_newFormals; + _431_newFormals = Dafny.Sequence.FromElements(); + BigInteger _hi17 = new BigInteger((_430_formals).Count); + for (BigInteger _432_i = BigInteger.Zero; _432_i < _hi17; _432_i++) { + var _pat_let_tv0 = _429_extraAttributes; + var _pat_let_tv1 = _430_formals; + _431_newFormals = Dafny.Sequence.Concat(_431_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_430_formals).Select(_432_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _433_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_432_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _434_dt__update_hattributes_h0 => DAST.Formal.create((_433_dt__update__tmp_h0).dtor_name, (_433_dt__update__tmp_h0).dtor_typ, _434_dt__update_hattributes_h0))))))); + } + DAST._IExpression _435_newLambda; + DAST._IExpression _436_dt__update__tmp_h1 = _424_lambda; + Dafny.ISequence _437_dt__update_hparams_h0 = _431_newFormals; + _435_newLambda = DAST.Expression.create_Lambda(_437_dt__update_hparams_h0, (_436_dt__update__tmp_h1).dtor_retType, (_436_dt__update__tmp_h1).dtor_body); + RAST._IExpr _438_lambdaGen; + Defs._IOwnership _439___v130; + Dafny.ISet> _440_recLambdaIdents; RAST._IExpr _out352; Defs._IOwnership _out353; Dafny.ISet> _out354; - (this).GenExpr(_431_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out352, out _out353, out _out354); - _434_lambdaGen = _out352; - _435___v130 = _out353; - _436_recLambdaIdents = _out354; - Dafny.ISequence _437_fn; - if (_419_is__forall) { - _437_fn = Dafny.Sequence.UnicodeFromString("all"); + (this).GenExpr(_435_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out352, out _out353, out _out354); + _438_lambdaGen = _out352; + _439___v130 = _out353; + _440_recLambdaIdents = _out354; + Dafny.ISequence _441_fn; + if (_423_is__forall) { + _441_fn = Dafny.Sequence.UnicodeFromString("all"); } else { - _437_fn = Dafny.Sequence.UnicodeFromString("any"); + _441_fn = Dafny.Sequence.UnicodeFromString("any"); } - r = ((_422_collectionGen).Sel(_437_fn)).Apply1(((_434_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); - readIdents = Dafny.Set>.Union(_424_recIdents, _436_recLambdaIdents); + r = ((_426_collectionGen).Sel(_441_fn)).Apply1(((_438_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); + readIdents = Dafny.Set>.Union(_428_recIdents, _440_recLambdaIdents); } else { RAST._IExpr _out355; _out355 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); From 972929d4d417fcbc2fc4ae29e7b7ff57dc497624 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Tue, 17 Dec 2024 16:14:31 -0600 Subject: [PATCH 33/69] No emitting self-upcastbox if not general trait --- Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy | 4 ++-- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index e986ade29ab..534c95c86f4 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -603,8 +603,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var parents: seq := []; var upcastImplemented: seq := []; - var instantiatedFullType := R.Box(R.DynType(traitFullType)); // TODO: make the object version as well - if instantiatedFullType.IsBox() { // TODO: Make it work also for object traits + var instantiatedFullType := R.Box(R.DynType(traitFullType)); + if t.traitType.GeneralTrait? { // TODO: Make it work also for object traits var upcastDynTrait := UpcastDynTraitFor(rTypeParamsDecls, instantiatedFullType, traitFullType, traitFullExpr); upcastImplemented := upcastImplemented + [upcastDynTrait]; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index f26c7a4da02..4c650f17fef 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -611,7 +611,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _18_upcastImplemented = Dafny.Sequence.FromElements(); RAST._IType _19_instantiatedFullType; _19_instantiatedFullType = RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)); - if ((_19_instantiatedFullType).IsBox()) { + if (((t).dtor_traitType).is_GeneralTrait) { RAST._IModDecl _20_upcastDynTrait; _20_upcastDynTrait = Defs.__default.UpcastDynTraitFor(_1_rTypeParamsDecls, _19_instantiatedFullType, _10_traitFullType, _11_traitFullExpr); _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(_20_upcastDynTrait)); From d507cece5ff97bc0fa1da96e23fe596a0616f28c Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Tue, 24 Dec 2024 10:30:06 -0600 Subject: [PATCH 34/69] Fixed the build --- .../SinglePassCodeGenerator.cs | 2 +- .../CheckTypeCharacteristics_Visitor.cs | 26 ------------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index 6c4525d695b..83347a320a6 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -1443,7 +1443,7 @@ protected virtual void CompileBinOp(BinaryExpr.ResolvedOpcode op, protected virtual void EmitTypeTestExpr(Expression expr, Type fromType, Type toType, IOrigin tok, bool inLetExprBody, ConcreteSyntaxTree wr, ref ConcreteSyntaxTree wStmts) { var name = $"_is_{GetUniqueAstNumber(expr)}"; - wr = CreateIIFE_ExprBody(name, fromType, tok, expr, inLetExprBody, Type.Bool, expr.tok, wr, ref wStmts); + wr = CreateIIFE_ExprBody(name, fromType, tok, expr, inLetExprBody, Type.Bool, expr.Tok, wr, ref wStmts); EmitTypeTest(name, fromType, toType, tok, wr); } diff --git a/Source/DafnyCore/Resolver/CheckTypeCharacteristics_Visitor.cs b/Source/DafnyCore/Resolver/CheckTypeCharacteristics_Visitor.cs index b1c89d1cb22..377e1f76654 100644 --- a/Source/DafnyCore/Resolver/CheckTypeCharacteristics_Visitor.cs +++ b/Source/DafnyCore/Resolver/CheckTypeCharacteristics_Visitor.cs @@ -430,32 +430,6 @@ public static string TypeEqualityErrorMessageHint(Type argType) { } } - if (argType.AsNewtype is { } newTypeDecl) { - return TypeEqualityErrorMessageHint(newTypeDecl.RhsWithArgument(argType.TypeArgs)); - } - - var typeArgs = argType.TypeArgs; - - if (argType.AsSeqType != null && typeArgs.Count >= 1) { - if (TypeEqualityErrorMessageHint(typeArgs[0]) is var messageSeq and not "") { - return messageSeq; - } - } - if (argType.AsMapType != null && - typeArgs.Count >= 2 && - TypeEqualityErrorMessageHint(typeArgs[1]) is var messageMap and not "") { - return messageMap; - } - if (argType.AsIndDatatype is { EqualitySupport: IndDatatypeDecl.ES.ConsultTypeArguments } decl) { - var i = 0; - foreach (var tParam in decl.TypeArgs) { - if (tParam.NecessaryForEqualitySupportOfSurroundingInductiveDatatype && i < typeArgs.Count && !typeArgs[i].SupportsEquality && TypeEqualityErrorMessageHint(typeArgs[i]) is var message and not "") { - return message; - } - i++; - } - } - if (argType.AsNewtype is { } newTypeDecl) { return TypeEqualityErrorMessageHint(newTypeDecl.RhsWithArgument(argType.TypeArgs)); } From 1b70b1f56608315bd452ba375d17e90dea7c4a05 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 3 Jan 2025 05:55:14 -0600 Subject: [PATCH 35/69] Compilation name gets an enclosing module name. Caching of compilation name. Don't copy target file if same path --- .../AST/TypeDeclarations/Declaration.cs | 27 ++++++++++- .../Backends/Dafny/DafnyCodeGenerator.cs | 26 +++++++++-- Source/DafnyCore/Backends/Rust/RustBackend.cs | 6 ++- .../SinglePassCodeGenerator.cs | 5 +++ .../integration- rust/IntegrationRust.md | 45 ++++++++++++++++++- 5 files changed, 102 insertions(+), 7 deletions(-) diff --git a/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs b/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs index 05695e5f1e4..350bdcb6b4a 100644 --- a/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs +++ b/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs @@ -111,17 +111,42 @@ public bool IsVisibleInScope(VisibilityScope scope) { protected string sanitizedName; public virtual string SanitizedName => sanitizedName ??= NonglobalVariable.SanitizeName(Name); + protected string enclosingModuleName; // Computed at the same time as compileName + protected string compileName; public virtual string GetCompileName(DafnyOptions options) { if (compileName == null) { - this.IsExtern(options, out _, out compileName); + this.IsExtern(options, out var possibleEnclosingModuleName, out compileName); + if (!IsCompiled) { + enclosingModuleName = possibleEnclosingModuleName; + } + if (this is TopLevelDecl topDecl) { + enclosingModuleName ??= topDecl.EnclosingModuleDefinition.GetCompileName(options); + } + compileName ??= SanitizedName; } return compileName; } + public bool IsCompiled { + get { + var compile = true; + return !Attributes.ContainsBool(Attributes, "compile", ref compile) || compile; + } + } + + public string GetQualificationName(DafnyOptions options) { + if (compileName == null) { + GetCompileName(options); // Sets the enclosing module name if defined by externs. + return enclosingModuleName; + } + + return enclosingModuleName; + } + public Attributes Attributes; // readonly, except during class merging in the refinement transformations and when changed by Compiler.MarkCapitalizationConflict Attributes IAttributeBearingDeclaration.Attributes { get => Attributes; diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index fa73a8b6f77..995f5063b32 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -1848,11 +1848,24 @@ private DAST.Type FullTypeNameAST(UserDefinedType udt, MemberDecl member = null) } } + private readonly Dictionary>> topLevelDeclPath = new(); + private ISequence> PathFromTopLevel(TopLevelDecl topLevel) { - List> path = new(); - path.Add(Sequence.UnicodeFromString(topLevel.EnclosingModuleDefinition.GetCompileName(Options))); - path.Add(Sequence.UnicodeFromString(topLevel.GetCompileName(Options))); - return Sequence>.FromArray(path.ToArray()); + if (topLevel is NonNullTypeDecl {Class: var classLikeDecl} nonNullTypeDecl) { + topLevel = classLikeDecl; + } + if (topLevelDeclPath.TryGetValue(topLevel, out var path)) { + return path; + } + var enclosingName = topLevel.GetQualificationName(Options); + var compileName = topLevel.GetCompileName(Options); + List> pathList = new() { + Sequence.UnicodeFromString(enclosingName), + Sequence.UnicodeFromString(compileName) + }; + var p = Sequence>.FromArray(pathList.ToArray()); + topLevelDeclPath[topLevel] = p; + return p; } private DAST.NewtypeRange NativeTypeToNewtypeRange(NewtypeDecl newtypeDecl, bool overflows) { @@ -1969,6 +1982,11 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type equalitySupport, infos); } else if (topLevel is ClassDecl) { resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Class(); + } else if (topLevel is AbstractTypeDecl atd) { + var traitType = atd.ParentTraits.Any(s => s.IsRefType) ? + TraitType.create_ObjectTrait() : + TraitType.create_GeneralTrait(); + resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Trait(traitType); } else { // SubsetTypeDecl are covered by TypeSynonymDecl throw new InvalidOperationException(topLevel.GetType().ToString()); diff --git a/Source/DafnyCore/Backends/Rust/RustBackend.cs b/Source/DafnyCore/Backends/Rust/RustBackend.cs index c0d06a59631..662c81cf48d 100644 --- a/Source/DafnyCore/Backends/Rust/RustBackend.cs +++ b/Source/DafnyCore/Backends/Rust/RustBackend.cs @@ -93,7 +93,11 @@ public override async Task OnPostGenerate(string dafnyProgramName, string foreach (var keyValue in ImportFilesMapping(dafnyProgramName)) { var fullRustExternName = keyValue.Key; var expectedRustName = keyValue.Value; - File.Copy(fullRustExternName, Path.Combine(targetDirectory, expectedRustName), true); + var targetName = Path.Combine(targetDirectory, expectedRustName); + if (fullRustExternName == targetName) { + return true; + } + File.Copy(fullRustExternName, targetName, true); } return await base.OnPostGenerate(dafnyProgramName, targetDirectory, outputWriter); } diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index 83347a320a6..3cd9b1effe0 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -1626,6 +1626,11 @@ private void EmitModule(Program program, ConcreteSyntaxTree programNode, ModuleD bool externP = Attributes.Contains(at.Attributes, "extern"); if (externP) { var exprs = Attributes.FindExpressions(at.Attributes, "extern"); + if (exprs == null || exprs.Count == 0) { + exprs = new List() { + Expression.CreateStringLiteral(Token.NoToken, at.Name) + }; + } Contract.Assert(exprs != null); // because externP is true if (exprs.Count == 1) { DeclareExternType(at, exprs[0], wr); diff --git a/docs/DafnyRef/integration- rust/IntegrationRust.md b/docs/DafnyRef/integration- rust/IntegrationRust.md index 6eb44ff9d4b..e417cb84799 100644 --- a/docs/DafnyRef/integration- rust/IntegrationRust.md +++ b/docs/DafnyRef/integration- rust/IntegrationRust.md @@ -125,7 +125,50 @@ pub struct Ptr(pub Option>>); # Externs -You can provide additional `*.rs` files to `dafny translate`, `dafny build` and even `dafny run` (via the `--input` option) +You can provide additional `*.rs` files to `dafny translate`, `dafny build` and even `dafny run` (via the `--input` option). We recommend giving each extern file a suffix `_extern.rs` to avoid name collisions. To understand how to fill these extern files, consider the corresponding section. + +## Partial extern modules + +If a module is defined in Dafny, but has types defined as externs, make sure you mark your module with `{:extern }` where `` is typically the module name. +Then, in a file `_extern.rs` that you include with the build, put the following code: + +``` +pub mod { +} +``` + +and you've just got started with a skeleton to fill implementations for Dafny axioms. + +## Externally implemented traits and classes + +You can define an extern Dafny trait in your extern rust files. Consider the following Dafny general trait declaration: + +``` +trait {:extern} ForeignTrait {} +``` + +To implement this in your extern file, use the following template: +``` + pub trait ForeignTrait { + fn _clone(&self) -> Box; + } + + impl Clone for Box { + fn clone(&self) -> Self { + self._clone() + } + } + + impl ::dafny_runtime::DafnyPrint for Box { + fn fmt_print(&self, f: &mut std::fmt::Formatter<'_>, in_seq: bool) -> std::fmt::Result { + write!(f, "object") + } + } +``` + +For classes, make sure all your mutable fields are wrapped in a `::dafny_runtime::Field` so that it's always possible to share the reference. + +## Other externs The best way to see what you have to implement as an extern Rust file is to compile your code with extern attributes and adding an external Rust file. For extra methods or static methods, you would then define an additional implementation in the extern Rust file. For other class or struct types, you just need to define them without any `mod` wrapper, or using the module structure as defined in the `{:extern}` attribute. From b0fca0dc3c2e552be0a4f07bdfca69e6d2f7380f Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 3 Jan 2025 08:09:21 -0600 Subject: [PATCH 36/69] Fixed a lot of issues --- .../Rust/Dafny-compiler-rust-definitions.dfy | 7 + .../Backends/Rust/Dafny-compiler-rust.dfy | 16 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 214 +++++++++--------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 7 + 4 files changed, 130 insertions(+), 114 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 6078aa06a8e..b549bf316ba 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -1161,4 +1161,11 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { } return NotAssigned; } + + function prefixWith2(s: string): string { + if |s| >= 2 && s[..2] == "r#" then + "_2_" + s[2..] + else + "_2_" + s + } } diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 8be78ec1088..b45eff4c800 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -262,7 +262,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } method GenTraitImplementations( - path: seq, + classPath: seq, rTypeParams: seq, rTypeParamsDecls: seq, superTraitTypes: seq, @@ -274,7 +274,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { modifies this { s := []; - var genPath := GenPath(path); + var genPath := GenPath(classPath); var genSelfPath := genPath.AsType(); var genPathExpr := genPath.AsExpr(); for i := 0 to |superTraitTypes| { @@ -297,7 +297,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { continue; // We assume everything is implemented externally } if |body| != |properMethods| { - error := Some("Error: In the "+kind+" " + R.SeqToString(traitPath, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + + error := Some("Error: In the "+kind+" " + R.SeqToString(classPath, (s: Ident) => s.id.dafny_name, ".") + ", some proper methods of " + fullTraitPath.ToString("") + " are marked {:extern} and some are not." + " For the Rust compiler, please make all methods (" + R.SeqToString(properMethods, (s: Name) => s.dafny_name, ", ") + ") bodiless and mark as {:extern} and implement them in a Rust file, "+ @@ -1310,12 +1310,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { hashRhs.Then(hash_function.Apply([R.Identifier(patternName), R.Identifier("_state")])); ctorMatchInner := ctorMatchInner + patternName + ", "; - ctorMatchInner2 := ctorMatchInner2 + patternName + ": " + "_2_" + patternName + ", "; + var matchingVariable2 := prefixWith2(patternName); + var patternPrefix := if isNumeric then "" else patternName + ": "; + ctorMatchInner2 := ctorMatchInner2 + patternPrefix + matchingVariable2 + ", "; // field: _2_field, partialEqRhs := if formalType.Arrow? then partialEqRhs.And(R.LiteralBool(false)) // No equality support for arrow else - partialEqRhs.And(R.Identifier(patternName).Equals(R.Identifier("_2_"+patternName))); + partialEqRhs.And(R.Identifier(patternName).Equals(R.Identifier(matchingVariable2))); if (j > 0) { printRhs := printRhs.Then(writeStr(", ")); @@ -3185,10 +3187,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } } - } else { - r := Error("Conversion from " + fromTpeGen.ToString("") + " to " + toTpeGen.ToString("") + " not yet supported. Currently supported are Object, Ptr, General trait, Datatype or newtype"); - r, resultingOwnership := FromOwned(r, expectedOwnership); - return; } var upcastConverter := UpcastConversionLambda(fromTyp, fromTpeGen, toTyp, toTpeGen, map[]); if upcastConverter.Success? { diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 4c650f17fef..956e3c25e93 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -314,13 +314,13 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } } } - public Dafny.ISequence GenTraitImplementations(Dafny.ISequence> path, Dafny.ISequence rTypeParams, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence superTraitTypes, Dafny.IMap>,Dafny.ISequence> traitBodies, Defs._IExternAttribute @extern, bool supportsEquality, Dafny.ISequence kind) + public Dafny.ISequence GenTraitImplementations(Dafny.ISequence> classPath, Dafny.ISequence rTypeParams, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence superTraitTypes, Dafny.IMap>,Dafny.ISequence> traitBodies, Defs._IExternAttribute @extern, bool supportsEquality, Dafny.ISequence kind) { Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.FromElements(); RAST._IPath _0_genPath; RAST._IPath _out0; - _out0 = (this).GenPath(path, true); + _out0 = (this).GenPath(classPath, true); _0_genPath = _out0; RAST._IType _1_genSelfPath; _1_genSelfPath = (_0_genPath).AsType(); @@ -365,7 +365,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc goto continue_0; } if ((new BigInteger((_12_body).Count)) != (new BigInteger((_8_properMethods).Count))) { - (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the "), kind), Dafny.Sequence.UnicodeFromString(" ")), RAST.__default.SeqToString>(_5_traitPath, ((System.Func, Dafny.ISequence>)((_15_s) => { + (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Error: In the "), kind), Dafny.Sequence.UnicodeFromString(" ")), RAST.__default.SeqToString>(classPath, ((System.Func, Dafny.ISequence>)((_15_s) => { return ((_15_s)); })), Dafny.Sequence.UnicodeFromString("."))), Dafny.Sequence.UnicodeFromString(", some proper methods of ")), (_13_fullTraitPath)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" are marked {:extern} and some are not.")), Dafny.Sequence.UnicodeFromString(" For the Rust compiler, please make all methods (")), RAST.__default.SeqToString>(_8_properMethods, ((System.Func, Dafny.ISequence>)((_16_s) => { return (_16_s); @@ -1298,116 +1298,124 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _97_hashRhs = (_97_hashRhs).Then((Defs.__default.hash__function).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_105_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_state"))))); } _101_ctorMatchInner = Dafny.Sequence.Concat(Dafny.Sequence.Concat(_101_ctorMatchInner, _105_patternName), Dafny.Sequence.UnicodeFromString(", ")); - _102_ctorMatchInner2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_102_ctorMatchInner2, _105_patternName), Dafny.Sequence.UnicodeFromString(": ")), Dafny.Sequence.UnicodeFromString("_2_")), _105_patternName), Dafny.Sequence.UnicodeFromString(", ")); + Dafny.ISequence _107_matchingVariable2; + _107_matchingVariable2 = Defs.__default.prefixWith2(_105_patternName); + Dafny.ISequence _108_patternPrefix; + if (_100_isNumeric) { + _108_patternPrefix = Dafny.Sequence.UnicodeFromString(""); + } else { + _108_patternPrefix = Dafny.Sequence.Concat(_105_patternName, Dafny.Sequence.UnicodeFromString(": ")); + } + _102_ctorMatchInner2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_102_ctorMatchInner2, _108_patternPrefix), _107_matchingVariable2), Dafny.Sequence.UnicodeFromString(", ")); if ((_106_formalType).is_Arrow) { _98_partialEqRhs = (_98_partialEqRhs).And(RAST.Expr.create_LiteralBool(false)); } else { - _98_partialEqRhs = (_98_partialEqRhs).And((RAST.Expr.create_Identifier(_105_patternName)).Equals(RAST.Expr.create_Identifier(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_2_"), _105_patternName)))); + _98_partialEqRhs = (_98_partialEqRhs).And((RAST.Expr.create_Identifier(_105_patternName)).Equals(RAST.Expr.create_Identifier(_107_matchingVariable2))); } if ((_103_j).Sign == 1) { _96_printRhs = (_96_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(", "), false)); } _96_printRhs = (_96_printRhs).Then((((_106_formalType).is_Arrow) ? ((this).writeStr(Dafny.Sequence.UnicodeFromString(""), false)) : (RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("?"), ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("fmt_print"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(_105_patternName), RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("_formatter")), RAST.Expr.create_LiteralBool(false))), DAST.Format.UnaryOpFormat.create_NoFormat())))); - RAST._IExpr _107_coerceRhsArg = RAST.Expr.Default(); - RAST._IType _108_formalTpe; + RAST._IExpr _109_coerceRhsArg = RAST.Expr.Default(); + RAST._IType _110_formalTpe; RAST._IType _out21; _out21 = (this).GenType(_106_formalType, Defs.GenTypeContext.@default()); - _108_formalTpe = _out21; - DAST._IType _109_newFormalType; - _109_newFormalType = (_106_formalType).Replace(_51_coerceMap); - RAST._IType _110_newFormalTpe; - _110_newFormalTpe = (_108_formalTpe).ReplaceMap(_52_rCoerceMap); - Std.Wrappers._IResult,RAST._IExpr>>> _111_upcastConverter; - _111_upcastConverter = (this).UpcastConversionLambda(_106_formalType, _108_formalTpe, _109_newFormalType, _110_newFormalTpe, _53_coerceMapToArg); - if ((_111_upcastConverter).is_Success) { - RAST._IExpr _112_coercionFunction; - _112_coercionFunction = (_111_upcastConverter).dtor_value; - _107_coerceRhsArg = (_112_coercionFunction).Apply1(RAST.Expr.create_Identifier(_105_patternName)); + _110_formalTpe = _out21; + DAST._IType _111_newFormalType; + _111_newFormalType = (_106_formalType).Replace(_51_coerceMap); + RAST._IType _112_newFormalTpe; + _112_newFormalTpe = (_110_formalTpe).ReplaceMap(_52_rCoerceMap); + Std.Wrappers._IResult,RAST._IExpr>>> _113_upcastConverter; + _113_upcastConverter = (this).UpcastConversionLambda(_106_formalType, _110_formalTpe, _111_newFormalType, _112_newFormalTpe, _53_coerceMapToArg); + if ((_113_upcastConverter).is_Success) { + RAST._IExpr _114_coercionFunction; + _114_coercionFunction = (_113_upcastConverter).dtor_value; + _109_coerceRhsArg = (_114_coercionFunction).Apply1(RAST.Expr.create_Identifier(_105_patternName)); } else { (this).error = Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not generate coercion function for contructor "), Std.Strings.__default.OfNat(_103_j)), Dafny.Sequence.UnicodeFromString(" of ")), _4_datatypeName)); - _107_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); + _109_coerceRhsArg = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("todo!"))).Apply1(RAST.Expr.create_LiteralString((this.error).dtor_value, false, false)); } - _99_coerceRhsArgs = Dafny.Sequence.Concat(_99_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_105_patternName, _107_coerceRhsArg))); + _99_coerceRhsArgs = Dafny.Sequence.Concat(_99_coerceRhsArgs, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(_105_patternName, _109_coerceRhsArg))); } - RAST._IExpr _113_coerceRhs; - _113_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_92_ctor).dtor_name)), _99_coerceRhsArgs); - Dafny.ISequence _114_pattern = Dafny.Sequence.Empty; - Dafny.ISequence _115_pattern2 = Dafny.Sequence.Empty; + RAST._IExpr _115_coerceRhs; + _115_coerceRhs = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_92_ctor).dtor_name)), _99_coerceRhsArgs); + Dafny.ISequence _116_pattern = Dafny.Sequence.Empty; + Dafny.ISequence _117_pattern2 = Dafny.Sequence.Empty; if (_100_isNumeric) { - _114_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _101_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); - _115_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _102_ctorMatchInner2), Dafny.Sequence.UnicodeFromString(")")); + _116_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _101_ctorMatchInner), Dafny.Sequence.UnicodeFromString(")")); + _117_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("(")), _102_ctorMatchInner2), Dafny.Sequence.UnicodeFromString(")")); } else { - _114_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _101_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); - _115_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _102_ctorMatchInner2), Dafny.Sequence.UnicodeFromString("}")); + _116_pattern = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _101_ctorMatchInner), Dafny.Sequence.UnicodeFromString("}")); + _117_pattern2 = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_93_ctorMatch, Dafny.Sequence.UnicodeFromString("{")), _102_ctorMatchInner2), Dafny.Sequence.UnicodeFromString("}")); } if ((_92_ctor).dtor_hasAnyArgs) { _96_printRhs = (_96_printRhs).Then((this).writeStr(Dafny.Sequence.UnicodeFromString(")"), false)); } _96_printRhs = (_96_printRhs).Then((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("Ok"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements())))); - _87_printImplBodyCases = Dafny.Sequence.Concat(_87_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _114_pattern), RAST.Expr.create_Block(_96_printRhs)))); - _88_hashImplBodyCases = Dafny.Sequence.Concat(_88_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _114_pattern), RAST.Expr.create_Block(_97_hashRhs)))); - _90_partialEqImplBodyCases = Dafny.Sequence.Concat(_90_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _114_pattern), Dafny.Sequence.UnicodeFromString(", ")), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _115_pattern2), Dafny.Sequence.UnicodeFromString(")")), RAST.Expr.create_Block(_98_partialEqRhs)))); - _89_coerceImplBodyCases = Dafny.Sequence.Concat(_89_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _114_pattern), RAST.Expr.create_Block(_113_coerceRhs)))); + _87_printImplBodyCases = Dafny.Sequence.Concat(_87_printImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _116_pattern), RAST.Expr.create_Block(_96_printRhs)))); + _88_hashImplBodyCases = Dafny.Sequence.Concat(_88_hashImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _116_pattern), RAST.Expr.create_Block(_97_hashRhs)))); + _90_partialEqImplBodyCases = Dafny.Sequence.Concat(_90_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("("), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _116_pattern), Dafny.Sequence.UnicodeFromString(", ")), _4_datatypeName), Dafny.Sequence.UnicodeFromString("::")), _117_pattern2), Dafny.Sequence.UnicodeFromString(")")), RAST.Expr.create_Block(_98_partialEqRhs)))); + _89_coerceImplBodyCases = Dafny.Sequence.Concat(_89_coerceImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::")), _116_pattern), RAST.Expr.create_Block(_115_coerceRhs)))); } _90_partialEqImplBodyCases = Dafny.Sequence.Concat(_90_partialEqImplBodyCases, Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.UnicodeFromString("_"), RAST.Expr.create_Block(RAST.Expr.create_LiteralBool(false))))); if (((new BigInteger(((c).dtor_typeParams).Count)).Sign == 1) && ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1)) { - Dafny.ISequence _116_extraCases; - _116_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); - _87_printImplBodyCases = Dafny.Sequence.Concat(_87_printImplBodyCases, _116_extraCases); - _88_hashImplBodyCases = Dafny.Sequence.Concat(_88_hashImplBodyCases, _116_extraCases); - _89_coerceImplBodyCases = Dafny.Sequence.Concat(_89_coerceImplBodyCases, _116_extraCases); - } - Dafny.ISequence _117_defaultConstrainedTypeParams; - _117_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); - RAST._IExpr _118_printImplBody; - _118_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _87_printImplBodyCases); - RAST._IExpr _119_hashImplBody; - _119_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _88_hashImplBodyCases); - RAST._IExpr _120_eqImplBody; - _120_eqImplBody = RAST.Expr.create_Match(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))), _90_partialEqImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _71_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _71_datatypeType, _2_rTypeParams, _118_printImplBody))); + Dafny.ISequence _118_extraCases; + _118_extraCases = Dafny.Sequence.FromElements(RAST.MatchCase.create(Dafny.Sequence.Concat(_4_datatypeName, Dafny.Sequence.UnicodeFromString("::_PhantomVariant(..)")), RAST.Expr.create_Block(Defs.__default.UnreachablePanicIfVerified((this).pointerType, Dafny.Sequence.UnicodeFromString(""))))); + _87_printImplBodyCases = Dafny.Sequence.Concat(_87_printImplBodyCases, _118_extraCases); + _88_hashImplBodyCases = Dafny.Sequence.Concat(_88_hashImplBodyCases, _118_extraCases); + _89_coerceImplBodyCases = Dafny.Sequence.Concat(_89_coerceImplBodyCases, _118_extraCases); + } + Dafny.ISequence _119_defaultConstrainedTypeParams; + _119_defaultConstrainedTypeParams = RAST.TypeParamDecl.AddConstraintsMultiple(_3_rTypeParamsDecls, Dafny.Sequence.FromElements(RAST.__default.DefaultTrait)); + RAST._IExpr _120_printImplBody; + _120_printImplBody = RAST.Expr.create_Match(RAST.__default.self, _87_printImplBodyCases); + RAST._IExpr _121_hashImplBody; + _121_hashImplBody = RAST.Expr.create_Match(RAST.__default.self, _88_hashImplBodyCases); + RAST._IExpr _122_eqImplBody; + _122_eqImplBody = RAST.Expr.create_Match(RAST.Expr.create_Tuple(Dafny.Sequence.FromElements(RAST.__default.self, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("other")))), _90_partialEqImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DebugImpl(_3_rTypeParamsDecls, _71_datatypeType, _2_rTypeParams), Defs.__default.PrintImpl(_3_rTypeParamsDecls, _71_datatypeType, _2_rTypeParams, _120_printImplBody))); if ((new BigInteger((_49_rCoerceTypeParams).Count)).Sign == 1) { - RAST._IExpr _121_coerceImplBody; - _121_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _89_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _71_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _121_coerceImplBody))); + RAST._IExpr _123_coerceImplBody; + _123_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _89_coerceImplBodyCases); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _71_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _123_coerceImplBody))); } if ((new BigInteger((_9_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { - RAST._IType _122_instantiationType; + RAST._IType _124_instantiationType; if (_0_isRcWrapped) { - _122_instantiationType = RAST.__default.Rc(_71_datatypeType); + _124_instantiationType = RAST.__default.Rc(_71_datatypeType); } else { - _122_instantiationType = _71_datatypeType; + _124_instantiationType = _71_datatypeType; } - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _71_datatypeType, _122_instantiationType, _9_singletonConstructors))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.SingletonsImpl(_3_rTypeParamsDecls, _71_datatypeType, _124_instantiationType, _9_singletonConstructors))); } if (((c).dtor_equalitySupport).is_ConsultTypeArguments) { - Dafny.ISequence _123_impls; + Dafny.ISequence _125_impls; Dafny.ISequence _out22; - _out22 = (this).GenEqHashImpls((c).dtor_typeParams, _3_rTypeParamsDecls, _2_rTypeParams, _71_datatypeType, _120_eqImplBody, _119_hashImplBody); - _123_impls = _out22; - s = Dafny.Sequence.Concat(s, _123_impls); + _out22 = (this).GenEqHashImpls((c).dtor_typeParams, _3_rTypeParamsDecls, _2_rTypeParams, _71_datatypeType, _122_eqImplBody, _121_hashImplBody); + _125_impls = _out22; + s = Dafny.Sequence.Concat(s, _125_impls); } if ((new BigInteger(((c).dtor_ctors).Count)).Sign == 1) { - RAST._IExpr _124_structName; - _124_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); - Dafny.ISequence _125_structAssignments; - _125_structAssignments = Dafny.Sequence.FromElements(); + RAST._IExpr _126_structName; + _126_structName = (RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_name)); + Dafny.ISequence _127_structAssignments; + _127_structAssignments = Dafny.Sequence.FromElements(); BigInteger _hi11 = new BigInteger(((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Count); - for (BigInteger _126_i = BigInteger.Zero; _126_i < _hi11; _126_i++) { - DAST._IDatatypeDtor _127_dtor; - _127_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_126_i); - _125_structAssignments = Dafny.Sequence.Concat(_125_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_127_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); + for (BigInteger _128_i = BigInteger.Zero; _128_i < _hi11; _128_i++) { + DAST._IDatatypeDtor _129_dtor; + _129_dtor = ((((c).dtor_ctors).Select(BigInteger.Zero)).dtor_args).Select(_128_i); + _127_structAssignments = Dafny.Sequence.Concat(_127_structAssignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(((_129_dtor).dtor_formal).dtor_name), (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("default"))).MSel(Dafny.Sequence.UnicodeFromString("Default"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("default"))).Apply0()))); } if ((false) && (_68_cIsAlwaysEq)) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _71_datatypeType, _124_structName, _125_structAssignments))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.DefaultDatatypeImpl(_3_rTypeParamsDecls, _71_datatypeType, _126_structName, _127_structAssignments))); } s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.AsRefDatatypeImpl(_3_rTypeParamsDecls, _71_datatypeType))); } - Dafny.ISequence _128_superTraitImplementations; + Dafny.ISequence _130_superTraitImplementations; Dafny.ISequence _out23; _out23 = (this).GenTraitImplementations(path, _2_rTypeParams, _3_rTypeParamsDecls, (c).dtor_superTraitTypes, _26_traitBodies, _5_extern, _68_cIsAlwaysEq, Dafny.Sequence.UnicodeFromString("datatype")); - _128_superTraitImplementations = _out23; - s = Dafny.Sequence.Concat(s, _128_superTraitImplementations); + _130_superTraitImplementations = _out23; + s = Dafny.Sequence.Concat(s, _130_superTraitImplementations); return s; } public RAST._IPath GenPath(Dafny.ISequence> p, bool escape) @@ -4328,6 +4336,7 @@ public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership r = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); r = expr; + resultingOwnership = exprOwnership; RAST._IType _0_fromTpeGen; RAST._IType _out0; _out0 = (this).GenType(fromTyp, Defs.GenTypeContext.@default()); @@ -4423,55 +4432,50 @@ public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership return ; } } - } else { - RAST._IExpr _out12; - _out12 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Conversion from "), (_0_fromTpeGen)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_1_toTpeGen)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" not yet supported. Currently supported are Object, Ptr, General trait, Datatype or newtype")), (this).InitEmptyExpr()); - r = _out12; - RAST._IExpr _out13; - Defs._IOwnership _out14; - (this).FromOwned(r, expectedOwnership, out _out13, out _out14); - r = _out13; - resultingOwnership = _out14; - return ; } Std.Wrappers._IResult,RAST._IExpr>>> _11_upcastConverter; _11_upcastConverter = (this).UpcastConversionLambda(fromTyp, _0_fromTpeGen, toTyp, _1_toTpeGen, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements()); if ((_11_upcastConverter).is_Success) { RAST._IExpr _12_conversionLambda; _12_conversionLambda = (_11_upcastConverter).dtor_value; - if (object.Equals(exprOwnership, Defs.Ownership.create_OwnershipBorrowed())) { + if (object.Equals(resultingOwnership, Defs.Ownership.create_OwnershipBorrowed())) { if (((fromTyp).IsGeneralTrait()) && (object.Equals(r, RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("self"))))) { RAST._IType _13_traitType; - RAST._IType _out15; - _out15 = (this).GenType(fromTyp, Defs.GenTypeContext.ForTraitParents()); - _13_traitType = _out15; + RAST._IType _out12; + _out12 = (this).GenType(fromTyp, Defs.GenTypeContext.ForTraitParents()); + _13_traitType = _out12; Std.Wrappers._IOption _14_traitExpr; _14_traitExpr = (_13_traitType).ToExpr(); if ((_14_traitExpr).is_None) { - RAST._IExpr _out16; - _out16 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_13_traitType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); - r = _out16; + RAST._IExpr _out13; + _out13 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_13_traitType)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); + r = _out13; } else { r = (((_14_traitExpr).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_clone"))).Apply1(r); } } else { r = (this).BorrowedToOwned(r, env); } + resultingOwnership = Defs.Ownership.create_OwnershipOwned(); } r = (_12_conversionLambda).Apply1(r); - RAST._IExpr _out17; - Defs._IOwnership _out18; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out17, out _out18); - r = _out17; - resultingOwnership = _out18; + RAST._IExpr _out14; + Defs._IOwnership _out15; + (this).FromOwnership(r, resultingOwnership, expectedOwnership, out _out14, out _out15); + r = _out14; + resultingOwnership = _out15; } else if ((this).IsDowncastConversion(_0_fromTpeGen, _1_toTpeGen)) { _1_toTpeGen = (_1_toTpeGen).ObjectOrPointerUnderlying(); + if (object.Equals(resultingOwnership, Defs.Ownership.create_OwnershipBorrowed())) { + r = (this).BorrowedToOwned(r, env); + resultingOwnership = Defs.Ownership.create_OwnershipOwned(); + } r = (((RAST.__default.dafny__runtime).MSel((this).downcast)).AsExpr()).Apply(Dafny.Sequence.FromElements(r, RAST.Expr.create_ExprFromType(_1_toTpeGen))); - RAST._IExpr _out19; - Defs._IOwnership _out20; - (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out19, out _out20); - r = _out19; - resultingOwnership = _out20; + RAST._IExpr _out16; + Defs._IOwnership _out17; + (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out16, out _out17); + r = _out16; + resultingOwnership = _out17; } else { Std.Wrappers._IResult,RAST._IExpr>>> _let_tmp_rhs0 = _11_upcastConverter; _System._ITuple5,RAST._IExpr>> _let_tmp_rhs1 = _let_tmp_rhs0.dtor_error; @@ -4480,14 +4484,14 @@ public void GenExprConvertOther(RAST._IExpr expr, Defs._IOwnership exprOwnership DAST._IType _17_toType = _let_tmp_rhs1.dtor__2; RAST._IType _18_toTpeGen = _let_tmp_rhs1.dtor__3; Dafny.IMap<_System._ITuple2,RAST._IExpr> _19_m = _let_tmp_rhs1.dtor__4; - RAST._IExpr _out21; - _out21 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Coercion from "), (_16_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_18_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), r); - r = _out21; - RAST._IExpr _out22; - Defs._IOwnership _out23; - (this).FromOwned(r, expectedOwnership, out _out22, out _out23); - r = _out22; - resultingOwnership = _out23; + RAST._IExpr _out18; + _out18 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Coercion from "), (_16_fromTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" to ")), (_18_toTpeGen)._ToString(Defs.__default.IND)), Dafny.Sequence.UnicodeFromString(" not yet implemented")), r); + r = _out18; + RAST._IExpr _out19; + Defs._IOwnership _out20; + (this).FromOwned(r, expectedOwnership, out _out19, out _out20); + r = _out19; + resultingOwnership = _out20; } } public void GenExprConvert(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership, out Dafny.ISet> readIdents) diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index 9bd57c73c02..cf7260543ae 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -765,6 +765,13 @@ public static Defs._IAssignmentStatus DetectAssignmentStatus(Dafny.ISequence prefixWith2(Dafny.ISequence s) { + if (((new BigInteger((s).Count)) >= (new BigInteger(2))) && (((s).Take(new BigInteger(2))).Equals(Dafny.Sequence.UnicodeFromString("r#")))) { + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_2_"), (s).Drop(new BigInteger(2))); + } else { + return Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_2_"), s); + } + } public static Dafny.ISet> reserved__rust { get { return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("as"), Dafny.Sequence.UnicodeFromString("async"), Dafny.Sequence.UnicodeFromString("await"), Dafny.Sequence.UnicodeFromString("break"), Dafny.Sequence.UnicodeFromString("const"), Dafny.Sequence.UnicodeFromString("continue"), Dafny.Sequence.UnicodeFromString("crate"), Dafny.Sequence.UnicodeFromString("dyn"), Dafny.Sequence.UnicodeFromString("else"), Dafny.Sequence.UnicodeFromString("enum"), Dafny.Sequence.UnicodeFromString("extern"), Dafny.Sequence.UnicodeFromString("false"), Dafny.Sequence.UnicodeFromString("fn"), Dafny.Sequence.UnicodeFromString("for"), Dafny.Sequence.UnicodeFromString("if"), Dafny.Sequence.UnicodeFromString("impl"), Dafny.Sequence.UnicodeFromString("in"), Dafny.Sequence.UnicodeFromString("let"), Dafny.Sequence.UnicodeFromString("loop"), Dafny.Sequence.UnicodeFromString("match"), Dafny.Sequence.UnicodeFromString("mod"), Dafny.Sequence.UnicodeFromString("move"), Dafny.Sequence.UnicodeFromString("mut"), Dafny.Sequence.UnicodeFromString("pub"), Dafny.Sequence.UnicodeFromString("ref"), Dafny.Sequence.UnicodeFromString("return"), Dafny.Sequence.UnicodeFromString("static"), Dafny.Sequence.UnicodeFromString("struct"), Dafny.Sequence.UnicodeFromString("super"), Dafny.Sequence.UnicodeFromString("trait"), Dafny.Sequence.UnicodeFromString("true"), Dafny.Sequence.UnicodeFromString("type"), Dafny.Sequence.UnicodeFromString("union"), Dafny.Sequence.UnicodeFromString("unsafe"), Dafny.Sequence.UnicodeFromString("use"), Dafny.Sequence.UnicodeFromString("where"), Dafny.Sequence.UnicodeFromString("while"), Dafny.Sequence.UnicodeFromString("Keywords"), Dafny.Sequence.UnicodeFromString("The"), Dafny.Sequence.UnicodeFromString("abstract"), Dafny.Sequence.UnicodeFromString("become"), Dafny.Sequence.UnicodeFromString("box"), Dafny.Sequence.UnicodeFromString("do"), Dafny.Sequence.UnicodeFromString("final"), Dafny.Sequence.UnicodeFromString("macro"), Dafny.Sequence.UnicodeFromString("override"), Dafny.Sequence.UnicodeFromString("priv"), Dafny.Sequence.UnicodeFromString("try"), Dafny.Sequence.UnicodeFromString("typeof"), Dafny.Sequence.UnicodeFromString("unsized"), Dafny.Sequence.UnicodeFromString("virtual"), Dafny.Sequence.UnicodeFromString("yield")); } } From 68a02b00e81064eea0ee22d4f92aa90e6ed5eb4e Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 3 Jan 2025 08:52:21 -0600 Subject: [PATCH 37/69] Fixed traits downcast --- Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy | 7 ++++--- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index b45eff4c800..213e26e507d 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -603,8 +603,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } var parents: seq := []; var upcastImplemented: seq := []; - var instantiatedFullType := R.Box(R.DynType(traitFullType)); + var instantiatedFullType: R.Type; if t.traitType.GeneralTrait? { // TODO: Make it work also for object traits + instantiatedFullType := R.Box(R.DynType(traitFullType)); var upcastDynTrait := UpcastDynTraitFor(rTypeParamsDecls, instantiatedFullType, traitFullType, traitFullExpr); upcastImplemented := upcastImplemented + [upcastDynTrait]; } @@ -627,7 +628,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } var downcastDefinition := []; - if |t.parents| > 0 { // We will need to downcast + if |t.parents| > 0 && t.traitType.GeneralTrait? { // We will need to downcast var downcastDefinitionOpt := DowncastTraitDeclFor(rTypeParamsDecls, instantiatedFullType); if downcastDefinitionOpt.None? { var dummy := Error("Could not generate downcast definition for " + instantiatedFullType.ToString("")); @@ -638,7 +639,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // Any top-most general trait must extend AnyRef so that we can perform downcasts to actual datatypes parents := [R.dafny_runtime.MSel("AnyRef").AsType()] + parents; } - if |t.downcastableTraits| > 0 { + if |t.downcastableTraits| > 0 && t.traitType.GeneralTrait? { for i := 0 to |t.downcastableTraits| { var downcastableTrait := GenType(t.downcastableTraits[i], GenTypeContext.ForTraitParents()); var downcastTraitOpt := downcastableTrait.ToDowncast(); diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 956e3c25e93..10734c1415a 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -609,9 +609,9 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _17_parents = Dafny.Sequence.FromElements(); Dafny.ISequence _18_upcastImplemented; _18_upcastImplemented = Dafny.Sequence.FromElements(); - RAST._IType _19_instantiatedFullType; - _19_instantiatedFullType = RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)); + RAST._IType _19_instantiatedFullType = RAST.Type.Default(); if (((t).dtor_traitType).is_GeneralTrait) { + _19_instantiatedFullType = RAST.__default.Box(RAST.Type.create_DynType(_10_traitFullType)); RAST._IModDecl _20_upcastDynTrait; _20_upcastDynTrait = Defs.__default.UpcastDynTraitFor(_1_rTypeParamsDecls, _19_instantiatedFullType, _10_traitFullType, _11_traitFullExpr); _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(_20_upcastDynTrait)); @@ -650,7 +650,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } Dafny.ISequence _28_downcastDefinition; _28_downcastDefinition = Dafny.Sequence.FromElements(); - if ((new BigInteger(((t).dtor_parents).Count)).Sign == 1) { + if (((new BigInteger(((t).dtor_parents).Count)).Sign == 1) && (((t).dtor_traitType).is_GeneralTrait)) { Std.Wrappers._IOption _29_downcastDefinitionOpt; _29_downcastDefinitionOpt = Defs.__default.DowncastTraitDeclFor(_1_rTypeParamsDecls, _19_instantiatedFullType); if ((_29_downcastDefinitionOpt).is_None) { @@ -664,7 +664,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc } else if (((t).dtor_traitType).is_GeneralTrait) { _17_parents = Dafny.Sequence.Concat(Dafny.Sequence.FromElements(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsType()), _17_parents); } - if ((new BigInteger(((t).dtor_downcastableTraits).Count)).Sign == 1) { + if (((new BigInteger(((t).dtor_downcastableTraits).Count)).Sign == 1) && (((t).dtor_traitType).is_GeneralTrait)) { BigInteger _hi3 = new BigInteger(((t).dtor_downcastableTraits).Count); for (BigInteger _31_i = BigInteger.Zero; _31_i < _hi3; _31_i++) { RAST._IType _32_downcastableTrait; From 5f42d6d41f1a121bacf5c85f611e6351292673bd Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 3 Jan 2025 10:33:12 -0600 Subject: [PATCH 38/69] Fixed the merge --- .../Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index 278265bb68f..08d9d43abfd 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -4873,7 +4873,7 @@ private void CompileTypeTest(TypeTestExpr expr, bool inLetExprBody, ConcreteSynt // Notes: // - The constraint of a non-null reference type can be omitted in some cases, see note (c) above. if (fromType.IsTraitType || fromType.IsRefType) { - EmitTypeTestExpr(expr.E, fromType, expr.ToType, expr.Tok, inLetExprBody, wr, ref wStmts); + EmitTypeTestExpr(expr.E, fromType, expr.ToType, expr.Origin, inLetExprBody, wr, ref wStmts); return; } From e9ece6b1da3f6883aa88ccd2462f7ba99ddd65b3 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 3 Jan 2025 12:11:17 -0600 Subject: [PATCH 39/69] All other test files --- .../LitTest/comp/rust/small/01-hash.dfy | 22 ++++++++++++ .../LitTest/comp/rust/small/02-binary.dfy | 17 +++++++++ .../comp/rust/small/03-methodnamed.dfy | 29 +++++++++++++++ .../LitTest/comp/rust/small/04-mismatched.dfy | 28 +++++++++++++++ .../LitTest/comp/rust/small/05-coerce.dfy | 36 +++++++++++++++++++ .../10-type-parameter-equality.dfy.expect | 2 ++ 6 files changed, 134 insertions(+) create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy new file mode 100644 index 00000000000..e2dc2ed5615 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy @@ -0,0 +1,22 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Super { + function Compare(a: T, b: T): bool +} + +trait Sub extends Super { + function Compare(a: T, b: T): bool { + a == b + } +} + +datatype IntOps extends Sub = IntOps { +} + +method Main() { + expect IntOps().Compare(1, 1); + expect !IntOps().Compare(1, 2); + print "ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy new file mode 100644 index 00000000000..e886248a139 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy @@ -0,0 +1,17 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Super { + function Get(): T +} + +datatype KeysValue extends Super = KeysValue(keys: set, value: V) { + function Get(): V { value } +} + +method Main() { + expect KeysValue({1}, 3).Get() == 3; + expect (KeysValue({1}, 5) as Super).Get() == 5; + print "ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy new file mode 100644 index 00000000000..389e4cc8215 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy @@ -0,0 +1,29 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Super { + function get(d:D,ks:K):(r:int) +} +datatype ZeroComputation = ZeroComputation { + function top(): int { 0 } +} + +datatype ComputationWrapper extends Super = ComputationWrapper { + function Computation_():ZeroComputation { ZeroComputation } + const computation := Computation_() + function get(d:K,ks:K):(r:int) { + computation.top() + } + function Copy(): ComputationWrapper { + this + } + function AsSuper(): Super { + this as Super + } +} + +method Main() { + expect ComputationWrapper.ComputationWrapper().Copy().get(1, 2) == 0; + print "ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy new file mode 100644 index 00000000000..c98e30d3ca6 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy @@ -0,0 +1,28 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Super { + function AsSuper(): Super + function GetInt(): int + + function GetDoubleInt(): int { + GetInt() * 2 + } +} + +datatype Sub extends Super = Sub { + function AsSuper(): Super { + this + } + function GetInt(): int { + 3 + } + function Total(): int { + this.AsSuper().GetInt() + this.GetDoubleInt() + } +} + +method Main() { + expect Sub().Total() == 9; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy new file mode 100644 index 00000000000..5a6d276eb6f --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy @@ -0,0 +1,36 @@ +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +trait Q { + function put():(r:OM) +} + +datatype Getter = Getter { + function get():(r:Single) { + Single + } +} + +datatype {:rust_rc false} Option = + | None + | Some(v:T) + +datatype Single_ = Single + +type Single = t:Single_ | true witness * + +type OM = Option> + +datatype ComplexCase extends Q = ComplexCase { + const getter := Getter + + function put():(r:OM) { + var xya := getter.get(); + None + } +} + +method Main() { + print "ok"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect new file mode 100644 index 00000000000..19e90eca854 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect @@ -0,0 +1,2 @@ +Dafny program verifier finished with 1 verified, 0 errors +ok \ No newline at end of file From 1d97c227cb68964d88d1a335a929aba177b60469 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 3 Jan 2025 12:15:29 -0600 Subject: [PATCH 40/69] CI fixes --- Source/DafnyCore/Backends/Dafny/AST.dfy | 2 +- .../Backends/Dafny/DafnyCodeGenerator.cs | 2 +- .../Rust/Dafny-compiler-rust-definitions.dfy | 56 ++++++------- .../Rust/Dafny-compiler-rust-rast.dfy | 8 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 83 ++++++++++++------- .../comp/rust/traits-datatypes.dfy.expect | 2 +- docs/HowToFAQ/Errors-Compiler.md | 9 -- 7 files changed, 87 insertions(+), 75 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/AST.dfy b/Source/DafnyCore/Backends/Dafny/AST.dfy index c4088556818..6ec80c938d3 100644 --- a/Source/DafnyCore/Backends/Dafny/AST.dfy +++ b/Source/DafnyCore/Backends/Dafny/AST.dfy @@ -294,7 +294,7 @@ module {:extern "DAST"} DAST { datatype TypeParameterInfo = TypeParameterInfo(variance: Variance, necessaryForEqualitySupportOfSurroundingInductiveDatatype: bool) - + datatype EqualitySupport = Never | ConsultTypeArguments datatype ResolvedTypeBase = diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index aea018c5d90..3b738c2582b 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -1851,7 +1851,7 @@ private DAST.Type FullTypeNameAST(UserDefinedType udt, MemberDecl member = null) private readonly Dictionary>> topLevelDeclPath = new(); private ISequence> PathFromTopLevel(TopLevelDecl topLevel) { - if (topLevel is NonNullTypeDecl {Class: var classLikeDecl} nonNullTypeDecl) { + if (topLevel is NonNullTypeDecl { Class: var classLikeDecl } nonNullTypeDecl) { topLevel = classLikeDecl; } if (topLevelDeclPath.TryGetValue(topLevel, out var path)) { diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index b549bf316ba..f4e21d15014 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -298,15 +298,15 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { ThisTyped? && dafnyType.IsClassOrObjectTrait() } predicate IsRcWrappedDatatype() { - ThisTyped? && IsRcWrappedDatatypeRec(dafnyType) + ThisTyped? && IsRcWrappedDatatypeRec(dafnyType) } } predicate IsRcWrappedDatatypeRec(dafnyType: Type) { match dafnyType { - case UserDefined(ResolvedType(_, _, Datatype(_, _), attributes, _, _)) => + case UserDefined(ResolvedType(_, _, Datatype(_, _), attributes, _, _)) => IsRcWrapped(attributes) - case UserDefined(ResolvedType(_, _, SynonymType(tpe), attributes, _, _)) => + case UserDefined(ResolvedType(_, _, SynonymType(tpe), attributes, _, _)) => IsRcWrappedDatatypeRec(tpe) case _ => false } @@ -314,7 +314,7 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { predicate IsRcWrapped(attributes: seq) { (Attribute("auto-nongrowing-size", []) !in attributes && - Attribute("rust_rc", ["false"]) !in attributes) || + Attribute("rust_rc", ["false"]) !in attributes) || Attribute("rust_rc", ["true"]) in attributes } @@ -620,20 +620,20 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { function EqImpl(rTypeParamsDeclsWithEq: seq, datatypeType: R.Type, rTypeParams: seq, eqImplBody: R.Expr): seq { [ R.ImplDecl( - R.ImplFor( - rTypeParamsDeclsWithEq, - R.PartialEq, - datatypeType, - [ R.FnDecl( - R.NoDoc, R.NoAttr, R.PRIV, - R.Fn( - "eq", - [], - [R.Formal.selfBorrowed, R.Formal("other", R.SelfBorrowed)], - Some(R.Bool), - Some(eqImplBody) - ) - )])), + R.ImplFor( + rTypeParamsDeclsWithEq, + R.PartialEq, + datatypeType, + [ R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn( + "eq", + [], + [R.Formal.selfBorrowed, R.Formal("other", R.SelfBorrowed)], + Some(R.Bool), + Some(eqImplBody) + ) + )])), R.ImplDecl( R.ImplFor( rTypeParamsDeclsWithEq, @@ -1068,7 +1068,7 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { } } */ - function UpcastDynTraitFor( + function UpcastDynTraitFor( rTypeParamsDecls: seq, forBoxedTraitType: R.Type, superTraitType: R.Type, @@ -1076,15 +1076,15 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { ): R.ModDecl { var superBoxedTraitType := R.Box(R.DynType(superTraitType)); var body := superTraitExpr.FSel("_clone").Apply1(R.self.Sel("as_ref").Apply0()); - R.ImplDecl( - R.ImplFor( - rTypeParamsDecls, - R.dafny_runtime.MSel("UpcastBox").AsType().Apply([R.DynType(superTraitType)]), - forBoxedTraitType, - [ R.FnDecl( - R.NoDoc, R.NoAttr, R.PRIV, - R.Fn("upcast", [], [R.Formal.selfBorrowed], Some(superBoxedTraitType), Some(body))) - ])) + R.ImplDecl( + R.ImplFor( + rTypeParamsDecls, + R.dafny_runtime.MSel("UpcastBox").AsType().Apply([R.DynType(superTraitType)]), + forBoxedTraitType, + [ R.FnDecl( + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn("upcast", [], [R.Formal.selfBorrowed], Some(superBoxedTraitType), Some(body))) + ])) } // Overapproximate but sound static analysis domain for assignment of a variable diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy index f8883c6df55..4226f409ad2 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy @@ -454,13 +454,13 @@ module RAST static function Name(name: string): Attribute { ApplyAttribute(name, []) } - + function ToString(ind: string): string { match this { case ApplyAttribute(name, derived) => var arguments := if |derived| != 0 then - "("+SeqToString(derived, (derived: string) => derived, ", ")+")" - else ""; + "("+SeqToString(derived, (derived: string) => derived, ", ")+")" + else ""; "#["+name+arguments+"]" } } @@ -1674,7 +1674,7 @@ module RAST else PrecedenceAssociativity(110, RightToLeft) case "=>" => // Not a Rust operation, used in the map macro syntax - PrecedenceAssociativity(120, RightToLeft) + PrecedenceAssociativity(120, RightToLeft) case _ => PrecedenceAssociativity(0, RequiresParentheses) } case Lambda(_, _, _) => PrecedenceAssociativity(300, LeftToRight) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 213e26e507d..dd6e2f71a89 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -174,12 +174,15 @@ module {:extern "DCOMP"} DafnyToRustCompiler { typeParamsSeq: seq, rTypeParams: seq, rTypeParamsDecls: seq) + ensures |rTypeParams| == |rTypeParamsDecls| == |typeParamsSeq| == |params| { typeParamsSeq := []; rTypeParams := []; rTypeParamsDecls := []; if |params| > 0 { - for tpI := 0 to |params| { + for tpI := 0 to |params| + invariant |rTypeParams| == |rTypeParamsDecls| == |typeParamsSeq| == tpI + { var tp := params[tpI]; var typeArg, typeParam := GenTypeParam(tp); var rType := GenType(typeArg, GenTypeContext.default()); @@ -622,7 +625,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { parents := parents + [parentTpe]; var upcastTrait := if parentTyp.IsGeneralTrait() then "UpcastBox" else Upcast; parents := parents + [R.dafny_runtime.MSel(upcastTrait).AsType().Apply1(R.DynType(parentTpe))]; - if parentTyp.IsGeneralTrait() { + if parentTyp.IsGeneralTrait() && t.traitType.GeneralTrait? { var upcastDynTrait := UpcastDynTraitFor(rTypeParamsDecls, instantiatedFullType, parentTpe, parentTpeExpr); upcastImplemented := upcastImplemented + [upcastDynTrait]; } @@ -724,7 +727,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.std.MSel("cmp").MSel("Eq").AsType(), R.Box(R.DynType(traitFullType)), []))]; - s := s + [ + s := s + [ /* impl Hash for Box { @@ -740,13 +743,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { R.Hash, R.Box(R.DynType(traitFullType)), [R.FnDecl( - R.NoDoc, R.NoAttr, R.PRIV, - R.Fn( - "hash", hash_type_parameters, - hash_parameters, - None, - Some(hash_function.Apply([R.Borrow(traitFullExpr.FSel("_hash").Apply1(R.self.Sel("as_ref").Apply0())), R.Identifier("_state")])) - ))])) + R.NoDoc, R.NoAttr, R.PRIV, + R.Fn( + "hash", hash_type_parameters, + hash_parameters, + None, + Some(hash_function.Apply([R.Borrow(traitFullExpr.FSel("_hash").Apply1(R.self.Sel("as_ref").Apply0())), R.Identifier("_state")])) + ))])) ]; } s := s + upcastImplemented; @@ -998,11 +1001,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { eqImplBody: R.Expr, hashImplBody: R.Expr ) returns (impls: seq) - requires |typeParamsDecls| == |rTypeParamsDecls| + requires |typeParamsDecls| == |rTypeParamsDecls| == |rTypeParams| { var rTypeParamsDeclsWithEq := rTypeParamsDecls; var rTypeParamsDeclsWithHash := rTypeParamsDecls; - for i := 0 to |rTypeParamsDecls| { + for i := 0 to |rTypeParamsDecls| + invariant |rTypeParamsDeclsWithEq| == |rTypeParamsDecls| + invariant |rTypeParamsDeclsWithHash| == |rTypeParamsDecls| + { if typeParamsDecls[i].info.necessaryForEqualitySupportOfSurroundingInductiveDatatype { rTypeParamsDeclsWithEq := rTypeParamsDeclsWithEq[i := rTypeParamsDeclsWithEq[i].AddConstraints([R.Eq, R.Hash])]; rTypeParamsDeclsWithHash := rTypeParamsDeclsWithHash[i := rTypeParamsDeclsWithHash[i].AddConstraints([R.Hash])]; @@ -1213,7 +1219,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } var cIsAlwaysEq := c.equalitySupport.ConsultTypeArguments? && - forall t <- c.typeParams :: !t.info.necessaryForEqualitySupportOfSurroundingInductiveDatatype; + forall t <- c.typeParams :: !t.info.necessaryForEqualitySupportOfSurroundingInductiveDatatype; var datatypeType := R.TypeApp(R.TIdentifier(datatypeName), rTypeParams); // Derive PartialEq when c supports equality / derive Clone in all cases @@ -1311,7 +1317,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { hashRhs.Then(hash_function.Apply([R.Identifier(patternName), R.Identifier("_state")])); ctorMatchInner := ctorMatchInner + patternName + ", "; - var matchingVariable2 := prefixWith2(patternName); + var matchingVariable2 := prefixWith2(patternName); var patternPrefix := if isNumeric then "" else patternName + ": "; ctorMatchInner2 := ctorMatchInner2 + patternPrefix + matchingVariable2 + ", "; // field: _2_field, partialEqRhs := @@ -1393,10 +1399,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { ]; } partialEqImplBodyCases := partialEqImplBodyCases + [ - R.MatchCase( - R.RawPattern("_"), - R.Block(R.LiteralBool(false))) - ]; + R.MatchCase( + R.RawPattern("_"), + R.Block(R.LiteralBool(false))) + ]; if |c.typeParams| > 0 && |unusedTypeParams| > 0 { var extraCases := [ @@ -1808,8 +1814,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { tpe := R.SelfBorrowed; } else { if enclosingType.UserDefined? && enclosingType.resolved.kind.Newtype? - && IsNewtypeCopy(enclosingType.resolved.kind.range) - && !forTrait { + && IsNewtypeCopy(enclosingType.resolved.kind.range) + && !forTrait { tpe := R.TMetaData( R.SelfOwned, copySemantics := true, @@ -2843,9 +2849,26 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } + method GenExprConvertTo( + expr: R.Expr, + exprOwnership: Ownership, + fromTpeWithSynonyms: Type, + toTpeWithSynonyms: Type, + env: Environment, + expectedOwnership: Ownership + ) returns (r: R.Expr, resultingOwnership: Ownership) + requires exprOwnership != OwnershipAutoBorrowed + modifies this + ensures OwnershipGuarantee(expectedOwnership, resultingOwnership) + { + var fromTpe := fromTpeWithSynonyms.RemoveSynonyms(); + var toTpe := toTpeWithSynonyms.RemoveSynonyms(); + r, resultingOwnership := GenExprConvertToWithoutSynonyms(expr, exprOwnership, fromTpe, toTpe, env, expectedOwnership); + } + // To use when we know that the expression is a Convert(_, _, toTpe) // and toTpe is a newtype - method GenExprConvertTo( + method GenExprConvertToWithoutSynonyms( expr: R.Expr, exprOwnership: Ownership, fromTpe: Type, @@ -2860,8 +2883,6 @@ module {:extern "DCOMP"} DafnyToRustCompiler { { r := expr; // For conversion purpose, synonyms are not desired - var fromTpe := fromTpe.RemoveSynonyms(); - var toTpe := toTpe.RemoveSynonyms(); if fromTpe == toTpe { r, resultingOwnership := FromOwnership(r, exprOwnership, expectedOwnership); return; @@ -2870,13 +2891,13 @@ module {:extern "DCOMP"} DafnyToRustCompiler { // From type is a newtype but it's not a primitive one. r := UnwrapNewtype(r, exprOwnership, fromTpe); r, resultingOwnership := - GenExprConvertTo(r, exprOwnership, fromTpe.resolved.kind.baseType, toTpe, env, expectedOwnership); + GenExprConvertToWithoutSynonyms(r, exprOwnership, fromTpe.resolved.kind.baseType, toTpe, env, expectedOwnership); return; } if NeedsUnwrappingConversion(toTpe) { var toKind := toTpe.resolved.kind; r, resultingOwnership := - GenExprConvertTo(r, exprOwnership, fromTpe, toKind.baseType, env, expectedOwnership); + GenExprConvertToWithoutSynonyms(r, exprOwnership, fromTpe, toKind.baseType, env, expectedOwnership); r := WrapWithNewtype(r, resultingOwnership, toTpe); r, resultingOwnership := FromOwnership(r, resultingOwnership, expectedOwnership); return; @@ -3051,12 +3072,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if fromType.UserDefined? && fromType.resolved.kind.Datatype? then Std.Collections.Seq.Filter( i => - if 0 <= i < |fromTpe.arguments| then - (0 <= i < |fromType.resolved.kind.info| ==> - !fromType.resolved.kind.info[i].variance.Nonvariant?) - else - false - , seq(|fromTpe.arguments|, i => i)) + if 0 <= i < |fromTpe.arguments| then + (0 <= i < |fromType.resolved.kind.info| ==> + !fromType.resolved.kind.info[i].variance.Nonvariant?) + else + false + , seq(|fromTpe.arguments|, i => i)) else seq(|fromTpe.arguments|, i => i); var lambdas :- diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect index cb1f36afd41..5cd1da2b7ff 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect @@ -1,5 +1,5 @@ -Dafny program verifier finished with 4 verified, 0 errors +Dafny program verifier finished with 12 verified, 0 errors ADatatype.ADatatype(2) true false diff --git a/docs/HowToFAQ/Errors-Compiler.md b/docs/HowToFAQ/Errors-Compiler.md index da243df24e4..71b11482255 100644 --- a/docs/HowToFAQ/Errors-Compiler.md +++ b/docs/HowToFAQ/Errors-Compiler.md @@ -45,15 +45,6 @@ so the program will need to be revised to avoid this feature; The latter is an omission in the in-tool documentation. Please report this error message and the part of the program provoking it to the Dafny team's [issue tracker](https://github.com/dafny-lang/dafny/issues). -## **Error: Abstract type ('_type_') with extern attribute requires a compile hint. Expected {:extern _hint_}** {#c_abstract_type_needs_hint} - - -```dafny -type {:extern } T -``` - -The type needs a name given to know which type in the target language it is associated with. - ## **Error: Abstract type (_name_) cannot be compiled; perhaps make it a type synonym or use :extern.** {#c_abstract_type_cannot_be_compiled} From 71703d993e17b52531396eefb9370c51db8f2996 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 3 Jan 2025 12:44:06 -0600 Subject: [PATCH 41/69] Regenerated core files --- Source/DafnyCore/Backends/GeneratorErrors.cs | 6 - .../SinglePassCodeGenerator.cs | 8 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 140 ++++++++++-------- 3 files changed, 76 insertions(+), 78 deletions(-) diff --git a/Source/DafnyCore/Backends/GeneratorErrors.cs b/Source/DafnyCore/Backends/GeneratorErrors.cs index 1d1ebc80f2d..32b4aa04ff3 100644 --- a/Source/DafnyCore/Backends/GeneratorErrors.cs +++ b/Source/DafnyCore/Backends/GeneratorErrors.cs @@ -13,7 +13,6 @@ public enum ErrorId { c_process_exit, c_process_failed_to_start, c_unsupported_feature, - c_abstract_type_needs_hint, c_abstract_type_cannot_be_compiled, c_iterators_are_not_deterministic, c_iterator_has_no_body, @@ -87,11 +86,6 @@ such as the proper files not having the correct permissions. - the feature is not listed in the in-tool list of unsupported features. The latter is an omission in the in-tool documentation. Please report this error message and the part of the program provoking it to the Dafny team's [issue tracker](https://github.com/dafny-lang/dafny/issues). -".TrimStart()); - - Add(ErrorId.c_abstract_type_needs_hint, - @" -The type needs a name given to know which type in the target language it is associated with. ".TrimStart()); Add(ErrorId.c_abstract_type_cannot_be_compiled, diff --git a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs index 08d9d43abfd..44e0fc71809 100644 --- a/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs +++ b/Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs @@ -1632,13 +1632,7 @@ private void EmitModule(Program program, ConcreteSyntaxTree programNode, ModuleD }; } Contract.Assert(exprs != null); // because externP is true - if (exprs.Count == 1) { - DeclareExternType(at, exprs[0], wr); - } else { - Error(ErrorId.c_abstract_type_needs_hint, d.Origin, - "Abstract type ('{0}') with extern attribute requires a compile hint. Expected {{:extern compile_type_hint}}", - wr, at.FullName); - } + DeclareExternType(at, exprs[0], wr); v.Visit(exprs); } else { diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 10734c1415a..89f34839343 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -642,7 +642,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _26_upcastTrait = (this).Upcast; } _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_26_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_23_parentTpe)))); - if ((_22_parentTyp).IsGeneralTrait()) { + if (((_22_parentTyp).IsGeneralTrait()) && (((t).dtor_traitType).is_GeneralTrait)) { RAST._IModDecl _27_upcastDynTrait; _27_upcastDynTrait = Defs.__default.UpcastDynTraitFor(_1_rTypeParamsDecls, _19_instantiatedFullType, _23_parentTpe, _25_parentTpeExpr); _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(_27_upcastDynTrait)); @@ -3858,16 +3858,26 @@ public RAST._IExpr WrapWithNewtype(RAST._IExpr expr, Defs._IOwnership exprOwners } return r; } - public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) + public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpeWithSynonyms, DAST._IType toTpeWithSynonyms, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) { r = RAST.Expr.Default(); resultingOwnership = Defs.Ownership.Default(); - r = expr; DAST._IType _0_fromTpe; - _0_fromTpe = (fromTpe).RemoveSynonyms(); + _0_fromTpe = (fromTpeWithSynonyms).RemoveSynonyms(); DAST._IType _1_toTpe; - _1_toTpe = (toTpe).RemoveSynonyms(); - if (object.Equals(_0_fromTpe, _1_toTpe)) { + _1_toTpe = (toTpeWithSynonyms).RemoveSynonyms(); + RAST._IExpr _out0; + Defs._IOwnership _out1; + (this).GenExprConvertToWithoutSynonyms(expr, exprOwnership, _0_fromTpe, _1_toTpe, env, expectedOwnership, out _out0, out _out1); + r = _out0; + resultingOwnership = _out1; + } + public void GenExprConvertToWithoutSynonyms(RAST._IExpr expr, Defs._IOwnership exprOwnership, DAST._IType fromTpe, DAST._IType toTpe, Defs._IEnvironment env, Defs._IOwnership expectedOwnership, out RAST._IExpr r, out Defs._IOwnership resultingOwnership) + { + r = RAST.Expr.Default(); + resultingOwnership = Defs.Ownership.Default(); + r = expr; + if (object.Equals(fromTpe, toTpe)) { RAST._IExpr _out0; Defs._IOwnership _out1; (this).FromOwnership(r, exprOwnership, expectedOwnership, out _out0, out _out1); @@ -3875,27 +3885,27 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D resultingOwnership = _out1; return ; } - if (Defs.__default.NeedsUnwrappingConversion(_0_fromTpe)) { + if (Defs.__default.NeedsUnwrappingConversion(fromTpe)) { RAST._IExpr _out2; - _out2 = (this).UnwrapNewtype(r, exprOwnership, _0_fromTpe); + _out2 = (this).UnwrapNewtype(r, exprOwnership, fromTpe); r = _out2; RAST._IExpr _out3; Defs._IOwnership _out4; - (this).GenExprConvertTo(r, exprOwnership, (((_0_fromTpe).dtor_resolved).dtor_kind).dtor_baseType, _1_toTpe, env, expectedOwnership, out _out3, out _out4); + (this).GenExprConvertToWithoutSynonyms(r, exprOwnership, (((fromTpe).dtor_resolved).dtor_kind).dtor_baseType, toTpe, env, expectedOwnership, out _out3, out _out4); r = _out3; resultingOwnership = _out4; return ; } - if (Defs.__default.NeedsUnwrappingConversion(_1_toTpe)) { - DAST._IResolvedTypeBase _2_toKind; - _2_toKind = ((_1_toTpe).dtor_resolved).dtor_kind; + if (Defs.__default.NeedsUnwrappingConversion(toTpe)) { + DAST._IResolvedTypeBase _0_toKind; + _0_toKind = ((toTpe).dtor_resolved).dtor_kind; RAST._IExpr _out5; Defs._IOwnership _out6; - (this).GenExprConvertTo(r, exprOwnership, _0_fromTpe, (_2_toKind).dtor_baseType, env, expectedOwnership, out _out5, out _out6); + (this).GenExprConvertToWithoutSynonyms(r, exprOwnership, fromTpe, (_0_toKind).dtor_baseType, env, expectedOwnership, out _out5, out _out6); r = _out5; resultingOwnership = _out6; RAST._IExpr _out7; - _out7 = (this).WrapWithNewtype(r, resultingOwnership, _1_toTpe); + _out7 = (this).WrapWithNewtype(r, resultingOwnership, toTpe); r = _out7; RAST._IExpr _out8; Defs._IOwnership _out9; @@ -3904,30 +3914,30 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D resultingOwnership = _out9; return ; } - Std.Wrappers._IOption _3_unwrappedFromType; - _3_unwrappedFromType = Defs.__default.GetUnwrappedBoundedRustType(_0_fromTpe); - Std.Wrappers._IOption _4_unwrappedToType; - _4_unwrappedToType = Defs.__default.GetUnwrappedBoundedRustType(_1_toTpe); - if ((_4_unwrappedToType).is_Some) { - RAST._IType _5_boundedToType; - _5_boundedToType = (_4_unwrappedToType).dtor_value; - if ((_3_unwrappedFromType).is_Some) { + Std.Wrappers._IOption _1_unwrappedFromType; + _1_unwrappedFromType = Defs.__default.GetUnwrappedBoundedRustType(fromTpe); + Std.Wrappers._IOption _2_unwrappedToType; + _2_unwrappedToType = Defs.__default.GetUnwrappedBoundedRustType(toTpe); + if ((_2_unwrappedToType).is_Some) { + RAST._IType _3_boundedToType; + _3_boundedToType = (_2_unwrappedToType).dtor_value; + if ((_1_unwrappedFromType).is_Some) { RAST._IExpr _out10; - _out10 = (this).UnwrapNewtype(r, exprOwnership, _0_fromTpe); + _out10 = (this).UnwrapNewtype(r, exprOwnership, fromTpe); r = _out10; - Defs._IOwnership _6_inOwnership; - _6_inOwnership = exprOwnership; - if (!object.Equals((_3_unwrappedFromType).dtor_value, (_4_unwrappedToType).dtor_value)) { - RAST._IType _7_asType; - _7_asType = _5_boundedToType; - if (object.Equals(_6_inOwnership, Defs.Ownership.create_OwnershipBorrowed())) { + Defs._IOwnership _4_inOwnership; + _4_inOwnership = exprOwnership; + if (!object.Equals((_1_unwrappedFromType).dtor_value, (_2_unwrappedToType).dtor_value)) { + RAST._IType _5_asType; + _5_asType = _3_boundedToType; + if (object.Equals(_4_inOwnership, Defs.Ownership.create_OwnershipBorrowed())) { RAST._IExpr _source0 = r; { if (_source0.is_UnaryOp) { Dafny.ISequence op10 = _source0.dtor_op1; if (object.Equals(op10, Dafny.Sequence.UnicodeFromString("&"))) { - RAST._IExpr _8_underlying = _source0.dtor_underlying; - r = _8_underlying; + RAST._IExpr _6_underlying = _source0.dtor_underlying; + r = _6_underlying; goto after_match0; } } @@ -3937,26 +3947,26 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D } after_match0: ; } - r = RAST.Expr.create_TypeAscription(r, _7_asType); - _6_inOwnership = Defs.Ownership.create_OwnershipOwned(); + r = RAST.Expr.create_TypeAscription(r, _5_asType); + _4_inOwnership = Defs.Ownership.create_OwnershipOwned(); } RAST._IExpr _out11; - _out11 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), _1_toTpe); + _out11 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); r = _out11; RAST._IExpr _out12; Defs._IOwnership _out13; - (this).FromOwnership(r, _6_inOwnership, expectedOwnership, out _out12, out _out13); + (this).FromOwnership(r, _4_inOwnership, expectedOwnership, out _out12, out _out13); r = _out12; resultingOwnership = _out13; return ; } - if ((_0_fromTpe).IsPrimitiveInt()) { + if ((fromTpe).IsPrimitiveInt()) { if (object.Equals(exprOwnership, Defs.Ownership.create_OwnershipBorrowed())) { r = (r).Clone(); } - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("truncate!"))).AsExpr()).Apply(Dafny.Sequence.FromElements(r, RAST.Expr.create_ExprFromType(_5_boundedToType))); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("truncate!"))).AsExpr()).Apply(Dafny.Sequence.FromElements(r, RAST.Expr.create_ExprFromType(_3_boundedToType))); RAST._IExpr _out14; - _out14 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), _1_toTpe); + _out14 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); r = _out14; RAST._IExpr _out15; Defs._IOwnership _out16; @@ -3965,10 +3975,10 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D resultingOwnership = _out16; return ; } - if (object.Equals(_0_fromTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { - r = RAST.Expr.create_TypeAscription((r).Sel(Dafny.Sequence.UnicodeFromString("0")), _5_boundedToType); + if (object.Equals(fromTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { + r = RAST.Expr.create_TypeAscription((r).Sel(Dafny.Sequence.UnicodeFromString("0")), _3_boundedToType); RAST._IExpr _out17; - _out17 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), _1_toTpe); + _out17 = (this).WrapWithNewtype(r, Defs.Ownership.create_OwnershipOwned(), toTpe); r = _out17; RAST._IExpr _out18; Defs._IOwnership _out19; @@ -3977,12 +3987,12 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D resultingOwnership = _out19; return ; } - RAST._IType _9_fromTpeRust; + RAST._IType _7_fromTpeRust; RAST._IType _out20; - _out20 = (this).GenType(_0_fromTpe, Defs.GenTypeContext.@default()); - _9_fromTpeRust = _out20; + _out20 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); + _7_fromTpeRust = _out20; RAST._IExpr _out21; - _out21 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), (_9_fromTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_5_boundedToType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _out21 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), (_7_fromTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_3_boundedToType)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); r = _out21; RAST._IExpr _out22; Defs._IOwnership _out23; @@ -3991,11 +4001,11 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D resultingOwnership = _out23; return ; } - if ((_3_unwrappedFromType).is_Some) { - if (!((((_0_fromTpe).dtor_resolved).dtor_kind).dtor_erase)) { + if ((_1_unwrappedFromType).is_Some) { + if (!((((fromTpe).dtor_resolved).dtor_kind).dtor_erase)) { r = (r).Sel(Dafny.Sequence.UnicodeFromString("0")); } - if (object.Equals(_1_toTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { + if (object.Equals(toTpe, DAST.Type.create_Primitive(DAST.Primitive.create_Char()))) { RAST._IExpr _out24; Defs._IOwnership _out25; (this).FromOwnership((((RAST.__default.dafny__runtime).MSel((this).DafnyChar)).AsExpr()).Apply1(RAST.Expr.create_TypeAscription(r, (this).DafnyCharUnderlying)), exprOwnership, expectedOwnership, out _out24, out _out25); @@ -4003,7 +4013,7 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D resultingOwnership = _out25; return ; } - if ((_1_toTpe).IsPrimitiveInt()) { + if ((toTpe).IsPrimitiveInt()) { RAST._IExpr _out26; Defs._IOwnership _out27; (this).FromOwnership(r, exprOwnership, Defs.Ownership.create_OwnershipOwned(), out _out26, out _out27); @@ -4017,12 +4027,12 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D resultingOwnership = _out29; return ; } - RAST._IType _10_toTpeRust; + RAST._IType _8_toTpeRust; RAST._IType _out30; - _out30 = (this).GenType(_1_toTpe, Defs.GenTypeContext.@default()); - _10_toTpeRust = _out30; + _out30 = (this).GenType(toTpe, Defs.GenTypeContext.@default()); + _8_toTpeRust = _out30; RAST._IExpr _out31; - _out31 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), ((_3_unwrappedFromType).dtor_value)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_10_toTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); + _out31 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("No conversion available from "), ((_1_unwrappedFromType).dtor_value)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to ")), (_8_toTpeRust)._ToString(Dafny.Sequence.UnicodeFromString(""))), (this).InitEmptyExpr()); r = _out31; RAST._IExpr _out32; Defs._IOwnership _out33; @@ -4031,7 +4041,7 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D resultingOwnership = _out33; return ; } - _System._ITuple2 _source1 = _System.Tuple2.create(_0_fromTpe, _1_toTpe); + _System._ITuple2 _source1 = _System.Tuple2.create(fromTpe, toTpe); { DAST._IType _00 = _source1.dtor__0; if (_00.is_Primitive) { @@ -4088,20 +4098,20 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D DAST._IPrimitive _h75 = _12.dtor_Primitive_a0; if (_h75.is_Char) { { - RAST._IType _11_rhsType; + RAST._IType _9_rhsType; RAST._IType _out38; - _out38 = (this).GenType(_1_toTpe, Defs.GenTypeContext.@default()); - _11_rhsType = _out38; - RAST._IType _12_uType; + _out38 = (this).GenType(toTpe, Defs.GenTypeContext.@default()); + _9_rhsType = _out38; + RAST._IType _10_uType; if (((this).charType).is_UTF32) { - _12_uType = RAST.Type.create_U32(); + _10_uType = RAST.Type.create_U32(); } else { - _12_uType = RAST.Type.create_U16(); + _10_uType = RAST.Type.create_U16(); } if (!object.Equals(exprOwnership, Defs.Ownership.create_OwnershipOwned())) { r = (r).Clone(); } - r = ((((RAST.Expr.create_TraitCast(_12_uType, ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("NumCast"))).AsType())).FSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(r)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0(); + r = ((((RAST.Expr.create_TraitCast(_10_uType, ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("NumCast"))).AsType())).FSel(Dafny.Sequence.UnicodeFromString("from"))).Apply1(r)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0(); if (((this).charType).is_UTF32) { r = ((((RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("char"))).FSel(Dafny.Sequence.UnicodeFromString("from_u32"))).Apply1(r)).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0(); } @@ -4128,10 +4138,10 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D DAST._IPrimitive _h77 = _13.dtor_Primitive_a0; if (_h77.is_Int) { { - RAST._IType _13_rhsType; + RAST._IType _11_rhsType; RAST._IType _out41; - _out41 = (this).GenType(_0_fromTpe, Defs.GenTypeContext.@default()); - _13_rhsType = _out41; + _out41 = (this).GenType(fromTpe, Defs.GenTypeContext.@default()); + _11_rhsType = _out41; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1((r).Sel(Dafny.Sequence.UnicodeFromString("0"))); RAST._IExpr _out42; Defs._IOwnership _out43; @@ -4149,7 +4159,7 @@ public void GenExprConvertTo(RAST._IExpr expr, Defs._IOwnership exprOwnership, D { RAST._IExpr _out44; Defs._IOwnership _out45; - (this).GenExprConvertOther(expr, exprOwnership, _0_fromTpe, _1_toTpe, env, expectedOwnership, out _out44, out _out45); + (this).GenExprConvertOther(expr, exprOwnership, fromTpe, toTpe, env, expectedOwnership, out _out44, out _out45); r = _out44; resultingOwnership = _out45; } From 617695cc9dc12acfb3b9e9b20e71dce8a2d0d1a0 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 3 Jan 2025 13:17:09 -0600 Subject: [PATCH 42/69] Fixed template and expect files --- .../LitTest/comp/rust/small/06-type-bounds.dfy.expect | 3 ++- .../comp/rust/small/07-instantiated-methods.dfy.expect | 1 + .../small/08-not-all-trait-items-implemented.dfy.expect | 1 + .../rust/small/10-type-parameter-equality.dfy.expect | 1 + docs/HowToFAQ/Errors-Compiler.template | 9 --------- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect index fabcdc8b30a..6a661c1e0cb 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy.expect @@ -1,2 +1,3 @@ -Dafny program verifier finished with 2 verified, 0 errors + +Dafny program verifier finished with 5 verified, 0 errors hellohellohellohellohellohello \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect index 19e90eca854..d2b8ffb5439 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy.expect @@ -1,2 +1,3 @@ + Dafny program verifier finished with 1 verified, 0 errors ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect index 32b63f1961a..9a27c3259f3 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy.expect @@ -1,2 +1,3 @@ + Dafny program verifier finished with 5 verified, 0 errors ping pong \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect index 19e90eca854..d2b8ffb5439 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy.expect @@ -1,2 +1,3 @@ + Dafny program verifier finished with 1 verified, 0 errors ok \ No newline at end of file diff --git a/docs/HowToFAQ/Errors-Compiler.template b/docs/HowToFAQ/Errors-Compiler.template index c6591bd1bce..0e4bec4dda4 100644 --- a/docs/HowToFAQ/Errors-Compiler.template +++ b/docs/HowToFAQ/Errors-Compiler.template @@ -24,15 +24,6 @@ -## **Error: Abstract type ('_type_') with extern attribute requires a compile hint. Expected {:extern _hint_}** {#c_abstract_type_needs_hint} - - -```dafny -type {:extern } T -``` - - - ## **Error: Abstract type (_name_) cannot be compiled; perhaps make it a type synonym or use :extern.** {#c_abstract_type_cannot_be_compiled} From 5e7d31256ac3e8c9acb14c30097fcfd6a3d679a1 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 3 Jan 2025 13:19:01 -0600 Subject: [PATCH 43/69] Updated runtime rust --- .../DafnyRuntimeRust/src/system/mod.rs | 818 +++++++++--------- 1 file changed, 399 insertions(+), 419 deletions(-) diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs index a274e83506e..d671ea22d59 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs @@ -11,15 +11,15 @@ pub mod _System { pub use ::std::rc::Rc; pub use ::std::cmp::Eq; pub use ::std::hash::Hash; + pub use ::std::cmp::PartialEq; pub use ::std::hash::Hasher; - pub use ::std::default::Default; pub use ::std::convert::AsRef; pub use crate::SequenceIter; pub use crate::seq; pub type nat = DafnyInt; - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple2 { _T2 { _0: T0, @@ -81,7 +81,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple2 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple2::_T2{_0, _1, }, Tuple2::_T2{_0: _2__0, _1: _2__1, }) => { + _0 == _2__0 && _1 == _2__1 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple2 {} impl Hash @@ -96,16 +113,6 @@ pub mod _System { } } - impl Default - for Tuple2 { - fn default() -> Tuple2 { - Tuple2::_T2 { - _0: Default::default(), - _1: Default::default() - } - } - } - impl AsRef> for Tuple2 { fn as_ref(&self) -> &Self { @@ -113,7 +120,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple0 { _T0 {} } @@ -146,6 +153,23 @@ pub mod _System { } } + impl PartialEq + for Tuple0 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple0::_T0{}, Tuple0::_T0{}) => { + true + }, + _ => { + false + }, + } + } + } + impl Eq for Tuple0 {} @@ -160,13 +184,6 @@ pub mod _System { } } - impl Default - for Tuple0 { - fn default() -> Tuple0 { - Tuple0::_T0 {} - } - } - impl AsRef for Tuple0 { fn as_ref(&self) -> &Self { @@ -174,7 +191,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple1 { _T1 { _0: T0 @@ -226,7 +243,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple1 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple1::_T1{_0, }, Tuple1::_T1{_0: _2__0, }) => { + _0 == _2__0 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple1 {} impl Hash @@ -240,15 +274,6 @@ pub mod _System { } } - impl Default - for Tuple1 { - fn default() -> Tuple1 { - Tuple1::_T1 { - _0: Default::default() - } - } - } - impl AsRef> for Tuple1 { fn as_ref(&self) -> &Self { @@ -256,7 +281,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple3 { _T3 { _0: T0, @@ -328,7 +353,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple3 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple3::_T3{_0, _1, _2, }, Tuple3::_T3{_0: _2__0, _1: _2__1, _2: _2__2, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple3 {} impl Hash @@ -344,17 +386,6 @@ pub mod _System { } } - impl Default - for Tuple3 { - fn default() -> Tuple3 { - Tuple3::_T3 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default() - } - } - } - impl AsRef> for Tuple3 { fn as_ref(&self) -> &Self { @@ -362,7 +393,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple4 { _T4 { _0: T0, @@ -444,7 +475,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple4 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple4::_T4{_0, _1, _2, _3, }, Tuple4::_T4{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple4 {} impl Hash @@ -461,18 +509,6 @@ pub mod _System { } } - impl Default - for Tuple4 { - fn default() -> Tuple4 { - Tuple4::_T4 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default() - } - } - } - impl AsRef> for Tuple4 { fn as_ref(&self) -> &Self { @@ -480,7 +516,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple5 { _T5 { _0: T0, @@ -572,7 +608,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple5 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple5::_T5{_0, _1, _2, _3, _4, }, Tuple5::_T5{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple5 {} impl Hash @@ -590,19 +643,6 @@ pub mod _System { } } - impl Default - for Tuple5 { - fn default() -> Tuple5 { - Tuple5::_T5 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default() - } - } - } - impl AsRef> for Tuple5 { fn as_ref(&self) -> &Self { @@ -610,7 +650,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple6 { _T6 { _0: T0, @@ -712,7 +752,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple6 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple6::_T6{_0, _1, _2, _3, _4, _5, }, Tuple6::_T6{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple6 {} impl Hash @@ -731,20 +788,6 @@ pub mod _System { } } - impl Default - for Tuple6 { - fn default() -> Tuple6 { - Tuple6::_T6 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default() - } - } - } - impl AsRef> for Tuple6 { fn as_ref(&self) -> &Self { @@ -752,7 +795,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple7 { _T7 { _0: T0, @@ -864,7 +907,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple7 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, }, Tuple7::_T7{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple7 {} impl Hash @@ -884,21 +944,6 @@ pub mod _System { } } - impl Default - for Tuple7 { - fn default() -> Tuple7 { - Tuple7::_T7 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default() - } - } - } - impl AsRef> for Tuple7 { fn as_ref(&self) -> &Self { @@ -906,7 +951,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple8 { _T8 { _0: T0, @@ -1028,7 +1073,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple8 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, }, Tuple8::_T8{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple8 {} impl Hash @@ -1049,22 +1111,6 @@ pub mod _System { } } - impl Default - for Tuple8 { - fn default() -> Tuple8 { - Tuple8::_T8 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default() - } - } - } - impl AsRef> for Tuple8 { fn as_ref(&self) -> &Self { @@ -1072,7 +1118,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple9 { _T9 { _0: T0, @@ -1204,7 +1250,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple9 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, }, Tuple9::_T9{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple9 {} impl Hash @@ -1226,23 +1289,6 @@ pub mod _System { } } - impl Default - for Tuple9 { - fn default() -> Tuple9 { - Tuple9::_T9 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default() - } - } - } - impl AsRef> for Tuple9 { fn as_ref(&self) -> &Self { @@ -1250,7 +1296,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple10 { _T10 { _0: T0, @@ -1392,7 +1438,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple10 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, }, Tuple10::_T10{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple10 {} impl Hash @@ -1415,24 +1478,6 @@ pub mod _System { } } - impl Default - for Tuple10 { - fn default() -> Tuple10 { - Tuple10::_T10 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default() - } - } - } - impl AsRef> for Tuple10 { fn as_ref(&self) -> &Self { @@ -1440,7 +1485,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple11 { _T11 { _0: T0, @@ -1592,7 +1637,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple11 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, }, Tuple11::_T11{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple11 {} impl Hash @@ -1616,25 +1678,6 @@ pub mod _System { } } - impl Default - for Tuple11 { - fn default() -> Tuple11 { - Tuple11::_T11 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default() - } - } - } - impl AsRef> for Tuple11 { fn as_ref(&self) -> &Self { @@ -1642,7 +1685,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple12 { _T12 { _0: T0, @@ -1804,7 +1847,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple12 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, }, Tuple12::_T12{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple12 {} impl Hash @@ -1829,26 +1889,6 @@ pub mod _System { } } - impl Default - for Tuple12 { - fn default() -> Tuple12 { - Tuple12::_T12 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default() - } - } - } - impl AsRef> for Tuple12 { fn as_ref(&self) -> &Self { @@ -1856,7 +1896,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple13 { _T13 { _0: T0, @@ -2028,7 +2068,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple13 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, }, Tuple13::_T13{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple13 {} impl Hash @@ -2054,27 +2111,6 @@ pub mod _System { } } - impl Default - for Tuple13 { - fn default() -> Tuple13 { - Tuple13::_T13 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default() - } - } - } - impl AsRef> for Tuple13 { fn as_ref(&self) -> &Self { @@ -2082,7 +2118,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple14 { _T14 { _0: T0, @@ -2264,7 +2300,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple14 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, }, Tuple14::_T14{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple14 {} impl Hash @@ -2291,28 +2344,6 @@ pub mod _System { } } - impl Default - for Tuple14 { - fn default() -> Tuple14 { - Tuple14::_T14 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default() - } - } - } - impl AsRef> for Tuple14 { fn as_ref(&self) -> &Self { @@ -2320,7 +2351,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple15 { _T15 { _0: T0, @@ -2512,7 +2543,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple15 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, }, Tuple15::_T15{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple15 {} impl Hash @@ -2540,29 +2588,6 @@ pub mod _System { } } - impl Default - for Tuple15 { - fn default() -> Tuple15 { - Tuple15::_T15 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default() - } - } - } - impl AsRef> for Tuple15 { fn as_ref(&self) -> &Self { @@ -2570,7 +2595,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple16 { _T16 { _0: T0, @@ -2772,7 +2797,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple16 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, }, Tuple16::_T16{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple16 {} impl Hash @@ -2801,30 +2843,6 @@ pub mod _System { } } - impl Default - for Tuple16 { - fn default() -> Tuple16 { - Tuple16::_T16 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default(), - _15: Default::default() - } - } - } - impl AsRef> for Tuple16 { fn as_ref(&self) -> &Self { @@ -2832,7 +2850,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple17 { _T17 { _0: T0, @@ -3044,7 +3062,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple17 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, }, Tuple17::_T17{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple17 {} impl Hash @@ -3074,31 +3109,6 @@ pub mod _System { } } - impl Default - for Tuple17 { - fn default() -> Tuple17 { - Tuple17::_T17 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default(), - _15: Default::default(), - _16: Default::default() - } - } - } - impl AsRef> for Tuple17 { fn as_ref(&self) -> &Self { @@ -3106,7 +3116,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple18 { _T18 { _0: T0, @@ -3328,7 +3338,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple18 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, }, Tuple18::_T18{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple18 {} impl Hash @@ -3359,32 +3386,6 @@ pub mod _System { } } - impl Default - for Tuple18 { - fn default() -> Tuple18 { - Tuple18::_T18 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default(), - _15: Default::default(), - _16: Default::default(), - _17: Default::default() - } - } - } - impl AsRef> for Tuple18 { fn as_ref(&self) -> &Self { @@ -3392,7 +3393,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple19 { _T19 { _0: T0, @@ -3624,7 +3625,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple19 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, }, Tuple19::_T19{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, _18: _2__18, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 && _18 == _2__18 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple19 {} impl Hash @@ -3656,33 +3674,6 @@ pub mod _System { } } - impl Default - for Tuple19 { - fn default() -> Tuple19 { - Tuple19::_T19 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default(), - _15: Default::default(), - _16: Default::default(), - _17: Default::default(), - _18: Default::default() - } - } - } - impl AsRef> for Tuple19 { fn as_ref(&self) -> &Self { @@ -3690,7 +3681,7 @@ pub mod _System { } } - #[derive(PartialEq, Clone)] + #[derive(Clone)] pub enum Tuple20 { _T20 { _0: T0, @@ -3932,7 +3923,24 @@ pub mod _System { } } - impl Eq + impl PartialEq + for Tuple20 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, }, Tuple20::_T20{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, _18: _2__18, _19: _2__19, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 && _18 == _2__18 && _19 == _2__19 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple20 {} impl Hash @@ -3965,34 +3973,6 @@ pub mod _System { } } - impl Default - for Tuple20 { - fn default() -> Tuple20 { - Tuple20::_T20 { - _0: Default::default(), - _1: Default::default(), - _2: Default::default(), - _3: Default::default(), - _4: Default::default(), - _5: Default::default(), - _6: Default::default(), - _7: Default::default(), - _8: Default::default(), - _9: Default::default(), - _10: Default::default(), - _11: Default::default(), - _12: Default::default(), - _13: Default::default(), - _14: Default::default(), - _15: Default::default(), - _16: Default::default(), - _17: Default::default(), - _18: Default::default(), - _19: Default::default() - } - } - } - impl AsRef> for Tuple20 { fn as_ref(&self) -> &Self { From c8b17396a5605c9a443cddd820fc9964bc56aaf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Mayer?= Date: Wed, 15 Jan 2025 05:40:14 -0600 Subject: [PATCH 44/69] Update Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs --- Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 3b738c2582b..b0da37a90ee 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -282,8 +282,8 @@ protected override IClassWriter CreateTrait(string name, bool isExtern, List Date: Wed, 15 Jan 2025 07:34:25 -0600 Subject: [PATCH 45/69] code review --- .../Resolver/TypeCharacteristicChecker.cs | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs b/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs index 410ce5c6e8e..81948edd90b 100644 --- a/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs +++ b/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs @@ -41,22 +41,13 @@ private static void InferEqualitySupport(List declarations, ErrorR foreach (var tp in dt.TypeArgs) { if (tp.Characteristics.EqualitySupport == TypeParameter.EqualitySupportValue.Unspecified) { // here's our chance to infer the need for equality support - foreach (var ctor in dt.Ctors) { - foreach (var arg in ctor.Formals) { - if (InferAndSetEqualitySupport(tp, arg.Type, reporter)) { - inferredSomething = true; - goto DONE_DT; // break out of the doubly-nested loop - } - } - } - - foreach (var parentType in dt.ParentTraits) { - if (InferAndSetEqualitySupport(tp, parentType, reporter)) { - inferredSomething = true; - goto DONE_DT; // break out of the doubly-nested loop - } - } - DONE_DT:; + inferredSomething = dt.Ctors.Any(ctor => + ctor.Formals.Any(arg => + InferAndSetEqualitySupport(tp, arg.Type, reporter) + ) + ) || dt.ParentTraits.Any(parentType => + InferAndSetEqualitySupport(tp, parentType, reporter) + ); } } } else if (d is TypeSynonymDecl syn) { From ccb8619d094bec7f8f1ae4dabcde919b158454ac Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Thu, 23 Jan 2025 12:20:25 -0600 Subject: [PATCH 46/69] Review comments --- .../AST/TypeDeclarations/TraitDecl.cs | 76 ++++++++++++++++ .../Backends/Dafny/DafnyCodeGenerator.cs | 91 +------------------ 2 files changed, 78 insertions(+), 89 deletions(-) diff --git a/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs b/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs index dd67c4481dd..48ccc105d61 100644 --- a/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs +++ b/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.Dafny.Auditor; using System.Diagnostics.Contracts; +using System.Linq; namespace Microsoft.Dafny; @@ -43,4 +44,79 @@ public override IEnumerable Assumptions(Declaration decl) { yield return new Assumption(this, Origin, AssumptionDescription.HasTerminationFalseAttribute); } } + + // Given a trait declaration, returns the list of traits that this trait can downcast to, + // using its type parameters only (no run-time information about the type available) + // Used in backends that apply monomorphization + public List DowncastableSubTraitsIfMonomorphized() { + var downcastableTraits = new List(); + foreach (var subTrait in TraitDeclsCanBeDowncastedTo) { + // Recovers which of the parent traits of the subTraits is the current trait declaration + var parentTrait = subTrait.ParentTraits.FirstOrDefault(t => t.AsTraitType == this); + Type downcastType = null; + if (parentTrait is UserDefinedType { TypeArgs: var parentTypeArguments } && + CanDowncastIfMonomorphized(parentTypeArguments, subTrait, ref downcastType)) { + downcastableTraits.Add(downcastType); + } + } + + return downcastableTraits; + } + + /// When traits generics are monomorphized, i.e. they are simply instantiated for every type for which they are used, + /// it becomes impossible to express some downcasts in the target language. For example, + /// trait SuperTrait {} + /// trait SubTrait extends SuperTrait {} + /// Although it's possible to cast a SubTrait to a SuperTrait, the other direction is not possible + /// if traits are monomorphized, because there could be infinitely new traits depending on the generic argument, + /// and traits only build a finite virtual dispatch table. + /// This algorithm determines if there are enough type parameters in common so that the downcast can be known + /// no matter what + public bool CanDowncastIfMonomorphized( + List parentTypeArguments, TraitDecl subTrait, ref Type downcastType) { + // Algorithm: + // trait Sub extends Parent where trait Parent + // Foreach type parameter in the parent TPi + // if PTi is some TCj, store the mapping TCj => TPi. We need only to store the first of such mapping + // If PTi is anything else, ok + // End of the loop: if not all children type parameters were found, cancel + // build the type Sub by iterating on the type parameters TC. + Contract.Assert(TypeArgs.Count == parentTypeArguments.Count); + var mapping = new Dictionary(); + for (var i = 0; i < TypeArgs.Count; i++) { + var TP = TypeArgs[i]; + var maybeTc = parentTypeArguments[i]; + if (maybeTc is UserDefinedType { ResolvedClass: TypeParameter maybeTc2 }) { + if (subTrait.TypeArgs.Contains(maybeTc2) && !mapping.ContainsKey(maybeTc2)) { + mapping.Add(maybeTc2, new UserDefinedType(TP)); + } + } + } + + var allTypeParametersCovered = subTrait.TypeArgs.TrueForAll( + tp => mapping.ContainsKey(tp)); + if (allTypeParametersCovered) { + // Now we need to make sure that type characteristics are compatible + var typeArgs = subTrait.TypeArgs.Select(tp => mapping[tp]).ToList(); + for (var i = 0; i < typeArgs.Count; i++) { + var downcastTypeParam = subTrait.TypeArgs[i]; + var parentType = typeArgs[i]; + if (!IsCompatibleWith(parentType, downcastTypeParam)) { + return false; + } + } + + var subTraitTypeDowncastable = + new UserDefinedType(Token.NoToken, subTrait.Name, subTrait, typeArgs); + downcastType = subTraitTypeDowncastable; + return true; + } + + return false; + } + + private static bool IsCompatibleWith(Type type, TypeParameter typeParameter) { + return (typeParameter.Characteristics.EqualitySupport == TypeParameter.EqualitySupportValue.Unspecified || + type.SupportsEquality) && typeParameter.TypeBounds.TrueForAll(t => type.IsSubtypeOf(t, false, true)); + } } \ No newline at end of file diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index b0da37a90ee..76d1df75e7f 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -281,100 +281,13 @@ protected override IClassWriter CreateTrait(string name, bool isExtern, List DowncastableTraitsTypes(TraitDecl trait) { - var downcastableTraits = new List(); - foreach (var subTrait in trait.TraitDeclsCanBeDowncastedTo) { - // Recovers which of the parent traits of the subTraits is the current trait declaration - var parentTrait = subTrait.ParentTraits.FirstOrDefault(t => t.AsTraitType == trait); - if (parentTrait != null && CanDowncast(parentTrait, subTrait, out var downcastType)) { - downcastableTraits.Add(downcastType); - } - } - - return downcastableTraits; - } - - /// - /// Given an instantiated parent type of the given subTrait, - /// return true if it's possible to describe the trait subTrait from the parent's own type parameters. - /// and an instantiation of such type. - /// This makes it possible to downcast the trait at run-time. - /// For example: - /// - /// trait Sub extends Parent where trait Parent - /// ===? true and Sub - /// trait Sub extends Parent> where trait Parent - /// ==> true and Sub (could have been Sub too) - /// trait Sub extends Parent where trait Parent - /// ==> true and Sub - /// trait Sub extends Parent> where trait Parent - /// ==> false and null - /// trait Sub extends Parent where trait Parent - /// ==> false and null - /// - private static bool CanDowncast(Type parentTrait, TraitDecl subTrait, out Type downcastType) { - Contract.Requires(parentTrait.AsTraitType != null); - var parentTraitDecl = parentTrait.AsTraitType; - var canDowncast = false; - downcastType = null; - if (parentTrait is UserDefinedType { TypeArgs: var PT }) { - // Algorithm: - // trait Sub extends Parent where trait Parent - // Foreach type parameter in the parent TPi - // if PTi is some TCj, store the mapping TCj => TPi. We need only to store the first of such mapping - // If PTi is anything else, ok - // End of the loop: if not all children type parameters were found, cancel - // build the type Sub by iterating on the type parameters TC. - Contract.Assert(parentTraitDecl.TypeArgs.Count == PT.Count); - var mapping = new Dictionary(); - for (var i = 0; i < parentTraitDecl.TypeArgs.Count; i++) { - var TP = parentTraitDecl.TypeArgs[i]; - var maybeTc = PT[i]; - if (maybeTc is UserDefinedType { ResolvedClass: TypeParameter maybeTc2 }) { - if (subTrait.TypeArgs.Contains(maybeTc2) && !mapping.ContainsKey(maybeTc2)) { - mapping.Add(maybeTc2, new UserDefinedType(TP)); - } - } - } - - var allTypeParametersCovered = subTrait.TypeArgs.TrueForAll( - tp => mapping.ContainsKey(tp)); - if (allTypeParametersCovered) { - // Now we need to make sure that type characteristics are compatible - var typeArgs = subTrait.TypeArgs.Select(tp => mapping[tp]).ToList(); - for (var i = 0; i < typeArgs.Count; i++) { - var downcastTypeParam = subTrait.TypeArgs[i]; - var parentType = typeArgs[i]; - if (!IsCompatibleWith(parentType, downcastTypeParam)) { - return false; - } - } - - var subTraitTypeDowncastable = - new UserDefinedType(Token.NoToken, subTrait.Name, subTrait, typeArgs); - downcastType = subTraitTypeDowncastable; - canDowncast = true; - } - } - - return canDowncast; - } - - private static bool IsCompatibleWith(Type type, TypeParameter typeParameter) { - return (typeParameter.Characteristics.EqualitySupport == TypeParameter.EqualitySupportValue.Unspecified || - type.SupportsEquality) && typeParameter.TypeBounds.TrueForAll(t => type.IsSubtypeOf(t, false, true)); - } - protected override ConcreteSyntaxTree CreateIterator(IteratorDecl iter, ConcreteSyntaxTree wr) { AddUnsupportedFeature(iter.Origin, Feature.Iterators); return wr; @@ -456,7 +369,7 @@ private List GenTypeParams(List typePargs) { .Where(t => t != null).ToHashSet(); foreach (var superClass in superClasses) { if (superClass.AsTraitType is { } traitDecl) { - var downcastableTraitTypes = DowncastableTraitsTypes(traitDecl); + var downcastableTraitTypes = traitDecl.DowncastableSubTraitsIfMonomorphized(); foreach (var downcastableTraitType in downcastableTraitTypes) { if (downcastableTraitType is { AsTraitType: { } downcastTraitDecl } && !traitDeclsNegative.Contains(downcastTraitDecl) && !traitDeclsImplemented.Contains(downcastTraitDecl)) { From e6c9ec260f2dc29cc828fbffc7ef2c73e3cfb7cc Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 24 Jan 2025 12:11:00 -0600 Subject: [PATCH 47/69] Fixed build and merge --- .../Rust/Dafny-compiler-rust-definitions.dfy | 3 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 6 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 1327 +++++++++-------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 83 +- .../DafnyRuntimeRust/src/system/mod.rs | 884 +++++------ 5 files changed, 1216 insertions(+), 1087 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 820c31d7f25..ef4ee65b373 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -960,6 +960,7 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { } } */ function DowncastImplFor( + rcNew: R.Expr -> R.Expr, rTypeParamsDecls: seq, datatypeType: R.Type ): Option { @@ -970,7 +971,7 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { R.self.Sel("downcast_ref").ApplyType([datatypeTypeRaw]).Apply0().Sel("is_some").Apply0(); var asBody := R.self.Sel("downcast_ref").ApplyType([datatypeTypeRaw]).Apply0().Sel("unwrap").Apply0().Sel("clone").Apply0(); - var asBody := if isRc then R.RcNew(asBody) else asBody; + var asBody := if isRc then rcNew(asBody) else asBody; Some( R.ImplDecl( R.ImplFor( diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index d5efc137e4f..84c73c62dd1 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -1253,14 +1253,14 @@ module {:extern "DCOMP"} DafnyToRustCompiler { implBody ))]; if |c.superTraitTypes| > 0 { // We will need to downcast - var fullType := if isRcWrapped then R.Rc(datatypeType) else datatypeType; + var fullType := if isRcWrapped then rc(datatypeType) else datatypeType; var downcastDefinitionOpt := DowncastTraitDeclFor(rTypeParamsDecls, fullType); if downcastDefinitionOpt.None? { var dummy := Error("Could not generate downcast definition for " + fullType.ToString("")); } else { s := s + [downcastDefinitionOpt.value]; } - var downcastImplementationsOpt := DowncastImplFor(rTypeParamsDecls, fullType); + var downcastImplementationsOpt := DowncastImplFor(rcNew, rTypeParamsDecls, fullType); if downcastImplementationsOpt.None? { var dummy := Error("Could not generate downcast implementation for " + fullType.ToString("")); } else { @@ -3334,7 +3334,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { if needsObjectFromRef { r := R.dafny_runtime.MSel("Object").AsExpr().ApplyType([R.TIdentifier("_")]).FSel("from_ref").Apply([r]); } else if needsRcWrapping { - r := R.RcNew(r.Clone()); + r := rcNew(r.Clone()); } else { if !noNeedOfClone { var needUnderscoreClone := isSelf && selfIdent.IsGeneralTrait(); diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 74337dcf4b5..bace7efb7d1 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -22,6 +22,7 @@ public COMP() { this._rootType = Defs.RootType.Default(); this._charType = Defs.CharType.Default(); this._pointerType = Defs.PointerType.Default(); + this._syncType = Defs.SyncType.Default(); } public RAST._IType Object(RAST._IType underlying) { if (((this).pointerType).is_Raw) { @@ -32,11 +33,12 @@ public RAST._IType Object(RAST._IType underlying) { } public Std.Wrappers._IOption> error {get; set;} public Dafny.ISequence> optimizations {get; set;} - public void __ctor(Defs._ICharType charType, Defs._IPointerType pointerType, Defs._IRootType rootType) + public void __ctor(Defs._ICharType charType, Defs._IPointerType pointerType, Defs._IRootType rootType, Defs._ISyncType syncType) { (this)._charType = charType; (this)._pointerType = pointerType; (this)._rootType = rootType; + (this)._syncType = syncType; (this).error = Std.Wrappers.Option>.create_None(); (this).optimizations = Dafny.Sequence>.FromElements(ExpressionOptimization.__default.apply, FactorPathsOptimization.__default.apply((this).thisFile)); } @@ -524,7 +526,7 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _out13 = (this).GenPathType(path); _28_genSelfPath = _out13; if (!(_16_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements(RAST.Type.create_DynType(RAST.__default.AnyTrait))), RAST.Type.create_TypeApp(_28_genSelfPath, _1_rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType(RAST.Type.create_DynType(RAST.__default.AnyTrait))))))))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(_2_rTypeParamsDecls, (((RAST.__default.dafny__runtime).MSel((this).Upcast)).AsType()).Apply(Dafny.Sequence.FromElements((this).DynAny)), RAST.Type.create_TypeApp(_28_genSelfPath, _1_rTypeParams), Dafny.Sequence.FromElements(RAST.ImplMember.create_ImplMemberMacro((((RAST.__default.dafny__runtime).MSel((this).UpcastFnMacro)).AsExpr()).Apply1(RAST.Expr.create_ExprFromType((this).DynAny)))))))); } Dafny.ISequence _29_superTraitTypes; if ((_16_className).Equals(Dafny.Sequence.UnicodeFromString("_default"))) { @@ -959,7 +961,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) RAST._IExpr _15_instantiation; _15_instantiation = RAST.Expr.create_StructBuild((RAST.Expr.create_Identifier(_4_datatypeName)).FSel(Defs.__default.escapeName((_12_ctor).dtor_name)), Dafny.Sequence.FromElements()); if (_0_isRcWrapped) { - _15_instantiation = RAST.__default.RcNew(_15_instantiation); + _15_instantiation = Dafny.Helpers.Id>((this).rcNew)(_15_instantiation); } _9_singletonConstructors = Dafny.Sequence.Concat(_9_singletonConstructors, Dafny.Sequence.FromElements(_15_instantiation)); } @@ -1150,7 +1152,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) Dafny.ISequence _66_coerceFormal; _66_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_55_typeI)); _53_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_53_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_59_rTypeArg, _65_rCoerceType), (RAST.Expr.create_Identifier(_66_coerceFormal)).Clone()))); - _50_coerceArguments = Dafny.Sequence.Concat(_50_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_66_coerceFormal, RAST.__default.Rc(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_59_rTypeArg), _65_rCoerceType)), RAST.__default.StaticTrait))))); + _50_coerceArguments = Dafny.Sequence.Concat(_50_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_66_coerceFormal, Dafny.Helpers.Id>((this).rc)(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_59_rTypeArg), _65_rCoerceType)), RAST.__default.StaticTrait))))); continue_2_0: ; } after_2_0: ; @@ -1171,7 +1173,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) if ((new BigInteger(((c).dtor_superTraitTypes).Count)).Sign == 1) { RAST._IType _72_fullType; if (_0_isRcWrapped) { - _72_fullType = RAST.__default.Rc(_71_datatypeType); + _72_fullType = Dafny.Helpers.Id>((this).rc)(_71_datatypeType); } else { _72_fullType = _71_datatypeType; } @@ -1186,7 +1188,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_73_downcastDefinitionOpt).dtor_value)); } Std.Wrappers._IOption _75_downcastImplementationsOpt; - _75_downcastImplementationsOpt = Defs.__default.DowncastImplFor(_3_rTypeParamsDecls, _72_fullType); + _75_downcastImplementationsOpt = Defs.__default.DowncastImplFor((this).rcNew, _3_rTypeParamsDecls, _72_fullType); if ((_75_downcastImplementationsOpt).is_None) { RAST._IExpr _76_dummy; RAST._IExpr _out16; @@ -1377,12 +1379,12 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) if ((new BigInteger((_49_rCoerceTypeParams).Count)).Sign == 1) { RAST._IExpr _123_coerceImplBody; _123_coerceImplBody = RAST.Expr.create_Match(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), _89_coerceImplBodyCases); - s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl(_3_rTypeParamsDecls, _4_datatypeName, _71_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _123_coerceImplBody))); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements(Defs.__default.CoerceImpl((this).rc, (this).rcNew, _3_rTypeParamsDecls, _4_datatypeName, _71_datatypeType, _49_rCoerceTypeParams, _50_coerceArguments, _48_coerceTypes, _123_coerceImplBody))); } if ((new BigInteger((_9_singletonConstructors).Count)) == (new BigInteger(((c).dtor_ctors).Count))) { RAST._IType _124_instantiationType; if (_0_isRcWrapped) { - _124_instantiationType = RAST.__default.Rc(_71_datatypeType); + _124_instantiationType = Dafny.Helpers.Id>((this).rc)(_71_datatypeType); } else { _124_instantiationType = _71_datatypeType; } @@ -1529,7 +1531,7 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) if (_source1.is_Datatype) { { if (Defs.__default.IsRcWrapped((_0_resolved).dtor_attributes)) { - s = RAST.__default.Rc(s); + s = Dafny.Helpers.Id>((this).rc)(s); } } goto after_match1; @@ -1554,7 +1556,7 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) if (traitType1.is_ObjectTrait) { { if (((_0_resolved).dtor_path).Equals(Dafny.Sequence>.FromElements(Dafny.Sequence.UnicodeFromString("_System"), Dafny.Sequence.UnicodeFromString("object")))) { - s = RAST.__default.AnyTrait; + s = (this).AnyTrait; } if (!((genTypeContext))) { s = (this).Object(RAST.Type.create_DynType(s)); @@ -1607,7 +1609,7 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) { if (_source0.is_Object) { { - s = RAST.__default.AnyTrait; + s = (this).AnyTrait; if (!((genTypeContext))) { s = (this).Object(RAST.Type.create_DynType(s)); } @@ -1775,7 +1777,12 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) RAST._IType _out15; _out15 = (this).GenType(_35_result, Defs.GenTypeContext.@default()); _39_resultType = _out15; - s = RAST.__default.Rc(RAST.Type.create_DynType(RAST.Type.create_FnType(_36_argTypes, _39_resultType))); + RAST._IType _40_fnType; + _40_fnType = RAST.Type.create_DynType(RAST.Type.create_FnType(_36_argTypes, _39_resultType)); + if (((this).syncType).is_Sync) { + _40_fnType = RAST.Type.create_IntersectionType(_40_fnType, (this).SyncSendType); + } + s = Dafny.Helpers.Id>((this).rc)(_40_fnType); } goto after_match0; } @@ -1783,16 +1790,16 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) { if (_source0.is_TypeArg) { Dafny.ISequence _h90 = _source0.dtor_TypeArg_a0; - Dafny.ISequence _40_name = _h90; - s = RAST.Type.create_TIdentifier(Defs.__default.escapeName(_40_name)); + Dafny.ISequence _41_name = _h90; + s = RAST.Type.create_TIdentifier(Defs.__default.escapeName(_41_name)); goto after_match0; } } { if (_source0.is_Primitive) { - DAST._IPrimitive _41_p = _source0.dtor_Primitive_a0; + DAST._IPrimitive _42_p = _source0.dtor_Primitive_a0; { - DAST._IPrimitive _source2 = _41_p; + DAST._IPrimitive _source2 = _42_p; { if (_source2.is_Int) { s = ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyInt"))).AsType(); @@ -1832,8 +1839,8 @@ public RAST._IType GenType(DAST._IType c, bool genTypeContext) } } { - Dafny.ISequence _42_v = _source0.dtor_Passthrough_a0; - s = RAST.__default.RawType(_42_v); + Dafny.ISequence _43_v = _source0.dtor_Passthrough_a0; + s = RAST.__default.RawType(_43_v); } after_match0: ; return s; @@ -4052,7 +4059,7 @@ public void GenExprConvertToWithoutSynonyms(RAST._IExpr expr, Defs._IOwnership e DAST._IPrimitive _h71 = _10.dtor_Primitive_a0; if (_h71.is_Real) { { - r = RAST.__default.RcNew(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("BigRational"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("from_integer"))).Apply1(r)); + r = Dafny.Helpers.Id>((this).rcNew)(((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("BigRational"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("from_integer"))).Apply1(r)); RAST._IExpr _out34; Defs._IOwnership _out35; (this).FromOwned(r, expectedOwnership, out _out34, out _out35); @@ -4588,7 +4595,7 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden if (_5_needsObjectFromRef) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Object"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))).FSel(Dafny.Sequence.UnicodeFromString("from_ref"))).Apply(Dafny.Sequence.FromElements(r)); } else if (_6_needsRcWrapping) { - r = RAST.__default.RcNew((r).Clone()); + r = Dafny.Helpers.Id>((this).rcNew)((r).Clone()); } else { if (!(_3_noNeedOfClone)) { bool _7_needUnderscoreClone; @@ -5169,7 +5176,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } r = RAST.Expr.create_StructBuild(r, _55_assignments); if (Defs.__default.IsRcWrapped((_47_datatypeType).dtor_attributes)) { - r = RAST.__default.RcNew(r); + r = Dafny.Helpers.Id>((this).rcNew)(r); } RAST._IExpr _out56; Defs._IOwnership _out57; @@ -5885,77 +5892,82 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _204_onExpr = _out179; _205_onOwned = _out180; _206_recIdents = _out181; - Dafny.ISequence _207_onString; - _207_onString = (_204_onExpr)._ToString(Defs.__default.IND); - Defs._IEnvironment _208_lEnv; - _208_lEnv = env; - Dafny.ISequence<_System._ITuple2, RAST._IType>> _209_args; - _209_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(); - Dafny.ISequence _210_parameters; - _210_parameters = Dafny.Sequence.FromElements(); + Defs._IEnvironment _207_lEnv; + _207_lEnv = env; + Dafny.ISequence<_System._ITuple2, RAST._IType>> _208_args; + _208_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(); + Dafny.ISequence _209_parameters; + _209_parameters = Dafny.Sequence.FromElements(); BigInteger _hi9 = new BigInteger((_203_arguments).Count); - for (BigInteger _211_i = BigInteger.Zero; _211_i < _hi9; _211_i++) { - RAST._IType _212_ty; + for (BigInteger _210_i = BigInteger.Zero; _210_i < _hi9; _210_i++) { + RAST._IType _211_ty; RAST._IType _out182; - _out182 = (this).GenType((_203_arguments).Select(_211_i), Defs.GenTypeContext.@default()); - _212_ty = _out182; - RAST._IType _213_bTy; - _213_bTy = RAST.Type.create_Borrowed(_212_ty); - Dafny.ISequence _214_name; - _214_name = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("x"), Std.Strings.__default.OfInt(_211_i)); - _208_lEnv = (_208_lEnv).AddAssigned(_214_name, _213_bTy); - _210_parameters = Dafny.Sequence.Concat(_210_parameters, Dafny.Sequence.FromElements(RAST.Formal.create(_214_name, _213_bTy))); - _209_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.Concat(_209_args, Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(_System.Tuple2, RAST._IType>.create(_214_name, _212_ty))); - } - RAST._IExpr _215_body; + _out182 = (this).GenType((_203_arguments).Select(_210_i), Defs.GenTypeContext.@default()); + _211_ty = _out182; + RAST._IType _212_bTy; + _212_bTy = RAST.Type.create_Borrowed(_211_ty); + Dafny.ISequence _213_name; + _213_name = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("x"), Std.Strings.__default.OfInt(_210_i)); + _207_lEnv = (_207_lEnv).AddAssigned(_213_name, _212_bTy); + _209_parameters = Dafny.Sequence.Concat(_209_parameters, Dafny.Sequence.FromElements(RAST.Formal.create(_213_name, _212_bTy))); + _208_args = Dafny.Sequence<_System._ITuple2, RAST._IType>>.Concat(_208_args, Dafny.Sequence<_System._ITuple2, RAST._IType>>.FromElements(_System.Tuple2, RAST._IType>.create(_213_name, _211_ty))); + } + RAST._IExpr _214_body = RAST.Expr.Default(); if (_201_isStatic) { - _215_body = (_204_onExpr).FSel(Defs.__default.escapeVar(_199_field)); + _214_body = (_204_onExpr).FSel(Defs.__default.escapeVar(_199_field)); } else { - _215_body = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("callTarget"))).Sel(Defs.__default.escapeVar(_199_field)); + _214_body = RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("callTarget")); + if (!(_200_isDatatype)) { + _214_body = ((this).read__macro).Apply1(_214_body); + } + _214_body = (_214_body).Sel(Defs.__default.escapeVar(_199_field)); } if (_202_isConstant) { - _215_body = (_215_body).Apply0(); - } - Dafny.ISequence _216_onExprArgs; - _216_onExprArgs = Dafny.Sequence.FromElements(); - BigInteger _hi10 = new BigInteger((_209_args).Count); - for (BigInteger _217_i = BigInteger.Zero; _217_i < _hi10; _217_i++) { - _System._ITuple2, RAST._IType> _let_tmp_rhs1 = (_209_args).Select(_217_i); - Dafny.ISequence _218_name = _let_tmp_rhs1.dtor__0; - RAST._IType _219_ty = _let_tmp_rhs1.dtor__1; - RAST._IExpr _220_rIdent; - Defs._IOwnership _221___v106; - Dafny.ISet> _222___v107; + _214_body = (_214_body).Apply0(); + } + Dafny.ISequence _215_onExprArgs; + _215_onExprArgs = Dafny.Sequence.FromElements(); + BigInteger _hi10 = new BigInteger((_208_args).Count); + for (BigInteger _216_i = BigInteger.Zero; _216_i < _hi10; _216_i++) { + _System._ITuple2, RAST._IType> _let_tmp_rhs1 = (_208_args).Select(_216_i); + Dafny.ISequence _217_name = _let_tmp_rhs1.dtor__0; + RAST._IType _218_ty = _let_tmp_rhs1.dtor__1; + RAST._IExpr _219_rIdent; + Defs._IOwnership _220___v106; + Dafny.ISet> _221___v107; RAST._IExpr _out183; Defs._IOwnership _out184; Dafny.ISet> _out185; - (this).GenIdent(_218_name, selfIdent, _208_lEnv, (((!(_202_isConstant)) && ((_219_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out183, out _out184, out _out185); - _220_rIdent = _out183; - _221___v106 = _out184; - _222___v107 = _out185; - _216_onExprArgs = Dafny.Sequence.Concat(_216_onExprArgs, Dafny.Sequence.FromElements(_220_rIdent)); - } - _215_body = (_215_body).Apply(_216_onExprArgs); - r = RAST.Expr.create_Lambda(_210_parameters, Std.Wrappers.Option.create_None(), _215_body); + (this).GenIdent(_217_name, selfIdent, _207_lEnv, (((!(_202_isConstant)) && ((_218_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out183, out _out184, out _out185); + _219_rIdent = _out183; + _220___v106 = _out184; + _221___v107 = _out185; + _215_onExprArgs = Dafny.Sequence.Concat(_215_onExprArgs, Dafny.Sequence.FromElements(_219_rIdent)); + } + _214_body = (_214_body).Apply(_215_onExprArgs); + r = RAST.Expr.create_Lambda(_209_parameters, Std.Wrappers.Option.create_None(), _214_body); if (_201_isStatic) { } else { - RAST._IExpr _223_target; + RAST._IExpr _222_target; if (object.Equals(_205_onOwned, Defs.Ownership.create_OwnershipOwned())) { - _223_target = _204_onExpr; + _222_target = _204_onExpr; } else { - _223_target = (_204_onExpr).Clone(); + _222_target = (_204_onExpr).Clone(); } - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("callTarget"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_223_target))).Then(r)); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("callTarget"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_222_target))).Then(r)); } - Dafny.ISequence _224_typeShapeArgs; - _224_typeShapeArgs = Dafny.Sequence.FromElements(); + Dafny.ISequence _223_typeShapeArgs; + _223_typeShapeArgs = Dafny.Sequence.FromElements(); BigInteger _hi11 = new BigInteger((_203_arguments).Count); - for (BigInteger _225_i = BigInteger.Zero; _225_i < _hi11; _225_i++) { - _224_typeShapeArgs = Dafny.Sequence.Concat(_224_typeShapeArgs, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))); + for (BigInteger _224_i = BigInteger.Zero; _224_i < _hi11; _224_i++) { + _223_typeShapeArgs = Dafny.Sequence.Concat(_223_typeShapeArgs, Dafny.Sequence.FromElements(RAST.Type.create_Borrowed(RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_"))))); } - RAST._IType _226_typeShape; - _226_typeShape = RAST.Type.create_DynType(RAST.Type.create_FnType(_224_typeShapeArgs, RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_")))); - r = RAST.Expr.create_TypeAscription((RAST.__default.std__rc__Rc__new).Apply1(r), ((RAST.__default.std__rc__Rc).AsType()).Apply(Dafny.Sequence.FromElements(_226_typeShape))); + RAST._IType _225_typeShape; + _225_typeShape = RAST.Type.create_DynType(RAST.Type.create_FnType(_223_typeShapeArgs, RAST.Type.create_TIdentifier(Dafny.Sequence.UnicodeFromString("_")))); + if (((this).syncType).is_Sync) { + _225_typeShape = RAST.Type.create_IntersectionType(_225_typeShape, (this).SyncSendType); + } + r = RAST.Expr.create_TypeAscription(Dafny.Helpers.Id>((this).rcNew)(r), Dafny.Helpers.Id>((this).rc)(_225_typeShape)); RAST._IExpr _out186; Defs._IOwnership _out187; (this).FromOwned(r, expectedOwnership, out _out186, out _out187); @@ -5969,46 +5981,46 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Select) { - DAST._IExpression _227_on = _source0.dtor_expr; - Dafny.ISequence _228_field = _source0.dtor_field; - DAST._IFieldMutability _229_fieldMutability = _source0.dtor_fieldMutability; - DAST._ISelectContext _230_selectContext = _source0.dtor_selectContext; - DAST._IType _231_fieldType = _source0.dtor_isfieldType; + DAST._IExpression _226_on = _source0.dtor_expr; + Dafny.ISequence _227_field = _source0.dtor_field; + DAST._IFieldMutability _228_fieldMutability = _source0.dtor_fieldMutability; + DAST._ISelectContext _229_selectContext = _source0.dtor_selectContext; + DAST._IType _230_fieldType = _source0.dtor_isfieldType; { - if (((_227_on).is_Companion) || ((_227_on).is_ExternCompanion)) { - RAST._IExpr _232_onExpr; - Defs._IOwnership _233_onOwned; - Dafny.ISet> _234_recIdents; + if (((_226_on).is_Companion) || ((_226_on).is_ExternCompanion)) { + RAST._IExpr _231_onExpr; + Defs._IOwnership _232_onOwned; + Dafny.ISet> _233_recIdents; RAST._IExpr _out188; Defs._IOwnership _out189; Dafny.ISet> _out190; - (this).GenExpr(_227_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out188, out _out189, out _out190); - _232_onExpr = _out188; - _233_onOwned = _out189; - _234_recIdents = _out190; - r = ((_232_onExpr).FSel(Defs.__default.escapeVar(_228_field))).Apply0(); + (this).GenExpr(_226_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out188, out _out189, out _out190); + _231_onExpr = _out188; + _232_onOwned = _out189; + _233_recIdents = _out190; + r = ((_231_onExpr).FSel(Defs.__default.escapeVar(_227_field))).Apply0(); RAST._IExpr _out191; Defs._IOwnership _out192; (this).FromOwned(r, expectedOwnership, out _out191, out _out192); r = _out191; resultingOwnership = _out192; - readIdents = _234_recIdents; + readIdents = _233_recIdents; return ; - } else if ((_230_selectContext).is_SelectContextDatatype) { - RAST._IExpr _235_onExpr; - Defs._IOwnership _236_onOwned; - Dafny.ISet> _237_recIdents; + } else if ((_229_selectContext).is_SelectContextDatatype) { + RAST._IExpr _234_onExpr; + Defs._IOwnership _235_onOwned; + Dafny.ISet> _236_recIdents; RAST._IExpr _out193; Defs._IOwnership _out194; Dafny.ISet> _out195; - (this).GenExpr(_227_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out193, out _out194, out _out195); - _235_onExpr = _out193; - _236_onOwned = _out194; - _237_recIdents = _out195; - r = ((_235_onExpr).Sel(Defs.__default.escapeVar(_228_field))).Apply0(); - Defs._IOwnership _238_originalMutability; - _238_originalMutability = Defs.Ownership.create_OwnershipOwned(); - DAST._IFieldMutability _source2 = _229_fieldMutability; + (this).GenExpr(_226_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out193, out _out194, out _out195); + _234_onExpr = _out193; + _235_onOwned = _out194; + _236_recIdents = _out195; + r = ((_234_onExpr).Sel(Defs.__default.escapeVar(_227_field))).Apply0(); + Defs._IOwnership _237_originalMutability; + _237_originalMutability = Defs.Ownership.create_OwnershipOwned(); + DAST._IFieldMutability _source2 = _228_fieldMutability; { if (_source2.is_ConstantField) { goto after_match2; @@ -6016,7 +6028,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source2.is_InternalClassConstantFieldOrDatatypeDestructor) { - _238_originalMutability = Defs.Ownership.create_OwnershipBorrowed(); + _237_originalMutability = Defs.Ownership.create_OwnershipBorrowed(); goto after_match2; } } @@ -6026,57 +6038,57 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir r = _out196; } after_match2: ; - RAST._IType _239_typ; + RAST._IType _238_typ; RAST._IType _out197; - _out197 = (this).GenType(_231_fieldType, Defs.GenTypeContext.@default()); - _239_typ = _out197; + _out197 = (this).GenType(_230_fieldType, Defs.GenTypeContext.@default()); + _238_typ = _out197; RAST._IExpr _out198; Defs._IOwnership _out199; - (this).FromOwnership(r, _238_originalMutability, expectedOwnership, out _out198, out _out199); + (this).FromOwnership(r, _237_originalMutability, expectedOwnership, out _out198, out _out199); r = _out198; resultingOwnership = _out199; - readIdents = _237_recIdents; - } else if ((_230_selectContext).is_SelectContextGeneralTrait) { - Defs._IOwnership _240_onOwned = Defs.Ownership.Default(); - Dafny.ISet> _241_recIdents = Dafny.Set>.Empty; + readIdents = _236_recIdents; + } else if ((_229_selectContext).is_SelectContextGeneralTrait) { + Defs._IOwnership _239_onOwned = Defs.Ownership.Default(); + Dafny.ISet> _240_recIdents = Dafny.Set>.Empty; readIdents = Dafny.Set>.FromElements(); - if ((_227_on).IsThisUpcast()) { + if ((_226_on).IsThisUpcast()) { r = RAST.__default.self; - _241_recIdents = Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self")); + _240_recIdents = Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("self")); } else { RAST._IExpr _out200; Defs._IOwnership _out201; Dafny.ISet> _out202; - (this).GenExpr(_227_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out200, out _out201, out _out202); + (this).GenExpr(_226_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out200, out _out201, out _out202); r = _out200; - _240_onOwned = _out201; - _241_recIdents = _out202; + _239_onOwned = _out201; + _240_recIdents = _out202; if (!object.Equals(r, RAST.__default.self)) { r = (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(r); } } - readIdents = Dafny.Set>.Union(readIdents, _241_recIdents); - r = ((r).Sel(Defs.__default.escapeVar(_228_field))).Apply0(); + readIdents = Dafny.Set>.Union(readIdents, _240_recIdents); + r = ((r).Sel(Defs.__default.escapeVar(_227_field))).Apply0(); RAST._IExpr _out203; Defs._IOwnership _out204; (this).FromOwned(r, expectedOwnership, out _out203, out _out204); r = _out203; resultingOwnership = _out204; - readIdents = _241_recIdents; + readIdents = _240_recIdents; } else { - RAST._IExpr _242_onExpr; - Defs._IOwnership _243_onOwned; - Dafny.ISet> _244_recIdents; + RAST._IExpr _241_onExpr; + Defs._IOwnership _242_onOwned; + Dafny.ISet> _243_recIdents; RAST._IExpr _out205; Defs._IOwnership _out206; Dafny.ISet> _out207; - (this).GenExpr(_227_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out205, out _out206, out _out207); - _242_onExpr = _out205; - _243_onOwned = _out206; - _244_recIdents = _out207; - r = _242_onExpr; - if (!object.Equals(_242_onExpr, RAST.__default.self)) { - RAST._IExpr _source3 = _242_onExpr; + (this).GenExpr(_226_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out205, out _out206, out _out207); + _241_onExpr = _out205; + _242_onOwned = _out206; + _243_recIdents = _out207; + r = _241_onExpr; + if (!object.Equals(_241_onExpr, RAST.__default.self)) { + RAST._IExpr _source3 = _241_onExpr; { if (_source3.is_UnaryOp) { Dafny.ISequence op10 = _source3.dtor_op1; @@ -6100,8 +6112,8 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } r = ((this).read__macro).Apply1(r); } - r = (r).Sel(Defs.__default.escapeVar(_228_field)); - DAST._IFieldMutability _source4 = _229_fieldMutability; + r = (r).Sel(Defs.__default.escapeVar(_227_field)); + DAST._IFieldMutability _source4 = _228_fieldMutability; { if (_source4.is_ConstantField) { r = (r).Apply0(); @@ -6124,7 +6136,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir (this).FromOwned(r, expectedOwnership, out _out208, out _out209); r = _out208; resultingOwnership = _out209; - readIdents = _244_recIdents; + readIdents = _243_recIdents; } return ; } @@ -6133,63 +6145,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Index) { - DAST._IExpression _245_on = _source0.dtor_expr; - DAST._ICollKind _246_collKind = _source0.dtor_collKind; - Dafny.ISequence _247_indices = _source0.dtor_indices; + DAST._IExpression _244_on = _source0.dtor_expr; + DAST._ICollKind _245_collKind = _source0.dtor_collKind; + Dafny.ISequence _246_indices = _source0.dtor_indices; { - RAST._IExpr _248_onExpr; - Defs._IOwnership _249_onOwned; - Dafny.ISet> _250_recIdents; + RAST._IExpr _247_onExpr; + Defs._IOwnership _248_onOwned; + Dafny.ISet> _249_recIdents; RAST._IExpr _out210; Defs._IOwnership _out211; Dafny.ISet> _out212; - (this).GenExpr(_245_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out210, out _out211, out _out212); - _248_onExpr = _out210; - _249_onOwned = _out211; - _250_recIdents = _out212; - readIdents = _250_recIdents; - r = _248_onExpr; - bool _251_hadArray; - _251_hadArray = false; - if (object.Equals(_246_collKind, DAST.CollKind.create_Array())) { + (this).GenExpr(_244_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out210, out _out211, out _out212); + _247_onExpr = _out210; + _248_onOwned = _out211; + _249_recIdents = _out212; + readIdents = _249_recIdents; + r = _247_onExpr; + bool _250_hadArray; + _250_hadArray = false; + if (object.Equals(_245_collKind, DAST.CollKind.create_Array())) { r = ((this).read__macro).Apply1(r); - _251_hadArray = true; - if ((new BigInteger((_247_indices).Count)) > (BigInteger.One)) { + _250_hadArray = true; + if ((new BigInteger((_246_indices).Count)) > (BigInteger.One)) { r = (r).Sel(Dafny.Sequence.UnicodeFromString("data")); } } - BigInteger _hi12 = new BigInteger((_247_indices).Count); - for (BigInteger _252_i = BigInteger.Zero; _252_i < _hi12; _252_i++) { - if (object.Equals(_246_collKind, DAST.CollKind.create_Array())) { - RAST._IExpr _253_idx; - Defs._IOwnership _254_idxOwned; - Dafny.ISet> _255_recIdentsIdx; + BigInteger _hi12 = new BigInteger((_246_indices).Count); + for (BigInteger _251_i = BigInteger.Zero; _251_i < _hi12; _251_i++) { + if (object.Equals(_245_collKind, DAST.CollKind.create_Array())) { + RAST._IExpr _252_idx; + Defs._IOwnership _253_idxOwned; + Dafny.ISet> _254_recIdentsIdx; RAST._IExpr _out213; Defs._IOwnership _out214; Dafny.ISet> _out215; - (this).GenExpr((_247_indices).Select(_252_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out213, out _out214, out _out215); - _253_idx = _out213; - _254_idxOwned = _out214; - _255_recIdentsIdx = _out215; - _253_idx = RAST.__default.IntoUsize(_253_idx); - r = RAST.Expr.create_SelectIndex(r, _253_idx); - readIdents = Dafny.Set>.Union(readIdents, _255_recIdentsIdx); + (this).GenExpr((_246_indices).Select(_251_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out213, out _out214, out _out215); + _252_idx = _out213; + _253_idxOwned = _out214; + _254_recIdentsIdx = _out215; + _252_idx = RAST.__default.IntoUsize(_252_idx); + r = RAST.Expr.create_SelectIndex(r, _252_idx); + readIdents = Dafny.Set>.Union(readIdents, _254_recIdentsIdx); } else { - RAST._IExpr _256_idx; - Defs._IOwnership _257_idxOwned; - Dafny.ISet> _258_recIdentsIdx; + RAST._IExpr _255_idx; + Defs._IOwnership _256_idxOwned; + Dafny.ISet> _257_recIdentsIdx; RAST._IExpr _out216; Defs._IOwnership _out217; Dafny.ISet> _out218; - (this).GenExpr((_247_indices).Select(_252_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out216, out _out217, out _out218); - _256_idx = _out216; - _257_idxOwned = _out217; - _258_recIdentsIdx = _out218; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_256_idx); - readIdents = Dafny.Set>.Union(readIdents, _258_recIdentsIdx); + (this).GenExpr((_246_indices).Select(_251_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out216, out _out217, out _out218); + _255_idx = _out216; + _256_idxOwned = _out217; + _257_recIdentsIdx = _out218; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("get"))).Apply1(_255_idx); + readIdents = Dafny.Set>.Union(readIdents, _257_recIdentsIdx); } } - if (_251_hadArray) { + if (_250_hadArray) { r = (r).Clone(); } RAST._IExpr _out219; @@ -6204,63 +6216,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IndexRange) { - DAST._IExpression _259_on = _source0.dtor_expr; - bool _260_isArray = _source0.dtor_isArray; - Std.Wrappers._IOption _261_low = _source0.dtor_low; - Std.Wrappers._IOption _262_high = _source0.dtor_high; + DAST._IExpression _258_on = _source0.dtor_expr; + bool _259_isArray = _source0.dtor_isArray; + Std.Wrappers._IOption _260_low = _source0.dtor_low; + Std.Wrappers._IOption _261_high = _source0.dtor_high; { - Defs._IOwnership _263_onExpectedOwnership; - if (_260_isArray) { + Defs._IOwnership _262_onExpectedOwnership; + if (_259_isArray) { if (((this).pointerType).is_Raw) { - _263_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); + _262_onExpectedOwnership = Defs.Ownership.create_OwnershipOwned(); } else { - _263_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); + _262_onExpectedOwnership = Defs.Ownership.create_OwnershipBorrowed(); } } else { - _263_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); + _262_onExpectedOwnership = Defs.Ownership.create_OwnershipAutoBorrowed(); } - RAST._IExpr _264_onExpr; - Defs._IOwnership _265_onOwned; - Dafny.ISet> _266_recIdents; + RAST._IExpr _263_onExpr; + Defs._IOwnership _264_onOwned; + Dafny.ISet> _265_recIdents; RAST._IExpr _out221; Defs._IOwnership _out222; Dafny.ISet> _out223; - (this).GenExpr(_259_on, selfIdent, env, _263_onExpectedOwnership, out _out221, out _out222, out _out223); - _264_onExpr = _out221; - _265_onOwned = _out222; - _266_recIdents = _out223; - readIdents = _266_recIdents; - Dafny.ISequence _267_methodName; - if ((_261_low).is_Some) { - if ((_262_high).is_Some) { - _267_methodName = Dafny.Sequence.UnicodeFromString("slice"); + (this).GenExpr(_258_on, selfIdent, env, _262_onExpectedOwnership, out _out221, out _out222, out _out223); + _263_onExpr = _out221; + _264_onOwned = _out222; + _265_recIdents = _out223; + readIdents = _265_recIdents; + Dafny.ISequence _266_methodName; + if ((_260_low).is_Some) { + if ((_261_high).is_Some) { + _266_methodName = Dafny.Sequence.UnicodeFromString("slice"); } else { - _267_methodName = Dafny.Sequence.UnicodeFromString("drop"); + _266_methodName = Dafny.Sequence.UnicodeFromString("drop"); } - } else if ((_262_high).is_Some) { - _267_methodName = Dafny.Sequence.UnicodeFromString("take"); + } else if ((_261_high).is_Some) { + _266_methodName = Dafny.Sequence.UnicodeFromString("take"); } else { - _267_methodName = Dafny.Sequence.UnicodeFromString(""); + _266_methodName = Dafny.Sequence.UnicodeFromString(""); } - Dafny.ISequence _268_arguments; - _268_arguments = Dafny.Sequence.FromElements(); - Std.Wrappers._IOption _source5 = _261_low; + Dafny.ISequence _267_arguments; + _267_arguments = Dafny.Sequence.FromElements(); + Std.Wrappers._IOption _source5 = _260_low; { if (_source5.is_Some) { - DAST._IExpression _269_l = _source5.dtor_value; + DAST._IExpression _268_l = _source5.dtor_value; { - RAST._IExpr _270_lExpr; - Defs._IOwnership _271___v110; - Dafny.ISet> _272_recIdentsL; + RAST._IExpr _269_lExpr; + Defs._IOwnership _270___v110; + Dafny.ISet> _271_recIdentsL; RAST._IExpr _out224; Defs._IOwnership _out225; Dafny.ISet> _out226; - (this).GenExpr(_269_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out224, out _out225, out _out226); - _270_lExpr = _out224; - _271___v110 = _out225; - _272_recIdentsL = _out226; - _268_arguments = Dafny.Sequence.Concat(_268_arguments, Dafny.Sequence.FromElements(_270_lExpr)); - readIdents = Dafny.Set>.Union(readIdents, _272_recIdentsL); + (this).GenExpr(_268_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out224, out _out225, out _out226); + _269_lExpr = _out224; + _270___v110 = _out225; + _271_recIdentsL = _out226; + _267_arguments = Dafny.Sequence.Concat(_267_arguments, Dafny.Sequence.FromElements(_269_lExpr)); + readIdents = Dafny.Set>.Union(readIdents, _271_recIdentsL); } goto after_match5; } @@ -6268,23 +6280,23 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match5: ; - Std.Wrappers._IOption _source6 = _262_high; + Std.Wrappers._IOption _source6 = _261_high; { if (_source6.is_Some) { - DAST._IExpression _273_h = _source6.dtor_value; + DAST._IExpression _272_h = _source6.dtor_value; { - RAST._IExpr _274_hExpr; - Defs._IOwnership _275___v111; - Dafny.ISet> _276_recIdentsH; + RAST._IExpr _273_hExpr; + Defs._IOwnership _274___v111; + Dafny.ISet> _275_recIdentsH; RAST._IExpr _out227; Defs._IOwnership _out228; Dafny.ISet> _out229; - (this).GenExpr(_273_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out227, out _out228, out _out229); - _274_hExpr = _out227; - _275___v111 = _out228; - _276_recIdentsH = _out229; - _268_arguments = Dafny.Sequence.Concat(_268_arguments, Dafny.Sequence.FromElements(_274_hExpr)); - readIdents = Dafny.Set>.Union(readIdents, _276_recIdentsH); + (this).GenExpr(_272_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out227, out _out228, out _out229); + _273_hExpr = _out227; + _274___v111 = _out228; + _275_recIdentsH = _out229; + _267_arguments = Dafny.Sequence.Concat(_267_arguments, Dafny.Sequence.FromElements(_273_hExpr)); + readIdents = Dafny.Set>.Union(readIdents, _275_recIdentsH); } goto after_match6; } @@ -6292,21 +6304,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match6: ; - r = _264_onExpr; - if (_260_isArray) { - if (!(_267_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - _267_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _267_methodName); + r = _263_onExpr; + if (_259_isArray) { + if (!(_266_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + _266_methodName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _266_methodName); } - Dafny.ISequence _277_object__suffix; + Dafny.ISequence _276_object__suffix; if (((this).pointerType).is_Raw) { - _277_object__suffix = Dafny.Sequence.UnicodeFromString(""); + _276_object__suffix = Dafny.Sequence.UnicodeFromString(""); } else { - _277_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); + _276_object__suffix = Dafny.Sequence.UnicodeFromString("_object"); } - r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _267_methodName), _277_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_264_onExpr), _268_arguments)); + r = ((RAST.__default.dafny__runtime__Sequence).FSel(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("from_array"), _266_methodName), _276_object__suffix))).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_263_onExpr), _267_arguments)); } else { - if (!(_267_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { - r = ((r).Sel(_267_methodName)).Apply(_268_arguments); + if (!(_266_methodName).Equals(Dafny.Sequence.UnicodeFromString(""))) { + r = ((r).Sel(_266_methodName)).Apply(_267_arguments); } else { r = (r).Clone(); } @@ -6323,28 +6335,28 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TupleSelect) { - DAST._IExpression _278_on = _source0.dtor_expr; - BigInteger _279_idx = _source0.dtor_index; - DAST._IType _280_fieldType = _source0.dtor_fieldType; + DAST._IExpression _277_on = _source0.dtor_expr; + BigInteger _278_idx = _source0.dtor_index; + DAST._IType _279_fieldType = _source0.dtor_fieldType; { - RAST._IExpr _281_onExpr; - Defs._IOwnership _282_onOwnership; - Dafny.ISet> _283_recIdents; + RAST._IExpr _280_onExpr; + Defs._IOwnership _281_onOwnership; + Dafny.ISet> _282_recIdents; RAST._IExpr _out232; Defs._IOwnership _out233; Dafny.ISet> _out234; - (this).GenExpr(_278_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out232, out _out233, out _out234); - _281_onExpr = _out232; - _282_onOwnership = _out233; - _283_recIdents = _out234; - Dafny.ISequence _284_selName; - _284_selName = Std.Strings.__default.OfNat(_279_idx); - DAST._IType _source7 = _280_fieldType; + (this).GenExpr(_277_on, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out232, out _out233, out _out234); + _280_onExpr = _out232; + _281_onOwnership = _out233; + _282_recIdents = _out234; + Dafny.ISequence _283_selName; + _283_selName = Std.Strings.__default.OfNat(_278_idx); + DAST._IType _source7 = _279_fieldType; { if (_source7.is_Tuple) { - Dafny.ISequence _285_tps = _source7.dtor_Tuple_a0; - if (((_280_fieldType).is_Tuple) && ((new BigInteger((_285_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { - _284_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _284_selName); + Dafny.ISequence _284_tps = _source7.dtor_Tuple_a0; + if (((_279_fieldType).is_Tuple) && ((new BigInteger((_284_tps).Count)) > (RAST.__default.MAX__TUPLE__SIZE))) { + _283_selName = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_"), _283_selName); } goto after_match7; } @@ -6352,13 +6364,13 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { } after_match7: ; - r = ((_281_onExpr).Sel(_284_selName)).Clone(); + r = ((_280_onExpr).Sel(_283_selName)).Clone(); RAST._IExpr _out235; Defs._IOwnership _out236; (this).FromOwnership(r, Defs.Ownership.create_OwnershipOwned(), expectedOwnership, out _out235, out _out236); r = _out235; resultingOwnership = _out236; - readIdents = _283_recIdents; + readIdents = _282_recIdents; return ; } goto after_match0; @@ -6366,14 +6378,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Call) { - DAST._IExpression _286_on = _source0.dtor_on; - DAST._ICallName _287_name = _source0.dtor_callName; - Dafny.ISequence _288_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _289_args = _source0.dtor_args; + DAST._IExpression _285_on = _source0.dtor_on; + DAST._ICallName _286_name = _source0.dtor_callName; + Dafny.ISequence _287_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _288_args = _source0.dtor_args; { RAST._IExpr _out237; Dafny.ISet> _out238; - (this).GenOwnedCallPart(_286_on, selfIdent, _287_name, _288_typeArgs, _289_args, env, out _out237, out _out238); + (this).GenOwnedCallPart(_285_on, selfIdent, _286_name, _287_typeArgs, _288_args, env, out _out237, out _out238); r = _out237; readIdents = _out238; RAST._IExpr _out239; @@ -6388,85 +6400,85 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Lambda) { - Dafny.ISequence _290_paramsDafny = _source0.dtor_params; - DAST._IType _291_retType = _source0.dtor_retType; - Dafny.ISequence _292_body = _source0.dtor_body; + Dafny.ISequence _289_paramsDafny = _source0.dtor_params; + DAST._IType _290_retType = _source0.dtor_retType; + Dafny.ISequence _291_body = _source0.dtor_body; { - Dafny.ISequence _293_params; + Dafny.ISequence _292_params; Dafny.ISequence _out241; - _out241 = (this).GenParams(_290_paramsDafny, _290_paramsDafny, true); - _293_params = _out241; - Dafny.ISequence> _294_paramNames; - _294_paramNames = Dafny.Sequence>.FromElements(); - Dafny.IMap,RAST._IType> _295_paramTypesMap; - _295_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); - BigInteger _hi13 = new BigInteger((_293_params).Count); - for (BigInteger _296_i = BigInteger.Zero; _296_i < _hi13; _296_i++) { - Dafny.ISequence _297_name; - _297_name = ((_293_params).Select(_296_i)).dtor_name; - _294_paramNames = Dafny.Sequence>.Concat(_294_paramNames, Dafny.Sequence>.FromElements(_297_name)); - _295_paramTypesMap = Dafny.Map, RAST._IType>.Update(_295_paramTypesMap, _297_name, ((_293_params).Select(_296_i)).dtor_tpe); - } - Defs._IEnvironment _298_subEnv; - _298_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_294_paramNames, _295_paramTypesMap, Dafny.Set>.FromElements())); - RAST._IExpr _299_recursiveGen; - Dafny.ISet> _300_recIdents; - Defs._IEnvironment _301___v113; + _out241 = (this).GenParams(_289_paramsDafny, _289_paramsDafny, true); + _292_params = _out241; + Dafny.ISequence> _293_paramNames; + _293_paramNames = Dafny.Sequence>.FromElements(); + Dafny.IMap,RAST._IType> _294_paramTypesMap; + _294_paramTypesMap = Dafny.Map, RAST._IType>.FromElements(); + BigInteger _hi13 = new BigInteger((_292_params).Count); + for (BigInteger _295_i = BigInteger.Zero; _295_i < _hi13; _295_i++) { + Dafny.ISequence _296_name; + _296_name = ((_292_params).Select(_295_i)).dtor_name; + _293_paramNames = Dafny.Sequence>.Concat(_293_paramNames, Dafny.Sequence>.FromElements(_296_name)); + _294_paramTypesMap = Dafny.Map, RAST._IType>.Update(_294_paramTypesMap, _296_name, ((_292_params).Select(_295_i)).dtor_tpe); + } + Defs._IEnvironment _297_subEnv; + _297_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_293_paramNames, _294_paramTypesMap, Dafny.Set>.FromElements())); + RAST._IExpr _298_recursiveGen; + Dafny.ISet> _299_recIdents; + Defs._IEnvironment _300___v113; RAST._IExpr _out242; Dafny.ISet> _out243; Defs._IEnvironment _out244; - (this).GenStmts(_292_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _298_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out242, out _out243, out _out244); - _299_recursiveGen = _out242; - _300_recIdents = _out243; - _301___v113 = _out244; + (this).GenStmts(_291_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _297_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out242, out _out243, out _out244); + _298_recursiveGen = _out242; + _299_recIdents = _out243; + _300___v113 = _out244; readIdents = Dafny.Set>.FromElements(); - _300_recIdents = Dafny.Set>.Difference(_300_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_302_paramNames) => ((System.Func>>)(() => { + _299_recIdents = Dafny.Set>.Difference(_299_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_301_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); - foreach (Dafny.ISequence _compr_0 in (_302_paramNames).CloneAsArray()) { - Dafny.ISequence _303_name = (Dafny.ISequence)_compr_0; - if ((_302_paramNames).Contains(_303_name)) { - _coll0.Add(_303_name); + foreach (Dafny.ISequence _compr_0 in (_301_paramNames).CloneAsArray()) { + Dafny.ISequence _302_name = (Dafny.ISequence)_compr_0; + if ((_301_paramNames).Contains(_302_name)) { + _coll0.Add(_302_name); } } return Dafny.Set>.FromCollection(_coll0); - }))())(_294_paramNames)); - RAST._IExpr _304_allReadCloned; - _304_allReadCloned = (this).InitEmptyExpr(); - while (!(_300_recIdents).Equals(Dafny.Set>.FromElements())) { - Dafny.ISequence _305_next; - foreach (Dafny.ISequence _assign_such_that_1 in (_300_recIdents).Elements) { - _305_next = (Dafny.ISequence)_assign_such_that_1; - if ((_300_recIdents).Contains(_305_next)) { + }))())(_293_paramNames)); + RAST._IExpr _303_allReadCloned; + _303_allReadCloned = (this).InitEmptyExpr(); + while (!(_299_recIdents).Equals(Dafny.Set>.FromElements())) { + Dafny.ISequence _304_next; + foreach (Dafny.ISequence _assign_such_that_1 in (_299_recIdents).Elements) { + _304_next = (Dafny.ISequence)_assign_such_that_1; + if ((_299_recIdents).Contains(_304_next)) { goto after__ASSIGN_SUCH_THAT_1; } } throw new System.Exception("assign-such-that search produced no value"); after__ASSIGN_SUCH_THAT_1: ; - if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_305_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { - RAST._IExpr _306_selfCloned; - Defs._IOwnership _307___v114; - Dafny.ISet> _308___v115; + if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_304_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { + RAST._IExpr _305_selfCloned; + Defs._IOwnership _306___v114; + Dafny.ISet> _307___v115; RAST._IExpr _out245; Defs._IOwnership _out246; Dafny.ISet> _out247; (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out245, out _out246, out _out247); - _306_selfCloned = _out245; - _307___v114 = _out246; - _308___v115 = _out247; - _304_allReadCloned = (_304_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_306_selfCloned))); - } else if (!((_294_paramNames).Contains(_305_next))) { - RAST._IExpr _309_copy; - _309_copy = (RAST.Expr.create_Identifier(_305_next)).Clone(); - _304_allReadCloned = (_304_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _305_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_309_copy))); - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_305_next)); + _305_selfCloned = _out245; + _306___v114 = _out246; + _307___v115 = _out247; + _303_allReadCloned = (_303_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_305_selfCloned))); + } else if (!((_293_paramNames).Contains(_304_next))) { + RAST._IExpr _308_copy; + _308_copy = (RAST.Expr.create_Identifier(_304_next)).Clone(); + _303_allReadCloned = (_303_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _304_next, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_308_copy))); + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_304_next)); } - _300_recIdents = Dafny.Set>.Difference(_300_recIdents, Dafny.Set>.FromElements(_305_next)); + _299_recIdents = Dafny.Set>.Difference(_299_recIdents, Dafny.Set>.FromElements(_304_next)); } - RAST._IType _310_retTypeGen; + RAST._IType _309_retTypeGen; RAST._IType _out248; - _out248 = (this).GenType(_291_retType, Defs.GenTypeContext.@default()); - _310_retTypeGen = _out248; - r = RAST.Expr.create_Block((_304_allReadCloned).Then(RAST.__default.RcNew(RAST.Expr.create_Lambda(_293_params, Std.Wrappers.Option.create_Some(_310_retTypeGen), RAST.Expr.create_Block(_299_recursiveGen))))); + _out248 = (this).GenType(_290_retType, Defs.GenTypeContext.@default()); + _309_retTypeGen = _out248; + r = RAST.Expr.create_Block((_303_allReadCloned).Then(Dafny.Helpers.Id>((this).rcNew)(RAST.Expr.create_Lambda(_292_params, Std.Wrappers.Option.create_Some(_309_retTypeGen), RAST.Expr.create_Block(_298_recursiveGen))))); RAST._IExpr _out249; Defs._IOwnership _out250; (this).FromOwned(r, expectedOwnership, out _out249, out _out250); @@ -6479,72 +6491,72 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_BetaRedex) { - Dafny.ISequence<_System._ITuple2> _311_values = _source0.dtor_values; - DAST._IType _312_retType = _source0.dtor_retType; - DAST._IExpression _313_expr = _source0.dtor_expr; + Dafny.ISequence<_System._ITuple2> _310_values = _source0.dtor_values; + DAST._IType _311_retType = _source0.dtor_retType; + DAST._IExpression _312_expr = _source0.dtor_expr; { - Dafny.ISequence> _314_paramNames; - _314_paramNames = Dafny.Sequence>.FromElements(); - Dafny.ISequence _315_paramFormals; + Dafny.ISequence> _313_paramNames; + _313_paramNames = Dafny.Sequence>.FromElements(); + Dafny.ISequence _314_paramFormals; Dafny.ISequence _out251; - _out251 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_316_value) => { - return (_316_value).dtor__0; - })), _311_values), Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_316_value) => { - return (_316_value).dtor__0; - })), _311_values), false); - _315_paramFormals = _out251; - Dafny.IMap,RAST._IType> _317_paramTypes; - _317_paramTypes = Dafny.Map, RAST._IType>.FromElements(); - Dafny.ISet> _318_paramNamesSet; - _318_paramNamesSet = Dafny.Set>.FromElements(); - BigInteger _hi14 = new BigInteger((_311_values).Count); - for (BigInteger _319_i = BigInteger.Zero; _319_i < _hi14; _319_i++) { - Dafny.ISequence _320_name; - _320_name = (((_311_values).Select(_319_i)).dtor__0).dtor_name; - Dafny.ISequence _321_rName; - _321_rName = Defs.__default.escapeVar(_320_name); - _314_paramNames = Dafny.Sequence>.Concat(_314_paramNames, Dafny.Sequence>.FromElements(_321_rName)); - _317_paramTypes = Dafny.Map, RAST._IType>.Update(_317_paramTypes, _321_rName, ((_315_paramFormals).Select(_319_i)).dtor_tpe); - _318_paramNamesSet = Dafny.Set>.Union(_318_paramNamesSet, Dafny.Set>.FromElements(_321_rName)); + _out251 = (this).GenParams(Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_315_value) => { + return (_315_value).dtor__0; + })), _310_values), Std.Collections.Seq.__default.Map<_System._ITuple2, DAST._IFormal>(((System.Func<_System._ITuple2, DAST._IFormal>)((_315_value) => { + return (_315_value).dtor__0; + })), _310_values), false); + _314_paramFormals = _out251; + Dafny.IMap,RAST._IType> _316_paramTypes; + _316_paramTypes = Dafny.Map, RAST._IType>.FromElements(); + Dafny.ISet> _317_paramNamesSet; + _317_paramNamesSet = Dafny.Set>.FromElements(); + BigInteger _hi14 = new BigInteger((_310_values).Count); + for (BigInteger _318_i = BigInteger.Zero; _318_i < _hi14; _318_i++) { + Dafny.ISequence _319_name; + _319_name = (((_310_values).Select(_318_i)).dtor__0).dtor_name; + Dafny.ISequence _320_rName; + _320_rName = Defs.__default.escapeVar(_319_name); + _313_paramNames = Dafny.Sequence>.Concat(_313_paramNames, Dafny.Sequence>.FromElements(_320_rName)); + _316_paramTypes = Dafny.Map, RAST._IType>.Update(_316_paramTypes, _320_rName, ((_314_paramFormals).Select(_318_i)).dtor_tpe); + _317_paramNamesSet = Dafny.Set>.Union(_317_paramNamesSet, Dafny.Set>.FromElements(_320_rName)); } readIdents = Dafny.Set>.FromElements(); r = (this).InitEmptyExpr(); - BigInteger _hi15 = new BigInteger((_311_values).Count); - for (BigInteger _322_i = BigInteger.Zero; _322_i < _hi15; _322_i++) { - RAST._IType _323_typeGen; + BigInteger _hi15 = new BigInteger((_310_values).Count); + for (BigInteger _321_i = BigInteger.Zero; _321_i < _hi15; _321_i++) { + RAST._IType _322_typeGen; RAST._IType _out252; - _out252 = (this).GenType((((_311_values).Select(_322_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); - _323_typeGen = _out252; - RAST._IExpr _324_valueGen; - Defs._IOwnership _325___v116; - Dafny.ISet> _326_recIdents; + _out252 = (this).GenType((((_310_values).Select(_321_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); + _322_typeGen = _out252; + RAST._IExpr _323_valueGen; + Defs._IOwnership _324___v116; + Dafny.ISet> _325_recIdents; RAST._IExpr _out253; Defs._IOwnership _out254; Dafny.ISet> _out255; - (this).GenExpr(((_311_values).Select(_322_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out253, out _out254, out _out255); - _324_valueGen = _out253; - _325___v116 = _out254; - _326_recIdents = _out255; - r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_311_values).Select(_322_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_323_typeGen), Std.Wrappers.Option.create_Some(_324_valueGen))); - readIdents = Dafny.Set>.Union(readIdents, _326_recIdents); - } - Defs._IEnvironment _327_newEnv; - _327_newEnv = Defs.Environment.create(_314_paramNames, _317_paramTypes, Dafny.Set>.FromElements()); - RAST._IExpr _328_recGen; - Defs._IOwnership _329_recOwned; - Dafny.ISet> _330_recIdents; + (this).GenExpr(((_310_values).Select(_321_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out253, out _out254, out _out255); + _323_valueGen = _out253; + _324___v116 = _out254; + _325_recIdents = _out255; + r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_310_values).Select(_321_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_322_typeGen), Std.Wrappers.Option.create_Some(_323_valueGen))); + readIdents = Dafny.Set>.Union(readIdents, _325_recIdents); + } + Defs._IEnvironment _326_newEnv; + _326_newEnv = Defs.Environment.create(_313_paramNames, _316_paramTypes, Dafny.Set>.FromElements()); + RAST._IExpr _327_recGen; + Defs._IOwnership _328_recOwned; + Dafny.ISet> _329_recIdents; RAST._IExpr _out256; Defs._IOwnership _out257; Dafny.ISet> _out258; - (this).GenExpr(_313_expr, selfIdent, _327_newEnv, expectedOwnership, out _out256, out _out257, out _out258); - _328_recGen = _out256; - _329_recOwned = _out257; - _330_recIdents = _out258; - readIdents = Dafny.Set>.Difference(_330_recIdents, _318_paramNamesSet); - r = RAST.Expr.create_Block((r).Then(_328_recGen)); + (this).GenExpr(_312_expr, selfIdent, _326_newEnv, expectedOwnership, out _out256, out _out257, out _out258); + _327_recGen = _out256; + _328_recOwned = _out257; + _329_recIdents = _out258; + readIdents = Dafny.Set>.Difference(_329_recIdents, _317_paramNamesSet); + r = RAST.Expr.create_Block((r).Then(_327_recGen)); RAST._IExpr _out259; Defs._IOwnership _out260; - (this).FromOwnership(r, _329_recOwned, expectedOwnership, out _out259, out _out260); + (this).FromOwnership(r, _328_recOwned, expectedOwnership, out _out259, out _out260); r = _out259; resultingOwnership = _out260; return ; @@ -6554,40 +6566,40 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IIFE) { - Dafny.ISequence _331_name = _source0.dtor_ident; - DAST._IType _332_tpe = _source0.dtor_typ; - DAST._IExpression _333_value = _source0.dtor_value; - DAST._IExpression _334_iifeBody = _source0.dtor_iifeBody; + Dafny.ISequence _330_name = _source0.dtor_ident; + DAST._IType _331_tpe = _source0.dtor_typ; + DAST._IExpression _332_value = _source0.dtor_value; + DAST._IExpression _333_iifeBody = _source0.dtor_iifeBody; { - RAST._IExpr _335_valueGen; - Defs._IOwnership _336___v117; - Dafny.ISet> _337_recIdents; + RAST._IExpr _334_valueGen; + Defs._IOwnership _335___v117; + Dafny.ISet> _336_recIdents; RAST._IExpr _out261; Defs._IOwnership _out262; Dafny.ISet> _out263; - (this).GenExpr(_333_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out261, out _out262, out _out263); - _335_valueGen = _out261; - _336___v117 = _out262; - _337_recIdents = _out263; - readIdents = _337_recIdents; - RAST._IType _338_valueTypeGen; + (this).GenExpr(_332_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out261, out _out262, out _out263); + _334_valueGen = _out261; + _335___v117 = _out262; + _336_recIdents = _out263; + readIdents = _336_recIdents; + RAST._IType _337_valueTypeGen; RAST._IType _out264; - _out264 = (this).GenType(_332_tpe, Defs.GenTypeContext.@default()); - _338_valueTypeGen = _out264; - Dafny.ISequence _339_iifeVar; - _339_iifeVar = Defs.__default.escapeVar(_331_name); - RAST._IExpr _340_bodyGen; - Defs._IOwnership _341___v118; - Dafny.ISet> _342_bodyIdents; + _out264 = (this).GenType(_331_tpe, Defs.GenTypeContext.@default()); + _337_valueTypeGen = _out264; + Dafny.ISequence _338_iifeVar; + _338_iifeVar = Defs.__default.escapeVar(_330_name); + RAST._IExpr _339_bodyGen; + Defs._IOwnership _340___v118; + Dafny.ISet> _341_bodyIdents; RAST._IExpr _out265; Defs._IOwnership _out266; Dafny.ISet> _out267; - (this).GenExpr(_334_iifeBody, selfIdent, (env).AddAssigned(_339_iifeVar, _338_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out265, out _out266, out _out267); - _340_bodyGen = _out265; - _341___v118 = _out266; - _342_bodyIdents = _out267; - readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_342_bodyIdents, Dafny.Set>.FromElements(_339_iifeVar))); - r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _339_iifeVar, Std.Wrappers.Option.create_Some(_338_valueTypeGen), Std.Wrappers.Option.create_Some(_335_valueGen))).Then(_340_bodyGen)); + (this).GenExpr(_333_iifeBody, selfIdent, (env).AddAssigned(_338_iifeVar, _337_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out265, out _out266, out _out267); + _339_bodyGen = _out265; + _340___v118 = _out266; + _341_bodyIdents = _out267; + readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_341_bodyIdents, Dafny.Set>.FromElements(_338_iifeVar))); + r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _338_iifeVar, Std.Wrappers.Option.create_Some(_337_valueTypeGen), Std.Wrappers.Option.create_Some(_334_valueGen))).Then(_339_bodyGen)); RAST._IExpr _out268; Defs._IOwnership _out269; (this).FromOwned(r, expectedOwnership, out _out268, out _out269); @@ -6600,38 +6612,38 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Apply) { - DAST._IExpression _343_func = _source0.dtor_expr; - Dafny.ISequence _344_args = _source0.dtor_args; + DAST._IExpression _342_func = _source0.dtor_expr; + Dafny.ISequence _343_args = _source0.dtor_args; { - RAST._IExpr _345_funcExpr; - Defs._IOwnership _346___v119; - Dafny.ISet> _347_recIdents; + RAST._IExpr _344_funcExpr; + Defs._IOwnership _345___v119; + Dafny.ISet> _346_recIdents; RAST._IExpr _out270; Defs._IOwnership _out271; Dafny.ISet> _out272; - (this).GenExpr(_343_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out270, out _out271, out _out272); - _345_funcExpr = _out270; - _346___v119 = _out271; - _347_recIdents = _out272; - readIdents = _347_recIdents; - Dafny.ISequence _348_rArgs; - _348_rArgs = Dafny.Sequence.FromElements(); - BigInteger _hi16 = new BigInteger((_344_args).Count); - for (BigInteger _349_i = BigInteger.Zero; _349_i < _hi16; _349_i++) { - RAST._IExpr _350_argExpr; - Defs._IOwnership _351_argOwned; - Dafny.ISet> _352_argIdents; + (this).GenExpr(_342_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out270, out _out271, out _out272); + _344_funcExpr = _out270; + _345___v119 = _out271; + _346_recIdents = _out272; + readIdents = _346_recIdents; + Dafny.ISequence _347_rArgs; + _347_rArgs = Dafny.Sequence.FromElements(); + BigInteger _hi16 = new BigInteger((_343_args).Count); + for (BigInteger _348_i = BigInteger.Zero; _348_i < _hi16; _348_i++) { + RAST._IExpr _349_argExpr; + Defs._IOwnership _350_argOwned; + Dafny.ISet> _351_argIdents; RAST._IExpr _out273; Defs._IOwnership _out274; Dafny.ISet> _out275; - (this).GenExpr((_344_args).Select(_349_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out273, out _out274, out _out275); - _350_argExpr = _out273; - _351_argOwned = _out274; - _352_argIdents = _out275; - _348_rArgs = Dafny.Sequence.Concat(_348_rArgs, Dafny.Sequence.FromElements(_350_argExpr)); - readIdents = Dafny.Set>.Union(readIdents, _352_argIdents); - } - r = (_345_funcExpr).Apply(_348_rArgs); + (this).GenExpr((_343_args).Select(_348_i), selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out273, out _out274, out _out275); + _349_argExpr = _out273; + _350_argOwned = _out274; + _351_argIdents = _out275; + _347_rArgs = Dafny.Sequence.Concat(_347_rArgs, Dafny.Sequence.FromElements(_349_argExpr)); + readIdents = Dafny.Set>.Union(readIdents, _351_argIdents); + } + r = (_344_funcExpr).Apply(_347_rArgs); RAST._IExpr _out276; Defs._IOwnership _out277; (this).FromOwned(r, expectedOwnership, out _out276, out _out277); @@ -6644,31 +6656,31 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_TypeTest) { - DAST._IExpression _353_on = _source0.dtor_on; - Dafny.ISequence> _354_dType = _source0.dtor_dType; - Dafny.ISequence _355_variant = _source0.dtor_variant; + DAST._IExpression _352_on = _source0.dtor_on; + Dafny.ISequence> _353_dType = _source0.dtor_dType; + Dafny.ISequence _354_variant = _source0.dtor_variant; { - RAST._IExpr _356_exprGen; - Defs._IOwnership _357___v120; - Dafny.ISet> _358_recIdents; + RAST._IExpr _355_exprGen; + Defs._IOwnership _356___v120; + Dafny.ISet> _357_recIdents; RAST._IExpr _out278; Defs._IOwnership _out279; Dafny.ISet> _out280; - (this).GenExpr(_353_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out278, out _out279, out _out280); - _356_exprGen = _out278; - _357___v120 = _out279; - _358_recIdents = _out280; - RAST._IExpr _359_variantExprPath; + (this).GenExpr(_352_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out278, out _out279, out _out280); + _355_exprGen = _out278; + _356___v120 = _out279; + _357_recIdents = _out280; + RAST._IExpr _358_variantExprPath; RAST._IExpr _out281; - _out281 = (this).GenPathExpr(Dafny.Sequence>.Concat(_354_dType, Dafny.Sequence>.FromElements(_355_variant)), true); - _359_variantExprPath = _out281; - r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_356_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _359_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); + _out281 = (this).GenPathExpr(Dafny.Sequence>.Concat(_353_dType, Dafny.Sequence>.FromElements(_354_variant)), true); + _358_variantExprPath = _out281; + r = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("matches!"))).Apply(Dafny.Sequence.FromElements(((_355_exprGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(), RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("{ .. }"), _358_variantExprPath, DAST.Format.UnaryOpFormat.create_NoFormat()))); RAST._IExpr _out282; Defs._IOwnership _out283; (this).FromOwned(r, expectedOwnership, out _out282, out _out283); r = _out282; resultingOwnership = _out283; - readIdents = _358_recIdents; + readIdents = _357_recIdents; return ; } goto after_match0; @@ -6676,77 +6688,77 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_Is) { - DAST._IExpression _360_expr = _source0.dtor_expr; - DAST._IType _361_fromTyp = _source0.dtor_fromType; - DAST._IType _362_toTyp = _source0.dtor_toType; + DAST._IExpression _359_expr = _source0.dtor_expr; + DAST._IType _360_fromTyp = _source0.dtor_fromType; + DAST._IType _361_toTyp = _source0.dtor_toType; { - RAST._IType _363_fromTpe; + RAST._IType _362_fromTpe; RAST._IType _out284; - _out284 = (this).GenType(_361_fromTyp, Defs.GenTypeContext.@default()); - _363_fromTpe = _out284; - RAST._IType _364_toTpe; + _out284 = (this).GenType(_360_fromTyp, Defs.GenTypeContext.@default()); + _362_fromTpe = _out284; + RAST._IType _363_toTpe; RAST._IType _out285; - _out285 = (this).GenType(_362_toTyp, Defs.GenTypeContext.@default()); - _364_toTpe = _out285; - if (((_363_fromTpe).IsObjectOrPointer()) && ((_364_toTpe).IsObjectOrPointer())) { - RAST._IExpr _365_expr; - Defs._IOwnership _366_recOwned; - Dafny.ISet> _367_recIdents; + _out285 = (this).GenType(_361_toTyp, Defs.GenTypeContext.@default()); + _363_toTpe = _out285; + if (((_362_fromTpe).IsObjectOrPointer()) && ((_363_toTpe).IsObjectOrPointer())) { + RAST._IExpr _364_expr; + Defs._IOwnership _365_recOwned; + Dafny.ISet> _366_recIdents; RAST._IExpr _out286; Defs._IOwnership _out287; Dafny.ISet> _out288; - (this).GenExpr(_360_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out286, out _out287, out _out288); - _365_expr = _out286; - _366_recOwned = _out287; - _367_recIdents = _out288; - r = (((_365_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_364_toTpe).ObjectOrPointerUnderlying()))).Apply0(); + (this).GenExpr(_359_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out286, out _out287, out _out288); + _364_expr = _out286; + _365_recOwned = _out287; + _366_recIdents = _out288; + r = (((_364_expr).Sel(Dafny.Sequence.UnicodeFromString("is_instance_of"))).ApplyType(Dafny.Sequence.FromElements((_363_toTpe).ObjectOrPointerUnderlying()))).Apply0(); RAST._IExpr _out289; Defs._IOwnership _out290; - (this).FromOwnership(r, _366_recOwned, expectedOwnership, out _out289, out _out290); + (this).FromOwnership(r, _365_recOwned, expectedOwnership, out _out289, out _out290); r = _out289; resultingOwnership = _out290; - readIdents = _367_recIdents; + readIdents = _366_recIdents; } else { - RAST._IExpr _368_expr; - Defs._IOwnership _369_recOwned; - Dafny.ISet> _370_recIdents; + RAST._IExpr _367_expr; + Defs._IOwnership _368_recOwned; + Dafny.ISet> _369_recIdents; RAST._IExpr _out291; Defs._IOwnership _out292; Dafny.ISet> _out293; - (this).GenExpr(_360_expr, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out291, out _out292, out _out293); - _368_expr = _out291; - _369_recOwned = _out292; - _370_recIdents = _out293; - bool _371_isDatatype; - _371_isDatatype = (_362_toTyp).IsDatatype(); - bool _372_isGeneralTrait; - _372_isGeneralTrait = (!(_371_isDatatype)) && ((_362_toTyp).IsGeneralTrait()); - if ((_371_isDatatype) || (_372_isGeneralTrait)) { - bool _373_isDowncast; - _373_isDowncast = (_362_toTyp).Extends(_361_fromTyp); - if (_373_isDowncast) { - DAST._IType _374_underlyingType; - if (_371_isDatatype) { - _374_underlyingType = (_362_toTyp).GetDatatypeType(); + (this).GenExpr(_359_expr, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out291, out _out292, out _out293); + _367_expr = _out291; + _368_recOwned = _out292; + _369_recIdents = _out293; + bool _370_isDatatype; + _370_isDatatype = (_361_toTyp).IsDatatype(); + bool _371_isGeneralTrait; + _371_isGeneralTrait = (!(_370_isDatatype)) && ((_361_toTyp).IsGeneralTrait()); + if ((_370_isDatatype) || (_371_isGeneralTrait)) { + bool _372_isDowncast; + _372_isDowncast = (_361_toTyp).Extends(_360_fromTyp); + if (_372_isDowncast) { + DAST._IType _373_underlyingType; + if (_370_isDatatype) { + _373_underlyingType = (_361_toTyp).GetDatatypeType(); } else { - _374_underlyingType = (_362_toTyp).GetGeneralTraitType(); + _373_underlyingType = (_361_toTyp).GetGeneralTraitType(); } - RAST._IType _375_toTpeRaw; + RAST._IType _374_toTpeRaw; RAST._IType _out294; - _out294 = (this).GenType(_374_underlyingType, Defs.GenTypeContext.@default()); - _375_toTpeRaw = _out294; - Std.Wrappers._IOption _376_toTpeRawDowncastOpt; - _376_toTpeRawDowncastOpt = (_375_toTpeRaw).ToDowncastExpr(); - if ((_376_toTpeRawDowncastOpt).is_Some) { - _368_expr = (this).FromGeneralBorrowToSelfBorrow(_368_expr, Defs.Ownership.create_OwnershipBorrowed(), env); - if (_371_isDatatype) { - _368_expr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_368_expr); + _out294 = (this).GenType(_373_underlyingType, Defs.GenTypeContext.@default()); + _374_toTpeRaw = _out294; + Std.Wrappers._IOption _375_toTpeRawDowncastOpt; + _375_toTpeRawDowncastOpt = (_374_toTpeRaw).ToDowncastExpr(); + if ((_375_toTpeRawDowncastOpt).is_Some) { + _367_expr = (this).FromGeneralBorrowToSelfBorrow(_367_expr, Defs.Ownership.create_OwnershipBorrowed(), env); + if (_370_isDatatype) { + _367_expr = ((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("AnyRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_any_ref"))).Apply1(_367_expr); } - r = (((_376_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_368_expr); - _369_recOwned = Defs.Ownership.create_OwnershipOwned(); + r = (((_375_toTpeRawDowncastOpt).dtor_value).FSel(Dafny.Sequence.UnicodeFromString("_is"))).Apply1(_367_expr); + _368_recOwned = Defs.Ownership.create_OwnershipOwned(); } else { RAST._IExpr _out295; - _out295 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_375_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); + _out295 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Could not convert "), (_374_toTpeRaw)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to a Downcast trait")), (this).InitEmptyExpr()); r = _out295; } } else { @@ -6761,10 +6773,10 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } RAST._IExpr _out298; Defs._IOwnership _out299; - (this).FromOwnership(r, _369_recOwned, expectedOwnership, out _out298, out _out299); + (this).FromOwnership(r, _368_recOwned, expectedOwnership, out _out298, out _out299); r = _out298; resultingOwnership = _out299; - readIdents = _370_recIdents; + readIdents = _369_recIdents; } return ; } @@ -6788,25 +6800,25 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBoundedPool) { - DAST._IExpression _377_of = _source0.dtor_of; + DAST._IExpression _376_of = _source0.dtor_of; { - RAST._IExpr _378_exprGen; - Defs._IOwnership _379___v121; - Dafny.ISet> _380_recIdents; + RAST._IExpr _377_exprGen; + Defs._IOwnership _378___v121; + Dafny.ISet> _379_recIdents; RAST._IExpr _out302; Defs._IOwnership _out303; Dafny.ISet> _out304; - (this).GenExpr(_377_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); - _378_exprGen = _out302; - _379___v121 = _out303; - _380_recIdents = _out304; - r = ((_378_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + (this).GenExpr(_376_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); + _377_exprGen = _out302; + _378___v121 = _out303; + _379_recIdents = _out304; + r = ((_377_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out305; Defs._IOwnership _out306; (this).FromOwned(r, expectedOwnership, out _out305, out _out306); r = _out305; resultingOwnership = _out306; - readIdents = _380_recIdents; + readIdents = _379_recIdents; return ; } goto after_match0; @@ -6814,21 +6826,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SeqBoundedPool) { - DAST._IExpression _381_of = _source0.dtor_of; - bool _382_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _380_of = _source0.dtor_of; + bool _381_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _383_exprGen; - Defs._IOwnership _384___v122; - Dafny.ISet> _385_recIdents; + RAST._IExpr _382_exprGen; + Defs._IOwnership _383___v122; + Dafny.ISet> _384_recIdents; RAST._IExpr _out307; Defs._IOwnership _out308; Dafny.ISet> _out309; - (this).GenExpr(_381_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out307, out _out308, out _out309); - _383_exprGen = _out307; - _384___v122 = _out308; - _385_recIdents = _out309; - r = ((_383_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_382_includeDuplicates)) { + (this).GenExpr(_380_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out307, out _out308, out _out309); + _382_exprGen = _out307; + _383___v122 = _out308; + _384_recIdents = _out309; + r = ((_382_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_381_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } RAST._IExpr _out310; @@ -6836,7 +6848,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir (this).FromOwned(r, expectedOwnership, out _out310, out _out311); r = _out310; resultingOwnership = _out311; - readIdents = _385_recIdents; + readIdents = _384_recIdents; return ; } goto after_match0; @@ -6844,21 +6856,21 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MultisetBoundedPool) { - DAST._IExpression _386_of = _source0.dtor_of; - bool _387_includeDuplicates = _source0.dtor_includeDuplicates; + DAST._IExpression _385_of = _source0.dtor_of; + bool _386_includeDuplicates = _source0.dtor_includeDuplicates; { - RAST._IExpr _388_exprGen; - Defs._IOwnership _389___v123; - Dafny.ISet> _390_recIdents; + RAST._IExpr _387_exprGen; + Defs._IOwnership _388___v123; + Dafny.ISet> _389_recIdents; RAST._IExpr _out312; Defs._IOwnership _out313; Dafny.ISet> _out314; - (this).GenExpr(_386_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out312, out _out313, out _out314); - _388_exprGen = _out312; - _389___v123 = _out313; - _390_recIdents = _out314; - r = ((_388_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - if (!(_387_includeDuplicates)) { + (this).GenExpr(_385_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out312, out _out313, out _out314); + _387_exprGen = _out312; + _388___v123 = _out313; + _389_recIdents = _out314; + r = ((_387_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + if (!(_386_includeDuplicates)) { r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("itertools"))).MSel(Dafny.Sequence.UnicodeFromString("Itertools"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unique"))).Apply1(r); } RAST._IExpr _out315; @@ -6866,7 +6878,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir (this).FromOwned(r, expectedOwnership, out _out315, out _out316); r = _out315; resultingOwnership = _out316; - readIdents = _390_recIdents; + readIdents = _389_recIdents; return ; } goto after_match0; @@ -6874,20 +6886,20 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBoundedPool) { - DAST._IExpression _391_of = _source0.dtor_of; + DAST._IExpression _390_of = _source0.dtor_of; { - RAST._IExpr _392_exprGen; - Defs._IOwnership _393___v124; - Dafny.ISet> _394_recIdents; + RAST._IExpr _391_exprGen; + Defs._IOwnership _392___v124; + Dafny.ISet> _393_recIdents; RAST._IExpr _out317; Defs._IOwnership _out318; Dafny.ISet> _out319; - (this).GenExpr(_391_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out317, out _out318, out _out319); - _392_exprGen = _out317; - _393___v124 = _out318; - _394_recIdents = _out319; - r = ((((_392_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); - readIdents = _394_recIdents; + (this).GenExpr(_390_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out317, out _out318, out _out319); + _391_exprGen = _out317; + _392___v124 = _out318; + _393_recIdents = _out319; + r = ((((_391_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); + readIdents = _393_recIdents; RAST._IExpr _out320; Defs._IOwnership _out321; (this).FromOwned(r, expectedOwnership, out _out320, out _out321); @@ -6899,20 +6911,20 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_ExactBoundedPool) { - DAST._IExpression _395_of = _source0.dtor_of; + DAST._IExpression _394_of = _source0.dtor_of; { - RAST._IExpr _396_exprGen; - Defs._IOwnership _397___v125; - Dafny.ISet> _398_recIdents; + RAST._IExpr _395_exprGen; + Defs._IOwnership _396___v125; + Dafny.ISet> _397_recIdents; RAST._IExpr _out322; Defs._IOwnership _out323; Dafny.ISet> _out324; - (this).GenExpr(_395_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out322, out _out323, out _out324); - _396_exprGen = _out322; - _397___v125 = _out323; - _398_recIdents = _out324; - r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_396_exprGen); - readIdents = _398_recIdents; + (this).GenExpr(_394_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out322, out _out323, out _out324); + _395_exprGen = _out322; + _396___v125 = _out323; + _397_recIdents = _out324; + r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_395_exprGen); + readIdents = _397_recIdents; RAST._IExpr _out325; Defs._IOwnership _out326; (this).FromOwned(r, expectedOwnership, out _out325, out _out326); @@ -6924,49 +6936,49 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_IntRange) { - DAST._IType _399_typ = _source0.dtor_elemType; - DAST._IExpression _400_lo = _source0.dtor_lo; - DAST._IExpression _401_hi = _source0.dtor_hi; - bool _402_up = _source0.dtor_up; + DAST._IType _398_typ = _source0.dtor_elemType; + DAST._IExpression _399_lo = _source0.dtor_lo; + DAST._IExpression _400_hi = _source0.dtor_hi; + bool _401_up = _source0.dtor_up; { - RAST._IExpr _403_lo; - Defs._IOwnership _404___v126; - Dafny.ISet> _405_recIdentsLo; + RAST._IExpr _402_lo; + Defs._IOwnership _403___v126; + Dafny.ISet> _404_recIdentsLo; RAST._IExpr _out327; Defs._IOwnership _out328; Dafny.ISet> _out329; - (this).GenExpr(_400_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out327, out _out328, out _out329); - _403_lo = _out327; - _404___v126 = _out328; - _405_recIdentsLo = _out329; - RAST._IExpr _406_hi; - Defs._IOwnership _407___v127; - Dafny.ISet> _408_recIdentsHi; + (this).GenExpr(_399_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out327, out _out328, out _out329); + _402_lo = _out327; + _403___v126 = _out328; + _404_recIdentsLo = _out329; + RAST._IExpr _405_hi; + Defs._IOwnership _406___v127; + Dafny.ISet> _407_recIdentsHi; RAST._IExpr _out330; Defs._IOwnership _out331; Dafny.ISet> _out332; - (this).GenExpr(_401_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out330, out _out331, out _out332); - _406_hi = _out330; - _407___v127 = _out331; - _408_recIdentsHi = _out332; - if (_402_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_403_lo, _406_hi)); + (this).GenExpr(_400_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out330, out _out331, out _out332); + _405_hi = _out330; + _406___v127 = _out331; + _407_recIdentsHi = _out332; + if (_401_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_402_lo, _405_hi)); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_406_hi, _403_lo)); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_405_hi, _402_lo)); } - if (!((_399_typ).is_Primitive)) { - RAST._IType _409_tpe; + if (!((_398_typ).is_Primitive)) { + RAST._IType _408_tpe; RAST._IType _out333; - _out333 = (this).GenType(_399_typ, Defs.GenTypeContext.@default()); - _409_tpe = _out333; - r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_409_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); + _out333 = (this).GenType(_398_typ, Defs.GenTypeContext.@default()); + _408_tpe = _out333; + r = ((r).Sel(Dafny.Sequence.UnicodeFromString("map"))).Apply1((((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("Into"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_408_tpe))).FSel(Dafny.Sequence.UnicodeFromString("into"))); } RAST._IExpr _out334; Defs._IOwnership _out335; (this).FromOwned(r, expectedOwnership, out _out334, out _out335); r = _out334; resultingOwnership = _out335; - readIdents = Dafny.Set>.Union(_405_recIdentsLo, _408_recIdentsHi); + readIdents = Dafny.Set>.Union(_404_recIdentsLo, _407_recIdentsHi); return ; } goto after_match0; @@ -6974,30 +6986,30 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_UnboundedIntRange) { - DAST._IExpression _410_start = _source0.dtor_start; - bool _411_up = _source0.dtor_up; + DAST._IExpression _409_start = _source0.dtor_start; + bool _410_up = _source0.dtor_up; { - RAST._IExpr _412_start; - Defs._IOwnership _413___v128; - Dafny.ISet> _414_recIdentStart; + RAST._IExpr _411_start; + Defs._IOwnership _412___v128; + Dafny.ISet> _413_recIdentStart; RAST._IExpr _out336; Defs._IOwnership _out337; Dafny.ISet> _out338; - (this).GenExpr(_410_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out336, out _out337, out _out338); - _412_start = _out336; - _413___v128 = _out337; - _414_recIdentStart = _out338; - if (_411_up) { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_412_start); + (this).GenExpr(_409_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out336, out _out337, out _out338); + _411_start = _out336; + _412___v128 = _out337; + _413_recIdentStart = _out338; + if (_410_up) { + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_411_start); } else { - r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_412_start); + r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_down_unbounded"))).AsExpr()).Apply1(_411_start); } RAST._IExpr _out339; Defs._IOwnership _out340; (this).FromOwned(r, expectedOwnership, out _out339, out _out340); r = _out339; resultingOwnership = _out340; - readIdents = _414_recIdentStart; + readIdents = _413_recIdentStart; return ; } goto after_match0; @@ -7005,18 +7017,18 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_MapBuilder) { - DAST._IType _415_keyType = _source0.dtor_keyType; - DAST._IType _416_valueType = _source0.dtor_valueType; + DAST._IType _414_keyType = _source0.dtor_keyType; + DAST._IType _415_valueType = _source0.dtor_valueType; { - RAST._IType _417_kType; + RAST._IType _416_kType; RAST._IType _out341; - _out341 = (this).GenType(_415_keyType, Defs.GenTypeContext.@default()); - _417_kType = _out341; - RAST._IType _418_vType; + _out341 = (this).GenType(_414_keyType, Defs.GenTypeContext.@default()); + _416_kType = _out341; + RAST._IType _417_vType; RAST._IType _out342; - _out342 = (this).GenType(_416_valueType, Defs.GenTypeContext.@default()); - _418_vType = _out342; - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_417_kType, _418_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + _out342 = (this).GenType(_415_valueType, Defs.GenTypeContext.@default()); + _417_vType = _out342; + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("MapBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_416_kType, _417_vType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); RAST._IExpr _out343; Defs._IOwnership _out344; (this).FromOwned(r, expectedOwnership, out _out343, out _out344); @@ -7030,14 +7042,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } { if (_source0.is_SetBuilder) { - DAST._IType _419_elemType = _source0.dtor_elemType; + DAST._IType _418_elemType = _source0.dtor_elemType; { - RAST._IType _420_eType; + RAST._IType _419_eType; RAST._IType _out345; - _out345 = (this).GenType(_419_elemType, Defs.GenTypeContext.@default()); - _420_eType = _out345; + _out345 = (this).GenType(_418_elemType, Defs.GenTypeContext.@default()); + _419_eType = _out345; readIdents = Dafny.Set>.FromElements(); - r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_420_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); + r = (((((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("SetBuilder"))).AsExpr()).ApplyType(Dafny.Sequence.FromElements(_419_eType))).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0(); RAST._IExpr _out346; Defs._IOwnership _out347; (this).FromOwned(r, expectedOwnership, out _out346, out _out347); @@ -7049,63 +7061,63 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir } } { - DAST._IType _421_elemType = _source0.dtor_elemType; - DAST._IExpression _422_collection = _source0.dtor_collection; - bool _423_is__forall = _source0.dtor_is__forall; - DAST._IExpression _424_lambda = _source0.dtor_lambda; + DAST._IType _420_elemType = _source0.dtor_elemType; + DAST._IExpression _421_collection = _source0.dtor_collection; + bool _422_is__forall = _source0.dtor_is__forall; + DAST._IExpression _423_lambda = _source0.dtor_lambda; { - RAST._IType _425_tpe; + RAST._IType _424_tpe; RAST._IType _out348; - _out348 = (this).GenType(_421_elemType, Defs.GenTypeContext.@default()); - _425_tpe = _out348; - RAST._IExpr _426_collectionGen; - Defs._IOwnership _427___v129; - Dafny.ISet> _428_recIdents; + _out348 = (this).GenType(_420_elemType, Defs.GenTypeContext.@default()); + _424_tpe = _out348; + RAST._IExpr _425_collectionGen; + Defs._IOwnership _426___v129; + Dafny.ISet> _427_recIdents; RAST._IExpr _out349; Defs._IOwnership _out350; Dafny.ISet> _out351; - (this).GenExpr(_422_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out349, out _out350, out _out351); - _426_collectionGen = _out349; - _427___v129 = _out350; - _428_recIdents = _out351; - Dafny.ISequence _429_extraAttributes; - _429_extraAttributes = Dafny.Sequence.FromElements(); - if ((((((_422_collection).is_IntRange) || ((_422_collection).is_UnboundedIntRange)) || ((_422_collection).is_SeqBoundedPool)) || ((_422_collection).is_ExactBoundedPool)) || ((_422_collection).is_MultisetBoundedPool)) { - _429_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); - } - if ((_424_lambda).is_Lambda) { - Dafny.ISequence _430_formals; - _430_formals = (_424_lambda).dtor_params; - Dafny.ISequence _431_newFormals; - _431_newFormals = Dafny.Sequence.FromElements(); - BigInteger _hi17 = new BigInteger((_430_formals).Count); - for (BigInteger _432_i = BigInteger.Zero; _432_i < _hi17; _432_i++) { - var _pat_let_tv0 = _429_extraAttributes; - var _pat_let_tv1 = _430_formals; - _431_newFormals = Dafny.Sequence.Concat(_431_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_430_formals).Select(_432_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _433_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_432_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _434_dt__update_hattributes_h0 => DAST.Formal.create((_433_dt__update__tmp_h0).dtor_name, (_433_dt__update__tmp_h0).dtor_typ, _434_dt__update_hattributes_h0))))))); - } - DAST._IExpression _435_newLambda; - DAST._IExpression _436_dt__update__tmp_h1 = _424_lambda; - Dafny.ISequence _437_dt__update_hparams_h0 = _431_newFormals; - _435_newLambda = DAST.Expression.create_Lambda(_437_dt__update_hparams_h0, (_436_dt__update__tmp_h1).dtor_retType, (_436_dt__update__tmp_h1).dtor_body); - RAST._IExpr _438_lambdaGen; - Defs._IOwnership _439___v130; - Dafny.ISet> _440_recLambdaIdents; + (this).GenExpr(_421_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out349, out _out350, out _out351); + _425_collectionGen = _out349; + _426___v129 = _out350; + _427_recIdents = _out351; + Dafny.ISequence _428_extraAttributes; + _428_extraAttributes = Dafny.Sequence.FromElements(); + if ((((((_421_collection).is_IntRange) || ((_421_collection).is_UnboundedIntRange)) || ((_421_collection).is_SeqBoundedPool)) || ((_421_collection).is_ExactBoundedPool)) || ((_421_collection).is_MultisetBoundedPool)) { + _428_extraAttributes = Dafny.Sequence.FromElements(Defs.__default.AttributeOwned); + } + if ((_423_lambda).is_Lambda) { + Dafny.ISequence _429_formals; + _429_formals = (_423_lambda).dtor_params; + Dafny.ISequence _430_newFormals; + _430_newFormals = Dafny.Sequence.FromElements(); + BigInteger _hi17 = new BigInteger((_429_formals).Count); + for (BigInteger _431_i = BigInteger.Zero; _431_i < _hi17; _431_i++) { + var _pat_let_tv0 = _428_extraAttributes; + var _pat_let_tv1 = _429_formals; + _430_newFormals = Dafny.Sequence.Concat(_430_newFormals, Dafny.Sequence.FromElements(Dafny.Helpers.Let((_429_formals).Select(_431_i), _pat_let28_0 => Dafny.Helpers.Let(_pat_let28_0, _432_dt__update__tmp_h0 => Dafny.Helpers.Let, DAST._IFormal>(Dafny.Sequence.Concat(_pat_let_tv0, ((_pat_let_tv1).Select(_431_i)).dtor_attributes), _pat_let29_0 => Dafny.Helpers.Let, DAST._IFormal>(_pat_let29_0, _433_dt__update_hattributes_h0 => DAST.Formal.create((_432_dt__update__tmp_h0).dtor_name, (_432_dt__update__tmp_h0).dtor_typ, _433_dt__update_hattributes_h0))))))); + } + DAST._IExpression _434_newLambda; + DAST._IExpression _435_dt__update__tmp_h1 = _423_lambda; + Dafny.ISequence _436_dt__update_hparams_h0 = _430_newFormals; + _434_newLambda = DAST.Expression.create_Lambda(_436_dt__update_hparams_h0, (_435_dt__update__tmp_h1).dtor_retType, (_435_dt__update__tmp_h1).dtor_body); + RAST._IExpr _437_lambdaGen; + Defs._IOwnership _438___v130; + Dafny.ISet> _439_recLambdaIdents; RAST._IExpr _out352; Defs._IOwnership _out353; Dafny.ISet> _out354; - (this).GenExpr(_435_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out352, out _out353, out _out354); - _438_lambdaGen = _out352; - _439___v130 = _out353; - _440_recLambdaIdents = _out354; - Dafny.ISequence _441_fn; - if (_423_is__forall) { - _441_fn = Dafny.Sequence.UnicodeFromString("all"); + (this).GenExpr(_434_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out352, out _out353, out _out354); + _437_lambdaGen = _out352; + _438___v130 = _out353; + _439_recLambdaIdents = _out354; + Dafny.ISequence _440_fn; + if (_422_is__forall) { + _440_fn = Dafny.Sequence.UnicodeFromString("all"); } else { - _441_fn = Dafny.Sequence.UnicodeFromString("any"); + _440_fn = Dafny.Sequence.UnicodeFromString("any"); } - r = ((_426_collectionGen).Sel(_441_fn)).Apply1(((_438_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); - readIdents = Dafny.Set>.Union(_428_recIdents, _440_recLambdaIdents); + r = ((_425_collectionGen).Sel(_440_fn)).Apply1(((_437_lambdaGen).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0()); + readIdents = Dafny.Set>.Union(_427_recIdents, _439_recLambdaIdents); } else { RAST._IExpr _out355; _out355 = (this).Error(Dafny.Sequence.UnicodeFromString("Quantifier without an inline lambda"), (this).InitEmptyExpr()); @@ -7138,6 +7150,7 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul Dafny.ISequence s = Dafny.Sequence.Empty; s = Dafny.Sequence.UnicodeFromString("#![allow(warnings, unconditional_panic)]\n"); s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("#![allow(nonstandard_style)]\n")); + s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("#![cfg_attr(any(), rustfmt::skip)]\n")); Dafny.ISequence _0_externUseDecls; _0_externUseDecls = Dafny.Sequence.FromElements(); BigInteger _hi0 = new BigInteger((externalFiles).Count); @@ -7357,11 +7370,51 @@ public Dafny.ISequence downcast { get { return Dafny.Sequence.UnicodeFromString("cast_object!"); } } } + public Defs._ISyncType _syncType {get; set;} + public Defs._ISyncType syncType { get { + return this._syncType; + } } + public RAST._IPath rcPath { get { + if (((this).syncType).is_NoSync) { + return RAST.__default.RcPath; + } else { + return RAST.__default.ArcPath; + } + } } + public RAST._IType rcType { get { + return ((this).rcPath).AsType(); + } } + public RAST._IExpr rcExpr { get { + return ((this).rcPath).AsExpr(); + } } + public Func rc { get { + return ((System.Func)((_0_underlying) => { + return ((this).rcType).Apply(Dafny.Sequence.FromElements(_0_underlying)); + })); + } } + public Func rcNew { get { + return ((System.Func)((_0_underlying) => { + return (((this).rcExpr).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply(Dafny.Sequence.FromElements(_0_underlying)); + })); + } } + public RAST._IType SyncSendType { get { + return RAST.Type.create_IntersectionType(RAST.__default.SyncType, RAST.__default.SendType); + } } + public RAST._IType AnyTrait { get { + if (((this).syncType).is_NoSync) { + return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType(); + } else { + return RAST.Type.create_IntersectionType(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType(), (this).SyncSendType); + } + } } public RAST._IExpr read__mutable__field__macro { get { return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("read_field!"))).AsExpr(); } } public RAST._IExpr modify__mutable__field__macro { get { return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("modify_field!"))).AsExpr(); } } + public RAST._IType DynAny { get { + return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DynAny"))).AsType(); + } } } } // end of namespace DCOMP \ No newline at end of file diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index 38c0d903ac9..3ee8e3755c4 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -522,9 +522,9 @@ public static RAST._IModDecl PrintImpl(Dafny.ISequence rTy { return Dafny.Sequence.FromElements(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithEq, RAST.__default.PartialEq, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed, RAST.Formal.create(Dafny.Sequence.UnicodeFromString("other"), RAST.__default.SelfBorrowed)), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(eqImplBody)))))), RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDeclsWithEq, RAST.__default.Eq, datatypeType, Dafny.Sequence.FromElements()))); } - public static RAST._IModDecl CoerceImpl(Dafny.ISequence rTypeParamsDecls, Dafny.ISequence datatypeName, RAST._IType datatypeType, Dafny.ISequence rCoerceTypeParams, Dafny.ISequence coerceArguments, Dafny.ISequence coerceTypes, RAST._IExpr coerceImplBody) + public static RAST._IModDecl CoerceImpl(Func rc, Func rcNew, Dafny.ISequence rTypeParamsDecls, Dafny.ISequence datatypeName, RAST._IType datatypeType, Dafny.ISequence rCoerceTypeParams, Dafny.ISequence coerceArguments, Dafny.ISequence coerceTypes, RAST._IExpr coerceImplBody) { - return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Given type parameter conversions, returns a lambda to convert this structure"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("coerce"), rCoerceTypeParams, coerceArguments, Std.Wrappers.Option.create_Some(RAST.__default.Rc(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(datatypeType), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes))))), Std.Wrappers.Option.create_Some(RAST.__default.RcNew(RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("this"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes)), coerceImplBody)))))))); + return RAST.ModDecl.create_ImplDecl(RAST.Impl.create_Impl(rTypeParamsDecls, datatypeType, Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(Dafny.Sequence.UnicodeFromString("Given type parameter conversions, returns a lambda to convert this structure"), RAST.__default.NoAttr, RAST.Visibility.create_PUB(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("coerce"), rCoerceTypeParams, coerceArguments, Std.Wrappers.Option.create_Some(Dafny.Helpers.Id>(rc)(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(datatypeType), RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes))))), Std.Wrappers.Option.create_Some(Dafny.Helpers.Id>(rcNew)(RAST.Expr.create_Lambda(Dafny.Sequence.FromElements(RAST.Formal.create(Dafny.Sequence.UnicodeFromString("this"), RAST.__default.SelfOwned)), Std.Wrappers.Option.create_Some(RAST.Type.create_TypeApp(RAST.Type.create_TIdentifier(datatypeName), coerceTypes)), coerceImplBody)))))))); } public static RAST._IModDecl SingletonsImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, RAST._IType instantiationType, Dafny.ISequence singletonConstructors) { @@ -598,7 +598,7 @@ public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence.create_Some(RAST.ModDecl.create_TraitDecl(RAST.Trait.create(RAST.__default.NoDoc, RAST.__default.NoAttr, rTypeParamsDecls, _1_downcast__type, Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_None())), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(fullType), Std.Wrappers.Option.create_None())))))); } } - public static Std.Wrappers._IOption DowncastImplFor(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType) + public static Std.Wrappers._IOption DowncastImplFor(Func rcNew, Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType) { Std.Wrappers._IOption _0_valueOrError0 = (datatypeType).ToDowncast(); if ((_0_valueOrError0).IsFailure()) { @@ -609,7 +609,7 @@ public static RAST._IModDecl PartialOrdImpl(Dafny.ISequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(_3_datatypeTypeRaw))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("is_some"))).Apply0(); RAST._IExpr _5_asBody = (((((((RAST.__default.self).Sel(Dafny.Sequence.UnicodeFromString("downcast_ref"))).ApplyType(Dafny.Sequence.FromElements(_3_datatypeTypeRaw))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("unwrap"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("clone"))).Apply0(); - RAST._IExpr _6_asBody = ((_2_isRc) ? (RAST.__default.RcNew(_5_asBody)) : (_5_asBody)); + RAST._IExpr _6_asBody = ((_2_isRc) ? (Dafny.Helpers.Id>(rcNew)(_5_asBody)) : (_5_asBody)); return Std.Wrappers.Option.create_Some(RAST.ModDecl.create_ImplDecl(RAST.Impl.create_ImplFor(rTypeParamsDecls, _1_downcast__type, RAST.Type.create_DynType(RAST.__default.AnyTrait), Dafny.Sequence.FromElements(RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_is"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(RAST.Type.create_Bool()), Std.Wrappers.Option.create_Some(_4_isBody))), RAST.ImplMember.create_FnDecl(RAST.__default.NoDoc, RAST.__default.NoAttr, RAST.Visibility.create_PRIV(), RAST.Fn.create(Dafny.Sequence.UnicodeFromString("_as"), Dafny.Sequence.FromElements(), Dafny.Sequence.FromElements(RAST.Formal.selfBorrowed), Std.Wrappers.Option.create_Some(datatypeType), Std.Wrappers.Option.create_Some(_6_asBody))))))); } } @@ -1338,6 +1338,81 @@ public override string ToString() { } } + public interface _ISyncType { + bool is_NoSync { get; } + bool is_Sync { get; } + _ISyncType DowncastClone(); + } + public abstract class SyncType : _ISyncType { + public SyncType() { + } + private static readonly Defs._ISyncType theDefault = create_NoSync(); + public static Defs._ISyncType Default() { + return theDefault; + } + private static readonly Dafny.TypeDescriptor _TYPE = new Dafny.TypeDescriptor(Defs.SyncType.Default()); + public static Dafny.TypeDescriptor _TypeDescriptor() { + return _TYPE; + } + public static _ISyncType create_NoSync() { + return new SyncType_NoSync(); + } + public static _ISyncType create_Sync() { + return new SyncType_Sync(); + } + public bool is_NoSync { get { return this is SyncType_NoSync; } } + public bool is_Sync { get { return this is SyncType_Sync; } } + public static System.Collections.Generic.IEnumerable<_ISyncType> AllSingletonConstructors { + get { + yield return SyncType.create_NoSync(); + yield return SyncType.create_Sync(); + } + } + public abstract _ISyncType DowncastClone(); + } + public class SyncType_NoSync : SyncType { + public SyncType_NoSync() : base() { + } + public override _ISyncType DowncastClone() { + if (this is _ISyncType dt) { return dt; } + return new SyncType_NoSync(); + } + public override bool Equals(object other) { + var oth = other as Defs.SyncType_NoSync; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 0; + return (int) hash; + } + public override string ToString() { + string s = "DafnyToRustCompilerDefinitions.SyncType.NoSync"; + return s; + } + } + public class SyncType_Sync : SyncType { + public SyncType_Sync() : base() { + } + public override _ISyncType DowncastClone() { + if (this is _ISyncType dt) { return dt; } + return new SyncType_Sync(); + } + public override bool Equals(object other) { + var oth = other as Defs.SyncType_Sync; + return oth != null; + } + public override int GetHashCode() { + ulong hash = 5381; + hash = ((hash << 5) + hash) + 1; + return (int) hash; + } + public override string ToString() { + string s = "DafnyToRustCompilerDefinitions.SyncType.Sync"; + return s; + } + } + public interface _IGenTypeContext { bool is_GenTypeContext { get; } bool dtor_forTraitParents { get; } diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs index 7f18178da61..13242934e75 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/system/mod.rs @@ -83,23 +83,23 @@ pub mod _System { } impl PartialEq - for Tuple2 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple2::_T2{_0, _1, }, Tuple2::_T2{_0: _2__0, _1: _2__1, }) => { - _0 == _2__0 && _1 == _2__1 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple2 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple2::_T2{_0, _1, }, Tuple2::_T2{_0: _2__0, _1: _2__1, }) => { + _0 == _2__0 && _1 == _2__1 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple2 {} impl Hash @@ -115,11 +115,11 @@ pub mod _System { } impl AsRef> - for Tuple2 { - fn as_ref(&self) -> &Self { - self + for Tuple2 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple0 { @@ -155,24 +155,24 @@ pub mod _System { } impl PartialEq - for Tuple0 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple0::_T0{}, Tuple0::_T0{}) => { - true - }, - _ => { - false - }, - } - } - } - - impl Eq - for Tuple0 {} + for Tuple0 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple0::_T0{}, Tuple0::_T0{}) => { + true + }, + _ => { + false + }, + } + } + } + + impl Eq + for Tuple0 {} impl Hash for Tuple0 { @@ -186,11 +186,11 @@ pub mod _System { } impl AsRef - for Tuple0 { - fn as_ref(&self) -> &Self { - self + for Tuple0 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple1 { @@ -245,23 +245,23 @@ pub mod _System { } impl PartialEq - for Tuple1 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple1::_T1{_0, }, Tuple1::_T1{_0: _2__0, }) => { - _0 == _2__0 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple1 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple1::_T1{_0, }, Tuple1::_T1{_0: _2__0, }) => { + _0 == _2__0 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple1 {} impl Hash @@ -276,11 +276,11 @@ pub mod _System { } impl AsRef> - for Tuple1 { - fn as_ref(&self) -> &Self { - self + for Tuple1 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple3 { @@ -355,23 +355,23 @@ pub mod _System { } impl PartialEq - for Tuple3 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple3::_T3{_0, _1, _2, }, Tuple3::_T3{_0: _2__0, _1: _2__1, _2: _2__2, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple3 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple3::_T3{_0, _1, _2, }, Tuple3::_T3{_0: _2__0, _1: _2__1, _2: _2__2, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple3 {} impl Hash @@ -388,11 +388,11 @@ pub mod _System { } impl AsRef> - for Tuple3 { - fn as_ref(&self) -> &Self { - self + for Tuple3 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple4 { @@ -477,23 +477,23 @@ pub mod _System { } impl PartialEq - for Tuple4 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple4::_T4{_0, _1, _2, _3, }, Tuple4::_T4{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple4 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple4::_T4{_0, _1, _2, _3, }, Tuple4::_T4{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple4 {} impl Hash @@ -511,11 +511,11 @@ pub mod _System { } impl AsRef> - for Tuple4 { - fn as_ref(&self) -> &Self { - self + for Tuple4 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple5 { @@ -610,23 +610,23 @@ pub mod _System { } impl PartialEq - for Tuple5 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple5::_T5{_0, _1, _2, _3, _4, }, Tuple5::_T5{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple5 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple5::_T5{_0, _1, _2, _3, _4, }, Tuple5::_T5{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple5 {} impl Hash @@ -645,11 +645,11 @@ pub mod _System { } impl AsRef> - for Tuple5 { - fn as_ref(&self) -> &Self { - self + for Tuple5 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple6 { @@ -754,23 +754,23 @@ pub mod _System { } impl PartialEq - for Tuple6 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple6::_T6{_0, _1, _2, _3, _4, _5, }, Tuple6::_T6{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple6 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple6::_T6{_0, _1, _2, _3, _4, _5, }, Tuple6::_T6{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple6 {} impl Hash @@ -790,11 +790,11 @@ pub mod _System { } impl AsRef> - for Tuple6 { - fn as_ref(&self) -> &Self { - self + for Tuple6 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple7 { @@ -909,23 +909,23 @@ pub mod _System { } impl PartialEq - for Tuple7 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, }, Tuple7::_T7{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple7 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple7::_T7{_0, _1, _2, _3, _4, _5, _6, }, Tuple7::_T7{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple7 {} impl Hash @@ -946,11 +946,11 @@ pub mod _System { } impl AsRef> - for Tuple7 { - fn as_ref(&self) -> &Self { - self + for Tuple7 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple8 { @@ -1075,23 +1075,23 @@ pub mod _System { } impl PartialEq - for Tuple8 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, }, Tuple8::_T8{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple8 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple8::_T8{_0, _1, _2, _3, _4, _5, _6, _7, }, Tuple8::_T8{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple8 {} impl Hash @@ -1113,11 +1113,11 @@ pub mod _System { } impl AsRef> - for Tuple8 { - fn as_ref(&self) -> &Self { - self + for Tuple8 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple9 { @@ -1252,23 +1252,23 @@ pub mod _System { } impl PartialEq - for Tuple9 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, }, Tuple9::_T9{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple9 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple9::_T9{_0, _1, _2, _3, _4, _5, _6, _7, _8, }, Tuple9::_T9{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple9 {} impl Hash @@ -1291,11 +1291,11 @@ pub mod _System { } impl AsRef> - for Tuple9 { - fn as_ref(&self) -> &Self { - self + for Tuple9 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple10 { @@ -1440,23 +1440,23 @@ pub mod _System { } impl PartialEq - for Tuple10 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, }, Tuple10::_T10{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple10 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple10::_T10{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, }, Tuple10::_T10{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple10 {} impl Hash @@ -1480,11 +1480,11 @@ pub mod _System { } impl AsRef> - for Tuple10 { - fn as_ref(&self) -> &Self { - self + for Tuple10 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple11 { @@ -1639,23 +1639,23 @@ pub mod _System { } impl PartialEq - for Tuple11 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, }, Tuple11::_T11{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple11 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple11::_T11{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, }, Tuple11::_T11{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple11 {} impl Hash @@ -1680,11 +1680,11 @@ pub mod _System { } impl AsRef> - for Tuple11 { - fn as_ref(&self) -> &Self { - self + for Tuple11 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple12 { @@ -1849,23 +1849,23 @@ pub mod _System { } impl PartialEq - for Tuple12 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, }, Tuple12::_T12{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple12 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple12::_T12{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, }, Tuple12::_T12{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple12 {} impl Hash @@ -1891,11 +1891,11 @@ pub mod _System { } impl AsRef> - for Tuple12 { - fn as_ref(&self) -> &Self { - self + for Tuple12 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple13 { @@ -2070,23 +2070,23 @@ pub mod _System { } impl PartialEq - for Tuple13 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, }, Tuple13::_T13{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple13 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple13::_T13{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, }, Tuple13::_T13{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple13 {} impl Hash @@ -2113,11 +2113,11 @@ pub mod _System { } impl AsRef> - for Tuple13 { - fn as_ref(&self) -> &Self { - self + for Tuple13 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple14 { @@ -2302,23 +2302,23 @@ pub mod _System { } impl PartialEq - for Tuple14 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, }, Tuple14::_T14{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple14 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple14::_T14{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, }, Tuple14::_T14{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple14 {} impl Hash @@ -2346,11 +2346,11 @@ pub mod _System { } impl AsRef> - for Tuple14 { - fn as_ref(&self) -> &Self { - self + for Tuple14 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple15 { @@ -2545,23 +2545,23 @@ pub mod _System { } impl PartialEq - for Tuple15 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, }, Tuple15::_T15{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple15 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple15::_T15{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, }, Tuple15::_T15{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple15 {} impl Hash @@ -2590,11 +2590,11 @@ pub mod _System { } impl AsRef> - for Tuple15 { - fn as_ref(&self) -> &Self { - self + for Tuple15 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple16 { @@ -2799,23 +2799,23 @@ pub mod _System { } impl PartialEq - for Tuple16 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, }, Tuple16::_T16{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple16 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple16::_T16{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, }, Tuple16::_T16{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple16 {} impl Hash @@ -2845,11 +2845,11 @@ pub mod _System { } impl AsRef> - for Tuple16 { - fn as_ref(&self) -> &Self { - self + for Tuple16 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple17 { @@ -3064,23 +3064,23 @@ pub mod _System { } impl PartialEq - for Tuple17 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, }, Tuple17::_T17{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple17 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple17::_T17{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, }, Tuple17::_T17{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple17 {} impl Hash @@ -3111,11 +3111,11 @@ pub mod _System { } impl AsRef> - for Tuple17 { - fn as_ref(&self) -> &Self { - self + for Tuple17 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple18 { @@ -3340,23 +3340,23 @@ pub mod _System { } impl PartialEq - for Tuple18 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, }, Tuple18::_T18{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple18 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple18::_T18{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, }, Tuple18::_T18{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple18 {} impl Hash @@ -3388,11 +3388,11 @@ pub mod _System { } impl AsRef> - for Tuple18 { - fn as_ref(&self) -> &Self { - self + for Tuple18 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple19 { @@ -3627,23 +3627,23 @@ pub mod _System { } impl PartialEq - for Tuple19 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, }, Tuple19::_T19{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, _18: _2__18, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 && _18 == _2__18 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple19 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple19::_T19{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, }, Tuple19::_T19{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, _18: _2__18, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 && _18 == _2__18 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple19 {} impl Hash @@ -3676,11 +3676,11 @@ pub mod _System { } impl AsRef> - for Tuple19 { - fn as_ref(&self) -> &Self { - self + for Tuple19 { + fn as_ref(&self) -> &Self { + self + } } - } #[derive(Clone)] pub enum Tuple20 { @@ -3925,23 +3925,23 @@ pub mod _System { } impl PartialEq - for Tuple20 { - fn eq(&self, other: &Self) -> bool { - match ( - self, - other - ) { - (Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, }, Tuple20::_T20{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, _18: _2__18, _19: _2__19, }) => { - _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 && _18 == _2__18 && _19 == _2__19 - }, - _ => { - false - }, - } - } - } - - impl Eq + for Tuple20 { + fn eq(&self, other: &Self) -> bool { + match ( + self, + other + ) { + (Tuple20::_T20{_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, }, Tuple20::_T20{_0: _2__0, _1: _2__1, _2: _2__2, _3: _2__3, _4: _2__4, _5: _2__5, _6: _2__6, _7: _2__7, _8: _2__8, _9: _2__9, _10: _2__10, _11: _2__11, _12: _2__12, _13: _2__13, _14: _2__14, _15: _2__15, _16: _2__16, _17: _2__17, _18: _2__18, _19: _2__19, }) => { + _0 == _2__0 && _1 == _2__1 && _2 == _2__2 && _3 == _2__3 && _4 == _2__4 && _5 == _2__5 && _6 == _2__6 && _7 == _2__7 && _8 == _2__8 && _9 == _2__9 && _10 == _2__10 && _11 == _2__11 && _12 == _2__12 && _13 == _2__13 && _14 == _2__14 && _15 == _2__15 && _16 == _2__16 && _17 == _2__17 && _18 == _2__18 && _19 == _2__19 + }, + _ => { + false + }, + } + } + } + + impl Eq for Tuple20 {} impl Hash @@ -3975,9 +3975,9 @@ pub mod _System { } impl AsRef> - for Tuple20 { - fn as_ref(&self) -> &Self { - self + for Tuple20 { + fn as_ref(&self) -> &Self { + self + } } - } } \ No newline at end of file From 954e7245b208571314c7b8f519730154dc7b5d03 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Tue, 28 Jan 2025 17:31:02 -0600 Subject: [PATCH 48/69] Fix format from merge --- Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index b96f4f22933..8e7b4255819 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -712,7 +712,7 @@ public ConcreteSyntaxTree CreateGetter(string name, TopLevelDecl enclosingDecl, name, [], (Sequence)Sequence.Empty, (Sequence)Sequence.Empty, - [ compiler.GenType(resultType) ], null); + [compiler.GenType(resultType)], null); methods.Add(builder); if (createBody) { From cb45a405e82aa541feb3ef53f71181d22f141ec3 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Thu, 30 Jan 2025 07:48:52 -0600 Subject: [PATCH 49/69] Fixed CI tests --- .../Backends/Rust/Dafny-compiler-rust.dfy | 16 ++++----- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 34 +++++++++---------- .../Resolver/TypeCharacteristicChecker.cs | 3 +- .../DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 2 +- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 84c73c62dd1..9b4e0f322dc 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -629,17 +629,17 @@ module {:extern "DCOMP"} DafnyToRustCompiler { for i := 0 to |t.parents| { var parentTyp := t.parents[i]; var parentTpe := GenType(parentTyp, GenTypeContext.ForTraitParents()); - var parentTpeExprMaybe := parentTpe.ToExpr(); - var parentTpeExpr; - if parentTpeExprMaybe.None? { - parentTpeExpr := Error("Cannot convert " + parentTpe.ToString("") + " to an expression"); - } else { - parentTpeExpr := parentTpeExprMaybe.value; - } parents := parents + [parentTpe]; var upcastTrait := if parentTyp.IsGeneralTrait() then "UpcastBox" else Upcast; parents := parents + [R.dafny_runtime.MSel(upcastTrait).AsType().Apply1(R.DynType(parentTpe))]; - if parentTyp.IsGeneralTrait() && t.traitType.GeneralTrait? { + if parentTyp.IsGeneralTrait() && t.traitType.GeneralTrait? && parentTpe != AnyTrait { + var parentTpeExprMaybe := parentTpe.ToExpr(); + var parentTpeExpr; + if parentTpeExprMaybe.None? { + parentTpeExpr := Error("Cannot convert " + parentTpe.ToString("") + " to an expression"); + } else { + parentTpeExpr := parentTpeExprMaybe.value; + } var upcastDynTrait := UpcastDynTraitFor(rTypeParamsDecls, instantiatedFullType, parentTpe, parentTpeExpr); upcastImplemented := upcastImplemented + [upcastDynTrait]; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index bace7efb7d1..39464166cfa 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -626,27 +626,27 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc RAST._IType _out5; _out5 = (this).GenType(_22_parentTyp, Defs.GenTypeContext.ForTraitParents()); _23_parentTpe = _out5; - Std.Wrappers._IOption _24_parentTpeExprMaybe; - _24_parentTpeExprMaybe = (_23_parentTpe).ToExpr(); - RAST._IExpr _25_parentTpeExpr = RAST.Expr.Default(); - if ((_24_parentTpeExprMaybe).is_None) { - RAST._IExpr _out6; - _out6 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Cannot convert "), (_23_parentTpe)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); - _25_parentTpeExpr = _out6; - } else { - _25_parentTpeExpr = (_24_parentTpeExprMaybe).dtor_value; - } _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements(_23_parentTpe)); - Dafny.ISequence _26_upcastTrait; + Dafny.ISequence _24_upcastTrait; if ((_22_parentTyp).IsGeneralTrait()) { - _26_upcastTrait = Dafny.Sequence.UnicodeFromString("UpcastBox"); + _24_upcastTrait = Dafny.Sequence.UnicodeFromString("UpcastBox"); } else { - _26_upcastTrait = (this).Upcast; - } - _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_26_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_23_parentTpe)))); - if (((_22_parentTyp).IsGeneralTrait()) && (((t).dtor_traitType).is_GeneralTrait)) { + _24_upcastTrait = (this).Upcast; + } + _17_parents = Dafny.Sequence.Concat(_17_parents, Dafny.Sequence.FromElements((((RAST.__default.dafny__runtime).MSel(_24_upcastTrait)).AsType()).Apply1(RAST.Type.create_DynType(_23_parentTpe)))); + if ((((_22_parentTyp).IsGeneralTrait()) && (((t).dtor_traitType).is_GeneralTrait)) && (!object.Equals(_23_parentTpe, (this).AnyTrait))) { + Std.Wrappers._IOption _25_parentTpeExprMaybe; + _25_parentTpeExprMaybe = (_23_parentTpe).ToExpr(); + RAST._IExpr _26_parentTpeExpr = RAST.Expr.Default(); + if ((_25_parentTpeExprMaybe).is_None) { + RAST._IExpr _out6; + _out6 = (this).Error(Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Cannot convert "), (_23_parentTpe)._ToString(Dafny.Sequence.UnicodeFromString(""))), Dafny.Sequence.UnicodeFromString(" to an expression")), (this).InitEmptyExpr()); + _26_parentTpeExpr = _out6; + } else { + _26_parentTpeExpr = (_25_parentTpeExprMaybe).dtor_value; + } RAST._IModDecl _27_upcastDynTrait; - _27_upcastDynTrait = Defs.__default.UpcastDynTraitFor(_1_rTypeParamsDecls, _19_instantiatedFullType, _23_parentTpe, _25_parentTpeExpr); + _27_upcastDynTrait = Defs.__default.UpcastDynTraitFor(_1_rTypeParamsDecls, _19_instantiatedFullType, _23_parentTpe, _26_parentTpeExpr); _18_upcastImplemented = Dafny.Sequence.Concat(_18_upcastImplemented, Dafny.Sequence.FromElements(_27_upcastDynTrait)); } } diff --git a/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs b/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs index d3b04225441..144ced57ada 100644 --- a/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs +++ b/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs @@ -40,8 +40,7 @@ private static void InferEqualitySupport(List declarations, ErrorR } else if (d is DatatypeDecl dt) { foreach (var tp in dt.TypeArgs) { if (tp.Characteristics.EqualitySupport == TypeParameter.EqualitySupportValue.Unspecified) { - // here's our chance to infer the need for equality support - inferredSomething = dt.Ctors.Any(ctor => + inferredSomething = inferredSomething || dt.Ctors.Any(ctor => ctor.Formals.Any(arg => InferAndSetEqualitySupport(tp, arg.Type, reporter) ) diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index fa7fc58a4ba..646f1a5bbe2 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -827,7 +827,7 @@ where } => { #[cfg(feature = "sync")] { - let mut guard = cache.as_ref().lock().unwrap(); + let guard = cache.as_ref().lock().unwrap(); let cache_borrow: Option<&Rc>> = guard.as_ref(); if let Some(cache) = cache_borrow { return Rc::clone(cache); From 801abb2b589e22e94b8902bb5025975483e8ed46 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Thu, 30 Jan 2025 09:19:38 -0600 Subject: [PATCH 50/69] Ensure everything is tested --- .../Backends/Dafny/DafnyCodeGenerator.cs | 27 ++++++++++++++----- .../LitTest/comp/rust/externalclasses.dfy | 16 ++++++++++- .../comp/rust/externalclasses.dfy.expect | 2 +- .../LitTest/comp/rust/externalclasses.rs | 18 +++++++++++++ 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs index 8e7b4255819..52869bc323b 100644 --- a/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs @@ -219,6 +219,10 @@ private TypeParameterInfo GenTypeParameterInfo(TypeParameter tp) { tp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype); } + private ISequence GenTypeParameterInfos(List typeParams) { + return Sequence.FromArray(typeParams.Select(GenTypeParameterInfo).ToArray()); + } + private Variance GenTypeVariance(TypeParameter tp) { if (tp.Variance is TypeParameter.TPVariance.Co) { return (Variance)Variance.create_Covariant(); @@ -288,6 +292,7 @@ protected override IClassWriter CreateTrait(string name, bool isExtern, List type var seqTypeArgs = Sequence.FromArray(typeArgs.Select(m => GenType(m)).ToArray()); DAST.ResolvedTypeBase resolvedTypeBase; + var attributes = topLevel.Attributes; if (topLevel is NewtypeDecl newType) { var range = NativeTypeToNewtypeRange(newType, false); @@ -1885,23 +1891,21 @@ private DAST.Type TypeNameASTFromTopLevel(TopLevelDecl topLevel, List type : TraitType.create_GeneralTrait(); resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Trait(traitType); } else if (topLevel is DatatypeDecl dd) { - var infos = Sequence.FromArray(dd.TypeArgs.Select(GenTypeParameterInfo).ToArray()); + var infos = GenTypeParameterInfos(dd.TypeArgs); var equalitySupport = GenEqualitySupport(dd); resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Datatype( equalitySupport, infos); } else if (topLevel is ClassDecl) { resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Class(); } else if (topLevel is AbstractTypeDecl atd) { - var traitType = atd.ParentTraits.Any(s => s.IsRefType) ? - TraitType.create_ObjectTrait() : - TraitType.create_GeneralTrait(); - resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Trait(traitType); + resolvedTypeBase = (DAST.ResolvedTypeBase)DAST.ResolvedTypeBase.create_Datatype(GenEqualitySupport(topLevel), GenTypeParameterInfos(topLevel.TypeArgs)); + attributes = new Attributes("rust_rc", [Expression.CreateBoolLiteral(Token.NoToken, false)], attributes); } else { // SubsetTypeDecl are covered by TypeSynonymDecl throw new InvalidOperationException(topLevel.GetType().ToString()); } var resolvedType = (DAST.ResolvedType)DAST.ResolvedType.create_ResolvedType( - path, seqTypeArgs, resolvedTypeBase, ParseAttributes(topLevel.Attributes), seqProperMethods, seqExtendTraits); + path, seqTypeArgs, resolvedTypeBase, ParseAttributes(attributes), seqProperMethods, seqExtendTraits); DAST.Type baseType = (DAST.Type)DAST.Type.create_UserDefined(resolvedType); @@ -1912,7 +1916,16 @@ private static _IEqualitySupport GenEqualitySupport(Declaration decl) { Contract.Requires(decl is IndDatatypeDecl or NewtypeDecl); IndDatatypeDecl.ES equalitySupport = decl is IndDatatypeDecl indDecl ? indDecl.EqualitySupport : - decl is NewtypeDecl nt ? nt.EqualitySupport : IndDatatypeDecl.ES.Never; + decl is NewtypeDecl nt ? nt.EqualitySupport : + decl is AbstractTypeDecl atd ? + atd.Characteristics.EqualitySupport switch { + TypeParameter.EqualitySupportValue.Required => IndDatatypeDecl.ES.ConsultTypeArguments, + TypeParameter.EqualitySupportValue.InferredRequired => IndDatatypeDecl.ES.ConsultTypeArguments, + TypeParameter.EqualitySupportValue.Unspecified => IndDatatypeDecl.ES.Never, + _ => throw new ArgumentOutOfRangeException() + } + : + IndDatatypeDecl.ES.Never; return equalitySupport switch { IndDatatypeDecl.ES.Never => EqualitySupport.create_Never(), diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy index c6d50772615..7fea88f510e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy @@ -1,8 +1,11 @@ -// NONUNIFORM: Rust-specific tests +// NONUNIFORM: Rust-specific tests. Extern abstract types only compile with the Rust compiler for now. // RUN: %baredafny run --target=rs --input "%S/externalclasses.rs" "%s" > "%t" // RUN: %diff "%s.expect" "%t" module {:extern "External.Class.Container"} ExternalClassContainer { + @NativeUInt64 + newtype u64 = x : int | 0 <= x <= 0xFFFF_FFFF_FFFF_FFFF + class {:extern} ExternalClass { constructor {:extern} (i: int) } @@ -27,6 +30,13 @@ module {:extern "External.Class.Container"} ExternalClassContainer { print GetValue(); } } + + type {:extern "StringWrapper"} RustString { + ghost const s: string + static function from_char(s: char): RustString + function concat(other: RustString): RustString + function length_bytes(): u64 + } } module Dafny.FileIO { @@ -99,5 +109,9 @@ method Main() { n.Put("x"); expect n.Get() == "x"; expect n.GetOpt() == "Some(x)"; + var a := ExternalClassContainer.RustString.from_char('a'); + expect a.length_bytes() == 1; + a := a.concat(a); + expect a.length_bytes() == 2; print message; } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy.expect index 86c68713487..9fa90752819 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy.expect @@ -1,3 +1,3 @@ -Dafny program verifier finished with 7 verified, 0 errors +Dafny program verifier finished with 8 verified, 0 errors 22Everything is ok. \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.rs b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.rs index e061478f099..b444323ef7a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.rs +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.rs @@ -4,7 +4,25 @@ pub mod External { pub mod Class { pub mod Container { + use std::str::FromStr; + + use dafny_runtime::DafnyChar; + use crate::*; + pub struct StringWrapper(String); + impl StringWrapper { + pub(crate) fn from_char(c: &DafnyChar) -> StringWrapper { + StringWrapper(String::from(c.0)) + } + + pub(crate) fn length_bytes(&self) -> u64 { + self.0.len() as u64 + } + + pub(crate) fn concat(&self, a: &StringWrapper) -> StringWrapper { + StringWrapper(format!("{}{}", self.0, a.0)) + } + } pub struct ExternalClass {} impl ExternalClass { From 2fa934ceb6fbf141b81b9389975c1bef7ff69863 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Thu, 30 Jan 2025 12:38:19 -0600 Subject: [PATCH 51/69] Updated tooltip --- .../TestFiles/LitTests/LitTest/dafny0/Tooltips.dfy.expect | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Tooltips.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Tooltips.dfy.expect index db3d6ab324c..9ef12d2cb20 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Tooltips.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Tooltips.dfy.expect @@ -3,8 +3,8 @@ Tooltips.dfy(4,7): Info: (==) Tooltips.dfy(6,8): Info: (==) Tooltips.dfy(7,8): Info: (==) Tooltips.dfy(9,12): Info: (==) -Tooltips.dfy(10,13): Info: (==) Tooltips.dfy(12,12): Info: (==) +Tooltips.dfy(10,13): Info: (==) Tooltips.dfy(13,15): Info: (==) Tooltips.dfy(15,9): Info: (==) Tooltips.dfy(16,9): Info: (==) From 8b34df852ca69170952dc69d57395d4972f9c4b7 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Tue, 4 Feb 2025 09:59:36 -0600 Subject: [PATCH 52/69] Fixed two issues --- .../Rust/Dafny-compiler-rust-definitions.dfy | 2 +- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 2 +- Source/DafnyCore/Resolver/ModuleResolver.cs | 6 +----- .../LitTest/comp/rust/datatypes-scoping.dfy | 14 +++++++++++++- .../LitTest/comp/rust/datatypes-scoping.dfy.expect | 2 ++ .../comp/rust/small/10-type-parameter-equality.dfy | 4 ++++ 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index ef4ee65b373..3d3b6a6fbb9 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -27,7 +27,7 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { // Method names that would automatically resolve to trait methods instead of inherent methods // Hence, full name is always required for these methods const builtin_trait_preferred_methods := { - "le", "eq", "lt", "ge", "gt" + "le", "eq", "lt", "ge", "gt", "hash" } diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index 3ee8e3755c4..454899a3d4e 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -803,7 +803,7 @@ public static Dafny.ISequence IND { get { return RAST.__default.IND; } } public static Dafny.ISet> builtin__trait__preferred__methods { get { - return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("le"), Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.UnicodeFromString("lt"), Dafny.Sequence.UnicodeFromString("ge"), Dafny.Sequence.UnicodeFromString("gt")); + return Dafny.Set>.FromElements(Dafny.Sequence.UnicodeFromString("le"), Dafny.Sequence.UnicodeFromString("eq"), Dafny.Sequence.UnicodeFromString("lt"), Dafny.Sequence.UnicodeFromString("ge"), Dafny.Sequence.UnicodeFromString("gt"), Dafny.Sequence.UnicodeFromString("hash")); } } public static DAST._IAttribute AttributeOwned { get { return DAST.Attribute.create(Dafny.Sequence.UnicodeFromString("owned"), Dafny.Sequence>.FromElements()); diff --git a/Source/DafnyCore/Resolver/ModuleResolver.cs b/Source/DafnyCore/Resolver/ModuleResolver.cs index 12b1ff32e21..30b83bea96a 100644 --- a/Source/DafnyCore/Resolver/ModuleResolver.cs +++ b/Source/DafnyCore/Resolver/ModuleResolver.cs @@ -2991,11 +2991,7 @@ public static void DetermineEqualitySupportType(Type type, ref bool thingsChange var i = 0; foreach (var otherTp in otherDt.TypeArgs) { if (otherTp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype) { - var tp = otherUdt.TypeArgs[i].AsTypeParameter; - if (tp != null) { - tp.NecessaryForEqualitySupportOfSurroundingInductiveDatatype = true; - thingsChanged = true; - } + DetermineEqualitySupportType(otherUdt.TypeArgs[i], ref thingsChanged); } i++; diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy index 4bde1628787..67f6d43b0f4 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy @@ -4,6 +4,18 @@ datatype Loop = Loop(loop: Loop) | Point() { function hash(): string { - "uh-oh!" + "This is Dafny Hash" } +} + +datatype Loop2 = Loop2(loop: Loop) { + method hash() { + print "\nThis is Dafny hash 2"; + } +} + +method Main() { + var t := Loop(Point()); + print t.hash(); + Loop2(t).hash(); } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect index 012f5b99379..4fdc6d557bf 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect @@ -1,2 +1,4 @@ Dafny program verifier finished with 0 verified, 0 errors +This is Dafny Hash +This is Dafny hash 2 \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy index b78d8dd5d50..5dd19147f48 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy @@ -36,6 +36,10 @@ datatype {:rust_rc false} DoubleWithGhostWrapper = DoubleWithGhostWrapper( dwg:DoubleWithGhost ) +datatype Wrapper1 = Wrapper1(w1: T) +datatype Wrapper2 = Wrapper2(w2: T) +datatype Wrapper3 = Wrapper3(w21: Wrapper2>) + method Test() { } From b5950bacdf46eab74cf9da23fe7ca156b4ea9301 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Tue, 4 Feb 2025 14:06:33 -0600 Subject: [PATCH 53/69] Added two failing tests --- .../LitTests/LitTest/comp/rust/classes.dfy | 16 +++++++++++----- .../rust/small/10-type-parameter-equality.dfy | 6 +++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy index 3bc5b6caeb3..5aa9fd3f3dd 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy @@ -4,19 +4,25 @@ // RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" // RUN: %diff "%s.expect" "%t" +datatype D = D(value: int) + class Y { var c: int ghost var Repr: set - const d: int - constructor(c: int) ensures this.c == c && d == c { + const d: D + constructor(c: int) ensures this.c == c && d.value == c { this.c := c; - this.d := c; + if c == 1 { + this.d := D(1); + } else { + this.d := D(c); + } this.Repr := {this}; } - constructor Two() ensures c == 2 == d { + constructor Two() ensures c == 2 == d.value { this.c := 2; - this.d := c; + this.d := D(c); this.Repr := {this}; } } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy index 5dd19147f48..a41ea691202 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy @@ -38,7 +38,11 @@ datatype {:rust_rc false} DoubleWithGhostWrapper = DoubleWithGhostWrapper( datatype Wrapper1 = Wrapper1(w1: T) datatype Wrapper2 = Wrapper2(w2: T) -datatype Wrapper3 = Wrapper3(w21: Wrapper2>) +datatype Wrapper3 = Wrapper3(w21: Wrapper2>) { + function ReturnThis(f: Wrapper3 -> Wrapper3): Wrapper3 { + f(this) + } +} method Test() { } From f2d7eb87790864a9454d90c484dd8c86dc0b0237 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Wed, 5 Feb 2025 14:16:38 -0600 Subject: [PATCH 54/69] Support for detecting complete assignments in constructor and panic if unassigned --- .../Rust/Dafny-compiler-rust-definitions.dfy | 23 +- .../Backends/Rust/Dafny-compiler-rust.dfy | 12 +- Source/DafnyCore/Backends/Rust/RustBackend.cs | 3 + Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 934 +++++++++--------- Source/DafnyCore/GeneratedFromDafny/Defs.cs | 23 +- .../LitTest/comp/rust/classes-relax.dfy | 36 + .../comp/rust/classes-relax.dfy.expect | 3 + .../comp/rust/classes-relax.dfy.wrong.expect | 3 + 8 files changed, 553 insertions(+), 484 deletions(-) create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.expect create mode 100644 Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy index 3d3b6a6fbb9..c79f31e51aa 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy @@ -190,7 +190,8 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { { Environment(names + [name], types[name := tpe], assignmentStatusKnown - {name}) } - function merge(other: Environment): Environment + // Merges a current environment with a new one + function Merge(other: Environment): Environment { Environment( names + other.names, @@ -198,6 +199,15 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { assignmentStatusKnown + other.assignmentStatusKnown ) } + // When exiting If-then-else, we can remove variables that were unassigned in both branches + function Join(thenBranch: Environment, elseBranch: Environment): Environment { + var removed := types.Keys - (thenBranch.types.Keys + elseBranch.types.Keys); + Environment( + Std.Collections.Seq.Filter(name => name !in removed, names), + types - removed, + assignmentStatusKnown - removed + ) + } // Used to removed from the environment the "_is_assigned" vars used to initialize fields function RemoveAssigned(name: string): Environment requires name in names @@ -519,13 +529,18 @@ module {:extern "Defs"} DafnyToRustCompilerDefinitions { ensures BecomesLeftCallsRight(op) ==> !BecomesRightCallsLeft(op) {} + function Panic(optText: string := ""): R.Expr { + if optText == "" then + R.Identifier("panic!").Apply0() + else + R.Identifier("panic!").Apply1(R.LiteralString(optText, binary := false, verbatim := false)) + } + function UnreachablePanicIfVerified(pointerType: PointerType, optText: string := ""): R.Expr { if pointerType.Raw? then R.Unsafe(R.Block(R.std.MSel("hint").AsExpr().FSel("unreachable_unchecked").Apply0())) - else if optText == "" then - R.Identifier("panic!").Apply0() else - R.Identifier("panic!").Apply1(R.LiteralString(optText, binary := false, verbatim := false)) + Panic(optText) } function DefaultDatatypeImpl( diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 9b4e0f322dc..fc4b881dd10 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -2229,9 +2229,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var fieldName := escapeVar(field.formal.name); var fieldTyp := GenType(field.formal.typ, GenTypeContext.default()); var isAssignedVar := AddAssignedPrefix(fieldName); - if isAssignedVar in newEnv.names { - assume {:axiom} InitializationValue(field.formal.typ) < stmt; // Needed for termination - var rhs, _, _ := GenExpr(InitializationValue(field.formal.typ), selfIdent, env, OwnershipOwned); + if isAssignedVar in newEnv.names { // We can't determine statically if the field was assigned + var panicked := "Field "+ fieldName +" is not initialized"; + var rhs := UnreachablePanicIfVerified(pointerType, panicked); readIdents := readIdents + {isAssignedVar}; var update_if_uninit := if field.isConstant then update_field_if_uninit_macro else update_field_mut_if_uninit_macro; @@ -2307,7 +2307,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := readIdents + thnIdents; var els, elsIdents, elsEnv := GenStmts(elsDafny, selfIdent, env, isLast, earlyReturn); readIdents := readIdents + elsIdents; - newEnv := env; + + // All variables that both thnEnv and elsEnv remove can be removed from the environment + newEnv := env.Join(thnEnv, elsEnv); generated := R.IfExpr(cond, thn, els); } case Labeled(lbl, body) => { @@ -4162,7 +4164,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { paramNames := paramNames + [name]; paramTypesMap := paramTypesMap[name := params[i].tpe]; } - var subEnv := env.ToOwned().merge(Environment(paramNames, paramTypesMap, {})); + var subEnv := env.ToOwned().Merge(Environment(paramNames, paramTypesMap, {})); var recursiveGen, recIdents, _ := GenStmts(body, if selfIdent != NoSelf then ThisTyped("_this", selfIdent.dafnyType) else NoSelf, subEnv, true, None); readIdents := {}; diff --git a/Source/DafnyCore/Backends/Rust/RustBackend.cs b/Source/DafnyCore/Backends/Rust/RustBackend.cs index 6e948c748b8..70d09b4b64a 100644 --- a/Source/DafnyCore/Backends/Rust/RustBackend.cs +++ b/Source/DafnyCore/Backends/Rust/RustBackend.cs @@ -48,6 +48,9 @@ public override string TargetBaseDir(string dafnyProgramName) => $"{Path.GetFileNameWithoutExtension(dafnyProgramName)}-rust/src"; protected override DafnyWrittenCodeGenerator CreateDafnyWrittenCompiler() { + if (Options.Get(CommonOptionBag.RelaxDefiniteAssignment)) { + throw new UnsupportedInvalidOperationException("The Rust compiler does not support `--relax-definite-assignment`"); + } return new RustCodeGenerator(Options); } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 39464166cfa..324f6820471 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -458,13 +458,13 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _out8 = (this).GenType(_13_typeArg, Defs.GenTypeContext.@default()); _15_rTypeArg = _out8; if ((_6_usedTypeParams).Contains((_14_typeParam).dtor_name)) { - goto continue_0; + goto continue_1; } _4_fields = Dafny.Sequence.Concat(_4_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(_12_typeParamI)), RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_15_rTypeArg)))))); _5_fieldInits = Dafny.Sequence.Concat(_5_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_12_typeParamI)), (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsExpr()))); - continue_0: ; + continue_1: ; } - after_0: ; + after_1: ; Dafny.ISequence _16_className; Defs._IExternAttribute _17_extern; Dafny.ISequence _out9; @@ -1128,7 +1128,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _54_types = Dafny.Sequence.Concat(_54_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_59_rTypeArg)))); if (((_55_typeI) < (new BigInteger((_7_typeParamInfos).Count))) && ((((_7_typeParamInfos).Select(_55_typeI)).dtor_variance).is_Nonvariant)) { _48_coerceTypes = Dafny.Sequence.Concat(_48_coerceTypes, Dafny.Sequence.FromElements(_59_rTypeArg)); - goto continue_2_0; + goto continue_2; } DAST._ITypeArgDecl _60_coerceTypeParam; DAST._ITypeArgDecl _61_dt__update__tmp_h0 = _56_typeParam; @@ -1153,9 +1153,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _66_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_55_typeI)); _53_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_53_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_59_rTypeArg, _65_rCoerceType), (RAST.Expr.create_Identifier(_66_coerceFormal)).Clone()))); _50_coerceArguments = Dafny.Sequence.Concat(_50_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_66_coerceFormal, Dafny.Helpers.Id>((this).rc)(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_59_rTypeArg), _65_rCoerceType)), RAST.__default.StaticTrait))))); - continue_2_0: ; + continue_2: ; } - after_2_0: ; + after_2: ; if ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1) { _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_67_tpe) => { return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _67_tpe); @@ -1219,7 +1219,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) DAST._IType _82_c; _82_c = ((c).dtor_superTraitTypes).Select(_81_i); if ((((_82_c).is_UserDefined) && ((((_82_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_82_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { - goto continue_3_0; + goto continue_3; } RAST._IType _83_cType; RAST._IType _out19; @@ -1237,9 +1237,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } else { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_85_downcastImplementationsOpt).dtor_value)); } - continue_3_0: ; + continue_3: ; } - after_3_0: ; + after_3: ; } Dafny.ISequence _87_printImplBodyCases; _87_printImplBodyCases = Dafny.Sequence.FromElements(); @@ -2243,13 +2243,13 @@ public void GenStmts(Dafny.ISequence stmts, Defs._ISelfInfo se readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_18_recIdents, _0_declarations)); generated = (generated).Then(_17_stmtExpr); if ((_17_stmtExpr).is_Return) { - goto after_0; + goto after_4; } _1_i = (_1_i) + (BigInteger.One); } - continue_0: ; + continue_4: ; } - after_0: ; + after_4: ; } public void GenDeclareVarAssign(Dafny.ISequence name, DAST._IType typ, DAST._IExpression rhs, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, out RAST._IExpr generated, out Dafny.ISet> readIdents, out Defs._IEnvironment newEnv) { @@ -2638,24 +2638,18 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _5_isAssignedVar; _5_isAssignedVar = Defs.__default.AddAssignedPrefix(_3_fieldName); if (((newEnv).dtor_names).Contains(_5_isAssignedVar)) { - RAST._IExpr _6_rhs; - Defs._IOwnership _7___v37; - Dafny.ISet> _8___v38; - RAST._IExpr _out1; - Defs._IOwnership _out2; - Dafny.ISet> _out3; - (this).GenExpr(DAST.Expression.create_InitializationValue(((_2_field).dtor_formal).dtor_typ), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out1, out _out2, out _out3); - _6_rhs = _out1; - _7___v37 = _out2; - _8___v38 = _out3; + Dafny.ISequence _6_panicked; + _6_panicked = Dafny.Sequence.Concat(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("Field "), _3_fieldName), Dafny.Sequence.UnicodeFromString(" is not initialized")); + RAST._IExpr _7_rhs; + _7_rhs = Defs.__default.UnreachablePanicIfVerified((this).pointerType, _6_panicked); readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.FromElements(_5_isAssignedVar)); - Dafny.ISequence _9_update__if__uninit; + Dafny.ISequence _8_update__if__uninit; if ((_2_field).dtor_isConstant) { - _9_update__if__uninit = (this).update__field__if__uninit__macro; + _8_update__if__uninit = (this).update__field__if__uninit__macro; } else { - _9_update__if__uninit = (this).update__field__mut__if__uninit__macro; + _8_update__if__uninit = (this).update__field__mut__if__uninit__macro; } - generated = (generated).Then((((RAST.__default.dafny__runtime).MSel(_9_update__if__uninit)).AsExpr()).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), RAST.Expr.create_Identifier(_3_fieldName), RAST.Expr.create_Identifier(_5_isAssignedVar), _6_rhs))); + generated = (generated).Then((((RAST.__default.dafny__runtime).MSel(_8_update__if__uninit)).AsExpr()).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("this")), RAST.Expr.create_Identifier(_3_fieldName), RAST.Expr.create_Identifier(_5_isAssignedVar), _7_rhs))); newEnv = (newEnv).RemoveAssigned(_5_isAssignedVar); } } @@ -2665,37 +2659,37 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_DeclareVar) { - Dafny.ISequence _10_name = _source0.dtor_name; - DAST._IType _11_typ = _source0.dtor_typ; + Dafny.ISequence _9_name = _source0.dtor_name; + DAST._IType _10_typ = _source0.dtor_typ; Std.Wrappers._IOption maybeValue0 = _source0.dtor_maybeValue; if (maybeValue0.is_Some) { - DAST._IExpression _12_expression = maybeValue0.dtor_value; + DAST._IExpression _11_expression = maybeValue0.dtor_value; { - RAST._IType _13_tpe; - RAST._IType _out4; - _out4 = (this).GenType(_11_typ, Defs.GenTypeContext.@default()); - _13_tpe = _out4; - Dafny.ISequence _14_varName; - _14_varName = Defs.__default.escapeVar(_10_name); - bool _15_hasCopySemantics; - _15_hasCopySemantics = (_13_tpe).CanReadWithoutClone(); - if (((_12_expression).is_InitializationValue) && (!(_15_hasCopySemantics))) { - if ((env).IsAssignmentStatusKnown(_14_varName)) { - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _14_varName, Std.Wrappers.Option.create_Some(_13_tpe), Std.Wrappers.Option.create_None()); + RAST._IType _12_tpe; + RAST._IType _out1; + _out1 = (this).GenType(_10_typ, Defs.GenTypeContext.@default()); + _12_tpe = _out1; + Dafny.ISequence _13_varName; + _13_varName = Defs.__default.escapeVar(_9_name); + bool _14_hasCopySemantics; + _14_hasCopySemantics = (_12_tpe).CanReadWithoutClone(); + if (((_11_expression).is_InitializationValue) && (!(_14_hasCopySemantics))) { + if ((env).IsAssignmentStatusKnown(_13_varName)) { + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _13_varName, Std.Wrappers.Option.create_Some(_12_tpe), Std.Wrappers.Option.create_None()); } else { - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _14_varName, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((((RAST.__default.MaybePlaceboPath).AsExpr()).ApplyType1(_13_tpe)).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0())); - _13_tpe = RAST.__default.MaybePlaceboType(_13_tpe); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _13_varName, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(((((RAST.__default.MaybePlaceboPath).AsExpr()).ApplyType1(_12_tpe)).FSel(Dafny.Sequence.UnicodeFromString("new"))).Apply0())); + _12_tpe = RAST.__default.MaybePlaceboType(_12_tpe); } readIdents = Dafny.Set>.FromElements(); - newEnv = (env).AddAssigned(_14_varName, _13_tpe); + newEnv = (env).AddAssigned(_13_varName, _12_tpe); } else { - RAST._IExpr _out5; - Dafny.ISet> _out6; - Defs._IEnvironment _out7; - (this).GenDeclareVarAssign(_10_name, _11_typ, _12_expression, selfIdent, env, out _out5, out _out6, out _out7); - generated = _out5; - readIdents = _out6; - newEnv = _out7; + RAST._IExpr _out2; + Dafny.ISet> _out3; + Defs._IEnvironment _out4; + (this).GenDeclareVarAssign(_9_name, _10_typ, _11_expression, selfIdent, env, out _out2, out _out3, out _out4); + generated = _out2; + readIdents = _out3; + newEnv = _out4; return ; } } @@ -2705,31 +2699,31 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_DeclareVar) { - Dafny.ISequence _16_name = _source0.dtor_name; - DAST._IType _17_typ = _source0.dtor_typ; + Dafny.ISequence _15_name = _source0.dtor_name; + DAST._IType _16_typ = _source0.dtor_typ; Std.Wrappers._IOption maybeValue1 = _source0.dtor_maybeValue; if (maybeValue1.is_None) { { - Dafny.ISequence _18_varName; - _18_varName = Defs.__default.escapeVar(_16_name); - if ((env).IsAssignmentStatusKnown(_18_varName)) { - RAST._IType _19_tpe; - RAST._IType _out8; - _out8 = (this).GenType(_17_typ, Defs.GenTypeContext.@default()); - _19_tpe = _out8; - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _18_varName, Std.Wrappers.Option.create_Some(_19_tpe), Std.Wrappers.Option.create_None()); + Dafny.ISequence _17_varName; + _17_varName = Defs.__default.escapeVar(_15_name); + if ((env).IsAssignmentStatusKnown(_17_varName)) { + RAST._IType _18_tpe; + RAST._IType _out5; + _out5 = (this).GenType(_16_typ, Defs.GenTypeContext.@default()); + _18_tpe = _out5; + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _17_varName, Std.Wrappers.Option.create_Some(_18_tpe), Std.Wrappers.Option.create_None()); readIdents = Dafny.Set>.FromElements(); - newEnv = (env).AddAssigned(_18_varName, _19_tpe); + newEnv = (env).AddAssigned(_17_varName, _18_tpe); } else { - DAST._IStatement _20_newStmt; - _20_newStmt = DAST.Statement.create_DeclareVar(_16_name, _17_typ, Std.Wrappers.Option.create_Some(DAST.Expression.create_InitializationValue(_17_typ))); - RAST._IExpr _out9; - Dafny.ISet> _out10; - Defs._IEnvironment _out11; - (this).GenStmt(_20_newStmt, selfIdent, env, isLast, earlyReturn, out _out9, out _out10, out _out11); - generated = _out9; - readIdents = _out10; - newEnv = _out11; + DAST._IStatement _19_newStmt; + _19_newStmt = DAST.Statement.create_DeclareVar(_15_name, _16_typ, Std.Wrappers.Option.create_Some(DAST.Expression.create_InitializationValue(_16_typ))); + RAST._IExpr _out6; + Dafny.ISet> _out7; + Defs._IEnvironment _out8; + (this).GenStmt(_19_newStmt, selfIdent, env, isLast, earlyReturn, out _out6, out _out7, out _out8); + generated = _out6; + readIdents = _out7; + newEnv = _out8; } } goto after_match0; @@ -2738,124 +2732,124 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_Assign) { - DAST._IAssignLhs _21_lhs = _source0.dtor_lhs; - DAST._IExpression _22_expression = _source0.dtor_value; + DAST._IAssignLhs _20_lhs = _source0.dtor_lhs; + DAST._IExpression _21_expression = _source0.dtor_value; { - RAST._IExpr _23_exprGen; - Defs._IOwnership _24___v39; - Dafny.ISet> _25_exprIdents; - RAST._IExpr _out12; - Defs._IOwnership _out13; - Dafny.ISet> _out14; - (this).GenExpr(_22_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out12, out _out13, out _out14); - _23_exprGen = _out12; - _24___v39 = _out13; - _25_exprIdents = _out14; - if ((_21_lhs).is_Ident) { - Dafny.ISequence _26_rustId; - _26_rustId = Defs.__default.escapeVar((_21_lhs).dtor_ident); - Std.Wrappers._IOption _27_tpe; - _27_tpe = (env).GetType(_26_rustId); - if (((_27_tpe).is_Some) && ((((_27_tpe).dtor_value).ExtractMaybePlacebo()).is_Some)) { - _23_exprGen = RAST.__default.MaybePlacebo(_23_exprGen); + RAST._IExpr _22_exprGen; + Defs._IOwnership _23___v37; + Dafny.ISet> _24_exprIdents; + RAST._IExpr _out9; + Defs._IOwnership _out10; + Dafny.ISet> _out11; + (this).GenExpr(_21_expression, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out9, out _out10, out _out11); + _22_exprGen = _out9; + _23___v37 = _out10; + _24_exprIdents = _out11; + if ((_20_lhs).is_Ident) { + Dafny.ISequence _25_rustId; + _25_rustId = Defs.__default.escapeVar((_20_lhs).dtor_ident); + Std.Wrappers._IOption _26_tpe; + _26_tpe = (env).GetType(_25_rustId); + if (((_26_tpe).is_Some) && ((((_26_tpe).dtor_value).ExtractMaybePlacebo()).is_Some)) { + _22_exprGen = RAST.__default.MaybePlacebo(_22_exprGen); } } - if (((_21_lhs).is_Index) && (((_21_lhs).dtor_expr).is_Ident)) { - Dafny.ISequence _28_rustId; - _28_rustId = Defs.__default.escapeVar(((_21_lhs).dtor_expr).dtor_name); - Std.Wrappers._IOption _29_tpe; - _29_tpe = (env).GetType(_28_rustId); - if (((_29_tpe).is_Some) && ((((_29_tpe).dtor_value).ExtractMaybeUninitArrayElement()).is_Some)) { - _23_exprGen = RAST.__default.MaybeUninitNew(_23_exprGen); + if (((_20_lhs).is_Index) && (((_20_lhs).dtor_expr).is_Ident)) { + Dafny.ISequence _27_rustId; + _27_rustId = Defs.__default.escapeVar(((_20_lhs).dtor_expr).dtor_name); + Std.Wrappers._IOption _28_tpe; + _28_tpe = (env).GetType(_27_rustId); + if (((_28_tpe).is_Some) && ((((_28_tpe).dtor_value).ExtractMaybeUninitArrayElement()).is_Some)) { + _22_exprGen = RAST.__default.MaybeUninitNew(_22_exprGen); } } - RAST._IExpr _30_lhsGen; - bool _31_needsIIFE; - Dafny.ISet> _32_recIdents; - Defs._IEnvironment _33_resEnv; - RAST._IExpr _out15; - bool _out16; - Dafny.ISet> _out17; - Defs._IEnvironment _out18; - (this).GenAssignLhs(_21_lhs, _23_exprGen, selfIdent, env, out _out15, out _out16, out _out17, out _out18); - _30_lhsGen = _out15; - _31_needsIIFE = _out16; - _32_recIdents = _out17; - _33_resEnv = _out18; - generated = _30_lhsGen; - newEnv = _33_resEnv; - if (_31_needsIIFE) { + RAST._IExpr _29_lhsGen; + bool _30_needsIIFE; + Dafny.ISet> _31_recIdents; + Defs._IEnvironment _32_resEnv; + RAST._IExpr _out12; + bool _out13; + Dafny.ISet> _out14; + Defs._IEnvironment _out15; + (this).GenAssignLhs(_20_lhs, _22_exprGen, selfIdent, env, out _out12, out _out13, out _out14, out _out15); + _29_lhsGen = _out12; + _30_needsIIFE = _out13; + _31_recIdents = _out14; + _32_resEnv = _out15; + generated = _29_lhsGen; + newEnv = _32_resEnv; + if (_30_needsIIFE) { generated = RAST.Expr.create_Block(generated); } - readIdents = Dafny.Set>.Union(_32_recIdents, _25_exprIdents); + readIdents = Dafny.Set>.Union(_31_recIdents, _24_exprIdents); } goto after_match0; } } { if (_source0.is_If) { - DAST._IExpression _34_cond = _source0.dtor_cond; - Dafny.ISequence _35_thnDafny = _source0.dtor_thn; - Dafny.ISequence _36_elsDafny = _source0.dtor_els; + DAST._IExpression _33_cond = _source0.dtor_cond; + Dafny.ISequence _34_thnDafny = _source0.dtor_thn; + Dafny.ISequence _35_elsDafny = _source0.dtor_els; { - RAST._IExpr _37_cond; - Defs._IOwnership _38___v40; - Dafny.ISet> _39_recIdents; + RAST._IExpr _36_cond; + Defs._IOwnership _37___v38; + Dafny.ISet> _38_recIdents; + RAST._IExpr _out16; + Defs._IOwnership _out17; + Dafny.ISet> _out18; + (this).GenExpr(_33_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); + _36_cond = _out16; + _37___v38 = _out17; + _38_recIdents = _out18; + Dafny.ISequence _39_condString; + _39_condString = (_36_cond)._ToString(Defs.__default.IND); + readIdents = _38_recIdents; + RAST._IExpr _40_thn; + Dafny.ISet> _41_thnIdents; + Defs._IEnvironment _42_thnEnv; RAST._IExpr _out19; - Defs._IOwnership _out20; - Dafny.ISet> _out21; - (this).GenExpr(_34_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out19, out _out20, out _out21); - _37_cond = _out19; - _38___v40 = _out20; - _39_recIdents = _out21; - Dafny.ISequence _40_condString; - _40_condString = (_37_cond)._ToString(Defs.__default.IND); - readIdents = _39_recIdents; - RAST._IExpr _41_thn; - Dafny.ISet> _42_thnIdents; - Defs._IEnvironment _43_thnEnv; + Dafny.ISet> _out20; + Defs._IEnvironment _out21; + (this).GenStmts(_34_thnDafny, selfIdent, env, isLast, earlyReturn, out _out19, out _out20, out _out21); + _40_thn = _out19; + _41_thnIdents = _out20; + _42_thnEnv = _out21; + readIdents = Dafny.Set>.Union(readIdents, _41_thnIdents); + RAST._IExpr _43_els; + Dafny.ISet> _44_elsIdents; + Defs._IEnvironment _45_elsEnv; RAST._IExpr _out22; Dafny.ISet> _out23; Defs._IEnvironment _out24; - (this).GenStmts(_35_thnDafny, selfIdent, env, isLast, earlyReturn, out _out22, out _out23, out _out24); - _41_thn = _out22; - _42_thnIdents = _out23; - _43_thnEnv = _out24; - readIdents = Dafny.Set>.Union(readIdents, _42_thnIdents); - RAST._IExpr _44_els; - Dafny.ISet> _45_elsIdents; - Defs._IEnvironment _46_elsEnv; - RAST._IExpr _out25; - Dafny.ISet> _out26; - Defs._IEnvironment _out27; - (this).GenStmts(_36_elsDafny, selfIdent, env, isLast, earlyReturn, out _out25, out _out26, out _out27); - _44_els = _out25; - _45_elsIdents = _out26; - _46_elsEnv = _out27; - readIdents = Dafny.Set>.Union(readIdents, _45_elsIdents); - newEnv = env; - generated = RAST.Expr.create_IfExpr(_37_cond, _41_thn, _44_els); + (this).GenStmts(_35_elsDafny, selfIdent, env, isLast, earlyReturn, out _out22, out _out23, out _out24); + _43_els = _out22; + _44_elsIdents = _out23; + _45_elsEnv = _out24; + readIdents = Dafny.Set>.Union(readIdents, _44_elsIdents); + newEnv = (env).Join(_42_thnEnv, _45_elsEnv); + generated = RAST.Expr.create_IfExpr(_36_cond, _40_thn, _43_els); } goto after_match0; } } { if (_source0.is_Labeled) { - Dafny.ISequence _47_lbl = _source0.dtor_lbl; - Dafny.ISequence _48_body = _source0.dtor_body; + Dafny.ISequence _46_lbl = _source0.dtor_lbl; + Dafny.ISequence _47_body = _source0.dtor_body; { - RAST._IExpr _49_body; - Dafny.ISet> _50_bodyIdents; - Defs._IEnvironment _51_env2; - RAST._IExpr _out28; - Dafny.ISet> _out29; - Defs._IEnvironment _out30; - (this).GenStmts(_48_body, selfIdent, env, isLast, earlyReturn, out _out28, out _out29, out _out30); - _49_body = _out28; - _50_bodyIdents = _out29; - _51_env2 = _out30; - readIdents = _50_bodyIdents; - generated = RAST.Expr.create_Labelled(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _47_lbl), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), RAST.Expr.create_StmtExpr(_49_body, RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())))); + RAST._IExpr _48_body; + Dafny.ISet> _49_bodyIdents; + Defs._IEnvironment _50_env2; + RAST._IExpr _out25; + Dafny.ISet> _out26; + Defs._IEnvironment _out27; + (this).GenStmts(_47_body, selfIdent, env, isLast, earlyReturn, out _out25, out _out26, out _out27); + _48_body = _out25; + _49_bodyIdents = _out26; + _50_env2 = _out27; + readIdents = _49_bodyIdents; + generated = RAST.Expr.create_Labelled(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _46_lbl), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), RAST.Expr.create_StmtExpr(_48_body, RAST.Expr.create_Break(Std.Wrappers.Option>.create_None())))); newEnv = env; } goto after_match0; @@ -2863,91 +2857,91 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_While) { - DAST._IExpression _52_cond = _source0.dtor_cond; - Dafny.ISequence _53_body = _source0.dtor_body; + DAST._IExpression _51_cond = _source0.dtor_cond; + Dafny.ISequence _52_body = _source0.dtor_body; { - RAST._IExpr _54_cond; - Defs._IOwnership _55___v41; - Dafny.ISet> _56_recIdents; + RAST._IExpr _53_cond; + Defs._IOwnership _54___v39; + Dafny.ISet> _55_recIdents; + RAST._IExpr _out28; + Defs._IOwnership _out29; + Dafny.ISet> _out30; + (this).GenExpr(_51_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out28, out _out29, out _out30); + _53_cond = _out28; + _54___v39 = _out29; + _55_recIdents = _out30; + readIdents = _55_recIdents; + RAST._IExpr _56_bodyExpr; + Dafny.ISet> _57_bodyIdents; + Defs._IEnvironment _58_bodyEnv; RAST._IExpr _out31; - Defs._IOwnership _out32; - Dafny.ISet> _out33; - (this).GenExpr(_52_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out31, out _out32, out _out33); - _54_cond = _out31; - _55___v41 = _out32; - _56_recIdents = _out33; - readIdents = _56_recIdents; - RAST._IExpr _57_bodyExpr; - Dafny.ISet> _58_bodyIdents; - Defs._IEnvironment _59_bodyEnv; - RAST._IExpr _out34; - Dafny.ISet> _out35; - Defs._IEnvironment _out36; - (this).GenStmts(_53_body, selfIdent, env, false, earlyReturn, out _out34, out _out35, out _out36); - _57_bodyExpr = _out34; - _58_bodyIdents = _out35; - _59_bodyEnv = _out36; + Dafny.ISet> _out32; + Defs._IEnvironment _out33; + (this).GenStmts(_52_body, selfIdent, env, false, earlyReturn, out _out31, out _out32, out _out33); + _56_bodyExpr = _out31; + _57_bodyIdents = _out32; + _58_bodyEnv = _out33; newEnv = env; - readIdents = Dafny.Set>.Union(readIdents, _58_bodyIdents); - generated = RAST.Expr.create_Loop(Std.Wrappers.Option.create_Some(_54_cond), _57_bodyExpr); + readIdents = Dafny.Set>.Union(readIdents, _57_bodyIdents); + generated = RAST.Expr.create_Loop(Std.Wrappers.Option.create_Some(_53_cond), _56_bodyExpr); } goto after_match0; } } { if (_source0.is_Foreach) { - Dafny.ISequence _60_boundName = _source0.dtor_boundName; - DAST._IType _61_boundType = _source0.dtor_boundType; - DAST._IExpression _62_overExpr = _source0.dtor_over; - Dafny.ISequence _63_body = _source0.dtor_body; + Dafny.ISequence _59_boundName = _source0.dtor_boundName; + DAST._IType _60_boundType = _source0.dtor_boundType; + DAST._IExpression _61_overExpr = _source0.dtor_over; + Dafny.ISequence _62_body = _source0.dtor_body; { - RAST._IExpr _64_over; - Defs._IOwnership _65___v42; - Dafny.ISet> _66_recIdents; - RAST._IExpr _out37; - Defs._IOwnership _out38; + RAST._IExpr _63_over; + Defs._IOwnership _64___v40; + Dafny.ISet> _65_recIdents; + RAST._IExpr _out34; + Defs._IOwnership _out35; + Dafny.ISet> _out36; + (this).GenExpr(_61_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out34, out _out35, out _out36); + _63_over = _out34; + _64___v40 = _out35; + _65_recIdents = _out36; + if (((_61_overExpr).is_MapBoundedPool) || ((_61_overExpr).is_SetBoundedPool)) { + _63_over = ((_63_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); + } + RAST._IType _66_boundTpe; + RAST._IType _out37; + _out37 = (this).GenType(_60_boundType, Defs.GenTypeContext.@default()); + _66_boundTpe = _out37; + readIdents = _65_recIdents; + Dafny.ISequence _67_boundRName; + _67_boundRName = Defs.__default.escapeVar(_59_boundName); + RAST._IExpr _68_bodyExpr; + Dafny.ISet> _69_bodyIdents; + Defs._IEnvironment _70_bodyEnv; + RAST._IExpr _out38; Dafny.ISet> _out39; - (this).GenExpr(_62_overExpr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out37, out _out38, out _out39); - _64_over = _out37; - _65___v42 = _out38; - _66_recIdents = _out39; - if (((_62_overExpr).is_MapBoundedPool) || ((_62_overExpr).is_SetBoundedPool)) { - _64_over = ((_64_over).Sel(Dafny.Sequence.UnicodeFromString("cloned"))).Apply0(); - } - RAST._IType _67_boundTpe; - RAST._IType _out40; - _out40 = (this).GenType(_61_boundType, Defs.GenTypeContext.@default()); - _67_boundTpe = _out40; - readIdents = _66_recIdents; - Dafny.ISequence _68_boundRName; - _68_boundRName = Defs.__default.escapeVar(_60_boundName); - RAST._IExpr _69_bodyExpr; - Dafny.ISet> _70_bodyIdents; - Defs._IEnvironment _71_bodyEnv; - RAST._IExpr _out41; - Dafny.ISet> _out42; - Defs._IEnvironment _out43; - (this).GenStmts(_63_body, selfIdent, (env).AddAssigned(_68_boundRName, _67_boundTpe), false, earlyReturn, out _out41, out _out42, out _out43); - _69_bodyExpr = _out41; - _70_bodyIdents = _out42; - _71_bodyEnv = _out43; - readIdents = Dafny.Set>.Difference(Dafny.Set>.Union(readIdents, _70_bodyIdents), Dafny.Set>.FromElements(_68_boundRName)); + Defs._IEnvironment _out40; + (this).GenStmts(_62_body, selfIdent, (env).AddAssigned(_67_boundRName, _66_boundTpe), false, earlyReturn, out _out38, out _out39, out _out40); + _68_bodyExpr = _out38; + _69_bodyIdents = _out39; + _70_bodyEnv = _out40; + readIdents = Dafny.Set>.Difference(Dafny.Set>.Union(readIdents, _69_bodyIdents), Dafny.Set>.FromElements(_67_boundRName)); newEnv = env; - generated = RAST.Expr.create_For(_68_boundRName, _64_over, _69_bodyExpr); + generated = RAST.Expr.create_For(_67_boundRName, _63_over, _68_bodyExpr); } goto after_match0; } } { if (_source0.is_Break) { - Std.Wrappers._IOption> _72_toLabel = _source0.dtor_toLabel; + Std.Wrappers._IOption> _71_toLabel = _source0.dtor_toLabel; { - Std.Wrappers._IOption> _source1 = _72_toLabel; + Std.Wrappers._IOption> _source1 = _71_toLabel; { if (_source1.is_Some) { - Dafny.ISequence _73_lbl = _source1.dtor_value; + Dafny.ISequence _72_lbl = _source1.dtor_value; { - generated = RAST.Expr.create_Break(Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _73_lbl))); + generated = RAST.Expr.create_Break(Std.Wrappers.Option>.create_Some(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("label_"), _72_lbl))); } goto after_match1; } @@ -2966,72 +2960,72 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_TailRecursive) { - Dafny.ISequence _74_body = _source0.dtor_body; + Dafny.ISequence _73_body = _source0.dtor_body; { generated = (this).InitEmptyExpr(); - Defs._IEnvironment _75_oldEnv; - _75_oldEnv = env; + Defs._IEnvironment _74_oldEnv; + _74_oldEnv = env; if (!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) { - RAST._IExpr _76_selfClone; - Defs._IOwnership _77___v43; - Dafny.ISet> _78___v44; - RAST._IExpr _out44; - Defs._IOwnership _out45; - Dafny.ISet> _out46; - (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out44, out _out45, out _out46); - _76_selfClone = _out44; - _77___v43 = _out45; - _78___v44 = _out46; - generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_76_selfClone))); - if (((_75_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { - _75_oldEnv = (_75_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); + RAST._IExpr _75_selfClone; + Defs._IOwnership _76___v41; + Dafny.ISet> _77___v42; + RAST._IExpr _out41; + Defs._IOwnership _out42; + Dafny.ISet> _out43; + (this).GenIdent((selfIdent).dtor_rSelfName, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); + _75_selfClone = _out41; + _76___v41 = _out42; + _77___v42 = _out43; + generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_75_selfClone))); + if (((_74_oldEnv).dtor_names).Contains((selfIdent).dtor_rSelfName)) { + _74_oldEnv = (_74_oldEnv).RemoveAssigned((selfIdent).dtor_rSelfName); } } - RAST._IExpr _79_loopBegin; - _79_loopBegin = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); + RAST._IExpr _78_loopBegin; + _78_loopBegin = RAST.Expr.create_RawExpr(Dafny.Sequence.UnicodeFromString("")); newEnv = env; - BigInteger _hi1 = new BigInteger(((_75_oldEnv).dtor_names).Count); - for (BigInteger _80_paramI = BigInteger.Zero; _80_paramI < _hi1; _80_paramI++) { - Dafny.ISequence _81_param; - _81_param = ((_75_oldEnv).dtor_names).Select(_80_paramI); - if ((_81_param).Equals(Dafny.Sequence.UnicodeFromString("_accumulator"))) { - goto continue_4_0; + BigInteger _hi1 = new BigInteger(((_74_oldEnv).dtor_names).Count); + for (BigInteger _79_paramI = BigInteger.Zero; _79_paramI < _hi1; _79_paramI++) { + Dafny.ISequence _80_param; + _80_param = ((_74_oldEnv).dtor_names).Select(_79_paramI); + if ((_80_param).Equals(Dafny.Sequence.UnicodeFromString("_accumulator"))) { + goto continue_5; } - RAST._IExpr _82_paramInit; - Defs._IOwnership _83___v45; - Dafny.ISet> _84___v46; - RAST._IExpr _out47; - Defs._IOwnership _out48; - Dafny.ISet> _out49; - (this).GenIdent(_81_param, selfIdent, _75_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out47, out _out48, out _out49); - _82_paramInit = _out47; - _83___v45 = _out48; - _84___v46 = _out49; - Dafny.ISequence _85_recVar; - _85_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_80_paramI)); - generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _85_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_82_paramInit))); - if (((_75_oldEnv).dtor_types).Contains(_81_param)) { - RAST._IType _86_declaredType; - _86_declaredType = (Dafny.Map, RAST._IType>.Select((_75_oldEnv).dtor_types,_81_param)).ToOwned(); - newEnv = (newEnv).AddAssigned(_81_param, _86_declaredType); - newEnv = (newEnv).AddAssigned(_85_recVar, _86_declaredType); + RAST._IExpr _81_paramInit; + Defs._IOwnership _82___v43; + Dafny.ISet> _83___v44; + RAST._IExpr _out44; + Defs._IOwnership _out45; + Dafny.ISet> _out46; + (this).GenIdent(_80_param, selfIdent, _74_oldEnv, Defs.Ownership.create_OwnershipOwned(), out _out44, out _out45, out _out46); + _81_paramInit = _out44; + _82___v43 = _out45; + _83___v44 = _out46; + Dafny.ISequence _84_recVar; + _84_recVar = Dafny.Sequence.Concat(Defs.__default.TailRecursionPrefix, Std.Strings.__default.OfNat(_79_paramI)); + generated = (generated).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), _84_recVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_81_paramInit))); + if (((_74_oldEnv).dtor_types).Contains(_80_param)) { + RAST._IType _85_declaredType; + _85_declaredType = (Dafny.Map, RAST._IType>.Select((_74_oldEnv).dtor_types,_80_param)).ToOwned(); + newEnv = (newEnv).AddAssigned(_80_param, _85_declaredType); + newEnv = (newEnv).AddAssigned(_84_recVar, _85_declaredType); } - _79_loopBegin = (_79_loopBegin).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _81_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_85_recVar)))); - continue_4_0: ; - } - after_4_0: ; - RAST._IExpr _87_bodyExpr; - Dafny.ISet> _88_bodyIdents; - Defs._IEnvironment _89_bodyEnv; - RAST._IExpr _out50; - Dafny.ISet> _out51; - Defs._IEnvironment _out52; - (this).GenStmts(_74_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), newEnv, false, earlyReturn, out _out50, out _out51, out _out52); - _87_bodyExpr = _out50; - _88_bodyIdents = _out51; - _89_bodyEnv = _out52; - readIdents = _88_bodyIdents; - generated = (generated).Then(RAST.Expr.create_Labelled(Dafny.Sequence.UnicodeFromString("TAIL_CALL_START"), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), (_79_loopBegin).Then(_87_bodyExpr)))); + _78_loopBegin = (_78_loopBegin).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _80_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_84_recVar)))); + continue_5: ; + } + after_5: ; + RAST._IExpr _86_bodyExpr; + Dafny.ISet> _87_bodyIdents; + Defs._IEnvironment _88_bodyEnv; + RAST._IExpr _out47; + Dafny.ISet> _out48; + Defs._IEnvironment _out49; + (this).GenStmts(_73_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), newEnv, false, earlyReturn, out _out47, out _out48, out _out49); + _86_bodyExpr = _out47; + _87_bodyIdents = _out48; + _88_bodyEnv = _out49; + readIdents = _87_bodyIdents; + generated = (generated).Then(RAST.Expr.create_Labelled(Dafny.Sequence.UnicodeFromString("TAIL_CALL_START"), RAST.Expr.create_Loop(Std.Wrappers.Option.create_None(), (_78_loopBegin).Then(_86_bodyExpr)))); } goto after_match0; } @@ -3048,44 +3042,44 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_Call) { - DAST._IExpression _90_on = _source0.dtor_on; - DAST._ICallName _91_name = _source0.dtor_callName; - Dafny.ISequence _92_typeArgs = _source0.dtor_typeArgs; - Dafny.ISequence _93_args = _source0.dtor_args; - Std.Wrappers._IOption>> _94_maybeOutVars = _source0.dtor_outs; + DAST._IExpression _89_on = _source0.dtor_on; + DAST._ICallName _90_name = _source0.dtor_callName; + Dafny.ISequence _91_typeArgs = _source0.dtor_typeArgs; + Dafny.ISequence _92_args = _source0.dtor_args; + Std.Wrappers._IOption>> _93_maybeOutVars = _source0.dtor_outs; { - RAST._IExpr _out53; - Dafny.ISet> _out54; - (this).GenOwnedCallPart(_90_on, selfIdent, _91_name, _92_typeArgs, _93_args, env, out _out53, out _out54); - generated = _out53; - readIdents = _out54; + RAST._IExpr _out50; + Dafny.ISet> _out51; + (this).GenOwnedCallPart(_89_on, selfIdent, _90_name, _91_typeArgs, _92_args, env, out _out50, out _out51); + generated = _out50; + readIdents = _out51; newEnv = env; - if (((_94_maybeOutVars).is_Some) && ((new BigInteger(((_94_maybeOutVars).dtor_value).Count)) == (BigInteger.One))) { - Dafny.ISequence _95_outVar; - _95_outVar = Defs.__default.escapeVar(((_94_maybeOutVars).dtor_value).Select(BigInteger.Zero)); - if ((env).IsMaybePlacebo(_95_outVar)) { + if (((_93_maybeOutVars).is_Some) && ((new BigInteger(((_93_maybeOutVars).dtor_value).Count)) == (BigInteger.One))) { + Dafny.ISequence _94_outVar; + _94_outVar = Defs.__default.escapeVar(((_93_maybeOutVars).dtor_value).Select(BigInteger.Zero)); + if ((env).IsMaybePlacebo(_94_outVar)) { generated = RAST.__default.MaybePlacebo(generated); } - generated = RAST.__default.AssignVar(_95_outVar, generated); - } else if (((_94_maybeOutVars).is_None) || ((new BigInteger(((_94_maybeOutVars).dtor_value).Count)).Sign == 0)) { + generated = RAST.__default.AssignVar(_94_outVar, generated); + } else if (((_93_maybeOutVars).is_None) || ((new BigInteger(((_93_maybeOutVars).dtor_value).Count)).Sign == 0)) { } else { - Dafny.ISequence _96_tmpVar; - _96_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); - RAST._IExpr _97_tmpId; - _97_tmpId = RAST.Expr.create_Identifier(_96_tmpVar); - generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _96_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); - Dafny.ISequence> _98_outVars; - _98_outVars = (_94_maybeOutVars).dtor_value; - BigInteger _hi2 = new BigInteger((_98_outVars).Count); - for (BigInteger _99_outI = BigInteger.Zero; _99_outI < _hi2; _99_outI++) { - Dafny.ISequence _100_outVar; - _100_outVar = Defs.__default.escapeVar((_98_outVars).Select(_99_outI)); - RAST._IExpr _101_rhs; - _101_rhs = (_97_tmpId).Sel(Std.Strings.__default.OfNat(_99_outI)); - if ((env).IsMaybePlacebo(_100_outVar)) { - _101_rhs = RAST.__default.MaybePlacebo(_101_rhs); + Dafny.ISequence _95_tmpVar; + _95_tmpVar = Dafny.Sequence.UnicodeFromString("_x"); + RAST._IExpr _96_tmpId; + _96_tmpId = RAST.Expr.create_Identifier(_95_tmpVar); + generated = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _95_tmpVar, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(generated)); + Dafny.ISequence> _97_outVars; + _97_outVars = (_93_maybeOutVars).dtor_value; + BigInteger _hi2 = new BigInteger((_97_outVars).Count); + for (BigInteger _98_outI = BigInteger.Zero; _98_outI < _hi2; _98_outI++) { + Dafny.ISequence _99_outVar; + _99_outVar = Defs.__default.escapeVar((_97_outVars).Select(_98_outI)); + RAST._IExpr _100_rhs; + _100_rhs = (_96_tmpId).Sel(Std.Strings.__default.OfNat(_98_outI)); + if ((env).IsMaybePlacebo(_99_outVar)) { + _100_rhs = RAST.__default.MaybePlacebo(_100_rhs); } - generated = (generated).Then(RAST.__default.AssignVar(_100_outVar, _101_rhs)); + generated = (generated).Then(RAST.__default.AssignVar(_99_outVar, _100_rhs)); } } newEnv = env; @@ -3095,23 +3089,23 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } { if (_source0.is_Return) { - DAST._IExpression _102_exprDafny = _source0.dtor_expr; + DAST._IExpression _101_exprDafny = _source0.dtor_expr; { - RAST._IExpr _103_expr; - Defs._IOwnership _104___v47; - Dafny.ISet> _105_recIdents; - RAST._IExpr _out55; - Defs._IOwnership _out56; - Dafny.ISet> _out57; - (this).GenExpr(_102_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out55, out _out56, out _out57); - _103_expr = _out55; - _104___v47 = _out56; - _105_recIdents = _out57; - readIdents = _105_recIdents; + RAST._IExpr _102_expr; + Defs._IOwnership _103___v45; + Dafny.ISet> _104_recIdents; + RAST._IExpr _out52; + Defs._IOwnership _out53; + Dafny.ISet> _out54; + (this).GenExpr(_101_exprDafny, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out52, out _out53, out _out54); + _102_expr = _out52; + _103___v45 = _out53; + _104_recIdents = _out54; + readIdents = _104_recIdents; if (isLast) { - generated = _103_expr; + generated = _102_expr; } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_103_expr)); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(_102_expr)); } newEnv = env; } @@ -3129,27 +3123,27 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } } { - Dafny.ISequence> _106_rustIdents = _source2.dtor_value; - Dafny.ISequence _107_tupleArgs; - _107_tupleArgs = Dafny.Sequence.FromElements(); - BigInteger _hi3 = new BigInteger((_106_rustIdents).Count); - for (BigInteger _108_i = BigInteger.Zero; _108_i < _hi3; _108_i++) { - RAST._IExpr _109_rIdent; - Defs._IOwnership _110___v48; - Dafny.ISet> _111___v49; - RAST._IExpr _out58; - Defs._IOwnership _out59; - Dafny.ISet> _out60; - (this).GenIdent((_106_rustIdents).Select(_108_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out58, out _out59, out _out60); - _109_rIdent = _out58; - _110___v48 = _out59; - _111___v49 = _out60; - _107_tupleArgs = Dafny.Sequence.Concat(_107_tupleArgs, Dafny.Sequence.FromElements(_109_rIdent)); + Dafny.ISequence> _105_rustIdents = _source2.dtor_value; + Dafny.ISequence _106_tupleArgs; + _106_tupleArgs = Dafny.Sequence.FromElements(); + BigInteger _hi3 = new BigInteger((_105_rustIdents).Count); + for (BigInteger _107_i = BigInteger.Zero; _107_i < _hi3; _107_i++) { + RAST._IExpr _108_rIdent; + Defs._IOwnership _109___v46; + Dafny.ISet> _110___v47; + RAST._IExpr _out55; + Defs._IOwnership _out56; + Dafny.ISet> _out57; + (this).GenIdent((_105_rustIdents).Select(_107_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out55, out _out56, out _out57); + _108_rIdent = _out55; + _109___v46 = _out56; + _110___v47 = _out57; + _106_tupleArgs = Dafny.Sequence.Concat(_106_tupleArgs, Dafny.Sequence.FromElements(_108_rIdent)); } - if ((new BigInteger((_107_tupleArgs).Count)) == (BigInteger.One)) { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_107_tupleArgs).Select(BigInteger.Zero))); + if ((new BigInteger((_106_tupleArgs).Count)) == (BigInteger.One)) { + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some((_106_tupleArgs).Select(BigInteger.Zero))); } else { - generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_107_tupleArgs))); + generated = RAST.Expr.create_Return(Std.Wrappers.Option.create_Some(RAST.Expr.create_Tuple(_106_tupleArgs))); } } after_match2: ; @@ -3170,20 +3164,20 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv } } { - DAST._IExpression _112_e = _source0.dtor_Print_a0; + DAST._IExpression _111_e = _source0.dtor_Print_a0; { - RAST._IExpr _113_printedExpr; - Defs._IOwnership _114_recOwnership; - Dafny.ISet> _115_recIdents; - RAST._IExpr _out61; - Defs._IOwnership _out62; - Dafny.ISet> _out63; - (this).GenExpr(_112_e, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out61, out _out62, out _out63); - _113_printedExpr = _out61; - _114_recOwnership = _out62; - _115_recIdents = _out63; - generated = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("print!"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("{}"), false, false), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrintWrapper"))).AsExpr()).Apply1(_113_printedExpr))); - readIdents = _115_recIdents; + RAST._IExpr _112_printedExpr; + Defs._IOwnership _113_recOwnership; + Dafny.ISet> _114_recIdents; + RAST._IExpr _out58; + Defs._IOwnership _out59; + Dafny.ISet> _out60; + (this).GenExpr(_111_e, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out58, out _out59, out _out60); + _112_printedExpr = _out58; + _113_recOwnership = _out59; + _114_recIdents = _out60; + generated = (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("print!"))).Apply(Dafny.Sequence.FromElements(RAST.Expr.create_LiteralString(Dafny.Sequence.UnicodeFromString("{}"), false, false), (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("DafnyPrintWrapper"))).AsExpr()).Apply1(_112_printedExpr))); + readIdents = _114_recIdents; newEnv = env; } } @@ -3539,24 +3533,24 @@ public void GenExprBinary(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._ _10_expectedRightOwnership = Defs.Ownership.create_OwnershipOwned(); } RAST._IExpr _11_left; - Defs._IOwnership _12___v50; + Defs._IOwnership _12___v48; Dafny.ISet> _13_recIdentsL; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(_4_lExpr, selfIdent, env, _9_expectedLeftOwnership, out _out0, out _out1, out _out2); _11_left = _out0; - _12___v50 = _out1; + _12___v48 = _out1; _13_recIdentsL = _out2; RAST._IExpr _14_right; - Defs._IOwnership _15___v51; + Defs._IOwnership _15___v49; Dafny.ISet> _16_recIdentsR; RAST._IExpr _out3; Defs._IOwnership _out4; Dafny.ISet> _out5; (this).GenExpr(_5_rExpr, selfIdent, env, _10_expectedRightOwnership, out _out3, out _out4, out _out5); _14_right = _out3; - _15___v51 = _out4; + _15___v49 = _out4; _16_recIdentsR = _out5; DAST._IBinOp _source0 = _0_op; { @@ -4688,14 +4682,14 @@ public void GenArgs(Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequ } } RAST._IExpr _4_argExpr; - Defs._IOwnership _5___v64; + Defs._IOwnership _5___v62; Dafny.ISet> _6_argIdents; RAST._IExpr _out1; Defs._IOwnership _out2; Dafny.ISet> _out3; (this).GenExpr((args).Select(_1_i), selfIdent, env, _2_argOwnership, out _out1, out _out2, out _out3); _4_argExpr = _out1; - _5___v64 = _out2; + _5___v62 = _out2; _6_argIdents = _out3; argExprs = Dafny.Sequence.Concat(argExprs, Dafny.Sequence.FromElements(_4_argExpr)); readIdents = Dafny.Set>.Union(readIdents, _6_argIdents); @@ -4893,14 +4887,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi1 = new BigInteger((_9_values).Count); for (BigInteger _11_i = BigInteger.Zero; _11_i < _hi1; _11_i++) { RAST._IExpr _12_recursiveGen; - Defs._IOwnership _13___v74; + Defs._IOwnership _13___v72; Dafny.ISet> _14_recIdents; RAST._IExpr _out16; Defs._IOwnership _out17; Dafny.ISet> _out18; (this).GenExpr((_9_values).Select(_11_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out16, out _out17, out _out18); _12_recursiveGen = _out16; - _13___v74 = _out17; + _13___v72 = _out17; _14_recIdents = _out18; _10_exprs = Dafny.Sequence.Concat(_10_exprs, Dafny.Sequence.FromElements(_12_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _14_recIdents); @@ -4949,14 +4943,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi3 = new BigInteger((_17_args).Count); for (BigInteger _22_i = BigInteger.Zero; _22_i < _hi3; _22_i++) { RAST._IExpr _23_recursiveGen; - Defs._IOwnership _24___v75; + Defs._IOwnership _24___v73; Dafny.ISet> _25_recIdents; RAST._IExpr _out23; Defs._IOwnership _out24; Dafny.ISet> _out25; (this).GenExpr((_17_args).Select(_22_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out23, out _out24, out _out25); _23_recursiveGen = _out23; - _24___v75 = _out24; + _24___v73 = _out24; _25_recIdents = _out25; _21_arguments = Dafny.Sequence.Concat(_21_arguments, Dafny.Sequence.FromElements(_23_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _25_recIdents); @@ -4994,14 +4988,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi4 = new BigInteger((_26_dims).Count); for (BigInteger _30_i = BigInteger.Zero; _30_i < _hi4; _30_i++) { RAST._IExpr _31_recursiveGen; - Defs._IOwnership _32___v76; + Defs._IOwnership _32___v74; Dafny.ISet> _33_recIdents; RAST._IExpr _out30; Defs._IOwnership _out31; Dafny.ISet> _out32; (this).GenExpr((_26_dims).Select(_30_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out30, out _out31, out _out32); _31_recursiveGen = _out30; - _32___v76 = _out31; + _32___v74 = _out31; _33_recIdents = _out32; _29_dimExprs = Dafny.Sequence.Concat(_29_dimExprs, Dafny.Sequence.FromElements(RAST.__default.IntoUsize(_31_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _33_recIdents); @@ -5028,14 +5022,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _35_underlying = _source0.dtor_value; { RAST._IExpr _36_recursiveGen; - Defs._IOwnership _37___v77; + Defs._IOwnership _37___v75; Dafny.ISet> _38_recIdents; RAST._IExpr _out35; Defs._IOwnership _out36; Dafny.ISet> _out37; (this).GenExpr(_35_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out35, out _out36, out _out37); _36_recursiveGen = _out35; - _37___v77 = _out36; + _37___v75 = _out36; _38_recIdents = _out37; r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("int!"))).AsExpr()).Apply1(_36_recursiveGen); readIdents = _38_recIdents; @@ -5058,14 +5052,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out40 = (this).GenType(_40_typ, Defs.GenTypeContext.@default()); _41_tpe = _out40; RAST._IExpr _42_recursiveGen; - Defs._IOwnership _43___v78; + Defs._IOwnership _43___v76; Dafny.ISet> _44_recIdents; RAST._IExpr _out41; Defs._IOwnership _out42; Dafny.ISet> _out43; (this).GenExpr(_39_underlying, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out41, out _out42, out _out43); _42_recursiveGen = _out41; - _43___v78 = _out42; + _43___v76 = _out42; _44_recIdents = _out43; readIdents = _44_recIdents; if ((_41_tpe).IsObjectOrPointer()) { @@ -5131,14 +5125,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _58_value = _let_tmp_rhs0.dtor__1; if (_50_isCo) { RAST._IExpr _59_recursiveGen; - Defs._IOwnership _60___v79; + Defs._IOwnership _60___v77; Dafny.ISet> _61_recIdents; RAST._IExpr _out50; Defs._IOwnership _out51; Dafny.ISet> _out52; (this).GenExpr(_58_value, selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out50, out _out51, out _out52); _59_recursiveGen = _out50; - _60___v79 = _out51; + _60___v77 = _out51; _61_recIdents = _out52; readIdents = Dafny.Set>.Union(readIdents, _61_recIdents); RAST._IExpr _62_allReadCloned; @@ -5161,14 +5155,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _64_wasAssigned))); } else { RAST._IExpr _65_recursiveGen; - Defs._IOwnership _66___v80; + Defs._IOwnership _66___v78; Dafny.ISet> _67_recIdents; RAST._IExpr _out53; Defs._IOwnership _out54; Dafny.ISet> _out55; (this).GenExpr(_58_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out53, out _out54, out _out55); _65_recursiveGen = _out53; - _66___v80 = _out54; + _66___v78 = _out54; _67_recIdents = _out55; _55_assignments = Dafny.Sequence.Concat(_55_assignments, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Defs.__default.escapeVar(_57_name), _65_recursiveGen))); readIdents = Dafny.Set>.Union(readIdents, _67_recIdents); @@ -5208,24 +5202,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _69_expr = _source0.dtor_elem; { RAST._IExpr _70_recursiveGen; - Defs._IOwnership _71___v84; + Defs._IOwnership _71___v82; Dafny.ISet> _72_recIdents; RAST._IExpr _out61; Defs._IOwnership _out62; Dafny.ISet> _out63; (this).GenExpr(_69_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out61, out _out62, out _out63); _70_recursiveGen = _out61; - _71___v84 = _out62; + _71___v82 = _out62; _72_recIdents = _out63; RAST._IExpr _73_lengthGen; - Defs._IOwnership _74___v85; + Defs._IOwnership _74___v83; Dafny.ISet> _75_lengthIdents; RAST._IExpr _out64; Defs._IOwnership _out65; Dafny.ISet> _out66; (this).GenExpr(_68_length, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out64, out _out65, out _out66); _73_lengthGen = _out64; - _74___v85 = _out65; + _74___v83 = _out65; _75_lengthIdents = _out66; r = RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Dafny.Sequence.UnicodeFromString("_initializer"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_70_recursiveGen)); RAST._IExpr _76_range; @@ -5264,14 +5258,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _82_args = Dafny.Sequence.FromElements(); while ((_81_i) < (new BigInteger((_78_exprs).Count))) { RAST._IExpr _83_recursiveGen; - Defs._IOwnership _84___v86; + Defs._IOwnership _84___v84; Dafny.ISet> _85_recIdents; RAST._IExpr _out70; Defs._IOwnership _out71; Dafny.ISet> _out72; (this).GenExpr((_78_exprs).Select(_81_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out70, out _out71, out _out72); _83_recursiveGen = _out70; - _84___v86 = _out71; + _84___v84 = _out71; _85_recIdents = _out72; readIdents = Dafny.Set>.Union(readIdents, _85_recIdents); _82_args = Dafny.Sequence.Concat(_82_args, Dafny.Sequence.FromElements(_83_recursiveGen)); @@ -5302,14 +5296,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _88_i = BigInteger.Zero; while ((_88_i) < (new BigInteger((_86_exprs).Count))) { RAST._IExpr _89_recursiveGen; - Defs._IOwnership _90___v87; + Defs._IOwnership _90___v85; Dafny.ISet> _91_recIdents; RAST._IExpr _out75; Defs._IOwnership _out76; Dafny.ISet> _out77; (this).GenExpr((_86_exprs).Select(_88_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out75, out _out76, out _out77); _89_recursiveGen = _out75; - _90___v87 = _out76; + _90___v85 = _out76; _91_recIdents = _out77; _87_generatedValues = Dafny.Sequence.Concat(_87_generatedValues, Dafny.Sequence.FromElements(_89_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _91_recIdents); @@ -5337,14 +5331,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _94_i = BigInteger.Zero; while ((_94_i) < (new BigInteger((_92_exprs).Count))) { RAST._IExpr _95_recursiveGen; - Defs._IOwnership _96___v88; + Defs._IOwnership _96___v86; Dafny.ISet> _97_recIdents; RAST._IExpr _out80; Defs._IOwnership _out81; Dafny.ISet> _out82; (this).GenExpr((_92_exprs).Select(_94_i), selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out80, out _out81, out _out82); _95_recursiveGen = _out80; - _96___v88 = _out81; + _96___v86 = _out81; _97_recIdents = _out82; _93_generatedValues = Dafny.Sequence.Concat(_93_generatedValues, Dafny.Sequence.FromElements(_95_recursiveGen)); readIdents = Dafny.Set>.Union(readIdents, _97_recIdents); @@ -5366,14 +5360,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _98_expr = _source0.dtor_ToMultiset_a0; { RAST._IExpr _99_recursiveGen; - Defs._IOwnership _100___v89; + Defs._IOwnership _100___v87; Dafny.ISet> _101_recIdents; RAST._IExpr _out85; Defs._IOwnership _out86; Dafny.ISet> _out87; (this).GenExpr(_98_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out85, out _out86, out _out87); _99_recursiveGen = _out85; - _100___v89 = _out86; + _100___v87 = _out86; _101_recIdents = _out87; r = ((_99_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("as_dafny_multiset"))).Apply0(); readIdents = _101_recIdents; @@ -5399,24 +5393,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir BigInteger _hi7 = new BigInteger((_102_mapElems).Count); for (BigInteger _106_i = BigInteger.Zero; _106_i < _hi7; _106_i++) { RAST._IExpr _107_recursiveGenKey; - Defs._IOwnership _108___v90; + Defs._IOwnership _108___v88; Dafny.ISet> _109_recIdentsKey; RAST._IExpr _out90; Defs._IOwnership _out91; Dafny.ISet> _out92; (this).GenExpr(((_102_mapElems).Select(_106_i)).dtor__0, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out90, out _out91, out _out92); _107_recursiveGenKey = _out90; - _108___v90 = _out91; + _108___v88 = _out91; _109_recIdentsKey = _out92; RAST._IExpr _110_recursiveGenValue; - Defs._IOwnership _111___v91; + Defs._IOwnership _111___v89; Dafny.ISet> _112_recIdentsValue; RAST._IExpr _out93; Defs._IOwnership _out94; Dafny.ISet> _out95; (this).GenExpr(((_102_mapElems).Select(_106_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out93, out _out94, out _out95); _110_recursiveGenValue = _out93; - _111___v91 = _out94; + _111___v89 = _out94; _112_recIdentsValue = _out95; _105_generatedValues = Dafny.Sequence<_System._ITuple2>.Concat(_105_generatedValues, Dafny.Sequence<_System._ITuple2>.FromElements(_System.Tuple2.create(_107_recursiveGenKey, _110_recursiveGenValue))); readIdents = Dafny.Set>.Union(Dafny.Set>.Union(readIdents, _109_recIdentsKey), _112_recIdentsValue); @@ -5462,14 +5456,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IType _123_exprType = _source0.dtor_exprType; { RAST._IExpr _124_exprR; - Defs._IOwnership _125___v92; + Defs._IOwnership _125___v90; Dafny.ISet> _126_exprIdents; RAST._IExpr _out100; Defs._IOwnership _out101; Dafny.ISet> _out102; (this).GenExpr(_119_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out100, out _out101, out _out102); _124_exprR = _out100; - _125___v92 = _out101; + _125___v90 = _out101; _126_exprIdents = _out102; RAST._IExpr _127_indexR; Defs._IOwnership _128_indexOwnership; @@ -5512,14 +5506,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IType _137_exprType = _source0.dtor_exprType; { RAST._IExpr _138_exprR; - Defs._IOwnership _139___v93; + Defs._IOwnership _139___v91; Dafny.ISet> _140_exprIdents; RAST._IExpr _out111; Defs._IOwnership _out112; Dafny.ISet> _out113; (this).GenExpr(_133_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out111, out _out112, out _out113); _138_exprR = _out111; - _139___v93 = _out112; + _139___v91 = _out112; _140_exprIdents = _out113; RAST._IExpr _141_indexR; Defs._IOwnership _142_indexOwnership; @@ -5600,14 +5594,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _152_f = _source0.dtor_els; { RAST._IExpr _153_cond; - Defs._IOwnership _154___v94; + Defs._IOwnership _154___v92; Dafny.ISet> _155_recIdentsCond; RAST._IExpr _out128; Defs._IOwnership _out129; Dafny.ISet> _out130; (this).GenExpr(_150_cond, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out128, out _out129, out _out130); _153_cond = _out128; - _154___v94 = _out129; + _154___v92 = _out129; _155_recIdentsCond = _out130; RAST._IExpr _156_fExpr; Defs._IOwnership _157_fOwned; @@ -5620,14 +5614,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _157_fOwned = _out132; _158_recIdentsF = _out133; RAST._IExpr _159_tExpr; - Defs._IOwnership _160___v95; + Defs._IOwnership _160___v93; Dafny.ISet> _161_recIdentsT; RAST._IExpr _out134; Defs._IOwnership _out135; Dafny.ISet> _out136; (this).GenExpr(_151_t, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out134, out _out135, out _out136); _159_tExpr = _out134; - _160___v95 = _out135; + _160___v93 = _out135; _161_recIdentsT = _out136; r = RAST.Expr.create_IfExpr(_153_cond, _159_tExpr, _156_fExpr); RAST._IExpr _out137; @@ -5649,14 +5643,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _163_format = _source0.dtor_format1; { RAST._IExpr _164_recursiveGen; - Defs._IOwnership _165___v96; + Defs._IOwnership _165___v94; Dafny.ISet> _166_recIdents; RAST._IExpr _out139; Defs._IOwnership _out140; Dafny.ISet> _out141; (this).GenExpr(_162_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out139, out _out140, out _out141); _164_recursiveGen = _out139; - _165___v96 = _out140; + _165___v94 = _out140; _166_recIdents = _out141; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _164_recursiveGen, _163_format); RAST._IExpr _out142; @@ -5679,14 +5673,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST.Format._IUnaryOpFormat _168_format = _source0.dtor_format1; { RAST._IExpr _169_recursiveGen; - Defs._IOwnership _170___v97; + Defs._IOwnership _170___v95; Dafny.ISet> _171_recIdents; RAST._IExpr _out144; Defs._IOwnership _out145; Dafny.ISet> _out146; (this).GenExpr(_167_e, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out144, out _out145, out _out146); _169_recursiveGen = _out144; - _170___v97 = _out145; + _170___v95 = _out145; _171_recIdents = _out146; r = RAST.Expr.create_UnaryOp(Dafny.Sequence.UnicodeFromString("!"), _169_recursiveGen, _168_format); RAST._IExpr _out147; @@ -5751,14 +5745,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _180_native = _source0.dtor_native; { RAST._IExpr _181_recursiveGen; - Defs._IOwnership _182___v102; + Defs._IOwnership _182___v100; Dafny.ISet> _183_recIdents; RAST._IExpr _out157; Defs._IOwnership _out158; Dafny.ISet> _out159; (this).GenExpr(_177_expr, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out157, out _out158, out _out159); _181_recursiveGen = _out157; - _182___v102 = _out158; + _182___v100 = _out158; _183_recIdents = _out159; RAST._IType _184_arrayType; RAST._IType _out160; @@ -5800,14 +5794,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _186_expr = _source0.dtor_expr; { RAST._IExpr _187_recursiveGen; - Defs._IOwnership _188___v103; + Defs._IOwnership _188___v101; Dafny.ISet> _189_recIdents; RAST._IExpr _out164; Defs._IOwnership _out165; Dafny.ISet> _out166; (this).GenExpr(_186_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out164, out _out165, out _out166); _187_recursiveGen = _out164; - _188___v103 = _out165; + _188___v101 = _out165; _189_recIdents = _out166; readIdents = _189_recIdents; r = ((_187_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0(); @@ -5826,14 +5820,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _190_expr = _source0.dtor_expr; { RAST._IExpr _191_recursiveGen; - Defs._IOwnership _192___v104; + Defs._IOwnership _192___v102; Dafny.ISet> _193_recIdents; RAST._IExpr _out169; Defs._IOwnership _out170; Dafny.ISet> _out171; (this).GenExpr(_190_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out169, out _out170, out _out171); _191_recursiveGen = _out169; - _192___v104 = _out170; + _192___v102 = _out170; _193_recIdents = _out171; readIdents = _193_recIdents; r = ((_191_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("values"))).Apply0(); @@ -5852,14 +5846,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _194_expr = _source0.dtor_expr; { RAST._IExpr _195_recursiveGen; - Defs._IOwnership _196___v105; + Defs._IOwnership _196___v103; Dafny.ISet> _197_recIdents; RAST._IExpr _out174; Defs._IOwnership _out175; Dafny.ISet> _out176; (this).GenExpr(_194_expr, selfIdent, env, Defs.Ownership.create_OwnershipAutoBorrowed(), out _out174, out _out175, out _out176); _195_recursiveGen = _out174; - _196___v105 = _out175; + _196___v103 = _out175; _197_recIdents = _out176; readIdents = _197_recIdents; r = ((_195_recursiveGen).Sel(Dafny.Sequence.UnicodeFromString("items"))).Apply0(); @@ -5933,15 +5927,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _217_name = _let_tmp_rhs1.dtor__0; RAST._IType _218_ty = _let_tmp_rhs1.dtor__1; RAST._IExpr _219_rIdent; - Defs._IOwnership _220___v106; - Dafny.ISet> _221___v107; + Defs._IOwnership _220___v104; + Dafny.ISet> _221___v105; RAST._IExpr _out183; Defs._IOwnership _out184; Dafny.ISet> _out185; (this).GenIdent(_217_name, selfIdent, _207_lEnv, (((!(_202_isConstant)) && ((_218_ty).CanReadWithoutClone())) ? (Defs.Ownership.create_OwnershipOwned()) : (Defs.Ownership.create_OwnershipBorrowed())), out _out183, out _out184, out _out185); _219_rIdent = _out183; - _220___v106 = _out184; - _221___v107 = _out185; + _220___v104 = _out184; + _221___v105 = _out185; _215_onExprArgs = Dafny.Sequence.Concat(_215_onExprArgs, Dafny.Sequence.FromElements(_219_rIdent)); } _214_body = (_214_body).Apply(_215_onExprArgs); @@ -6262,14 +6256,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _268_l = _source5.dtor_value; { RAST._IExpr _269_lExpr; - Defs._IOwnership _270___v110; + Defs._IOwnership _270___v108; Dafny.ISet> _271_recIdentsL; RAST._IExpr _out224; Defs._IOwnership _out225; Dafny.ISet> _out226; (this).GenExpr(_268_l, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out224, out _out225, out _out226); _269_lExpr = _out224; - _270___v110 = _out225; + _270___v108 = _out225; _271_recIdentsL = _out226; _267_arguments = Dafny.Sequence.Concat(_267_arguments, Dafny.Sequence.FromElements(_269_lExpr)); readIdents = Dafny.Set>.Union(readIdents, _271_recIdentsL); @@ -6286,14 +6280,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _272_h = _source6.dtor_value; { RAST._IExpr _273_hExpr; - Defs._IOwnership _274___v111; + Defs._IOwnership _274___v109; Dafny.ISet> _275_recIdentsH; RAST._IExpr _out227; Defs._IOwnership _out228; Dafny.ISet> _out229; (this).GenExpr(_272_h, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out227, out _out228, out _out229); _273_hExpr = _out227; - _274___v111 = _out228; + _274___v109 = _out228; _275_recIdentsH = _out229; _267_arguments = Dafny.Sequence.Concat(_267_arguments, Dafny.Sequence.FromElements(_273_hExpr)); readIdents = Dafny.Set>.Union(readIdents, _275_recIdentsH); @@ -6420,17 +6414,17 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _294_paramTypesMap = Dafny.Map, RAST._IType>.Update(_294_paramTypesMap, _296_name, ((_292_params).Select(_295_i)).dtor_tpe); } Defs._IEnvironment _297_subEnv; - _297_subEnv = ((env).ToOwned()).merge(Defs.Environment.create(_293_paramNames, _294_paramTypesMap, Dafny.Set>.FromElements())); + _297_subEnv = ((env).ToOwned()).Merge(Defs.Environment.create(_293_paramNames, _294_paramTypesMap, Dafny.Set>.FromElements())); RAST._IExpr _298_recursiveGen; Dafny.ISet> _299_recIdents; - Defs._IEnvironment _300___v113; + Defs._IEnvironment _300___v111; RAST._IExpr _out242; Dafny.ISet> _out243; Defs._IEnvironment _out244; (this).GenStmts(_291_body, ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) ? (Defs.SelfInfo.create_ThisTyped(Dafny.Sequence.UnicodeFromString("_this"), (selfIdent).dtor_dafnyType)) : (Defs.SelfInfo.create_NoSelf())), _297_subEnv, true, Std.Wrappers.Option>>.create_None(), out _out242, out _out243, out _out244); _298_recursiveGen = _out242; _299_recIdents = _out243; - _300___v113 = _out244; + _300___v111 = _out244; readIdents = Dafny.Set>.FromElements(); _299_recIdents = Dafny.Set>.Difference(_299_recIdents, Dafny.Helpers.Id>, Dafny.ISet>>>((_301_paramNames) => ((System.Func>>)(() => { var _coll0 = new System.Collections.Generic.List>(); @@ -6456,15 +6450,15 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir after__ASSIGN_SUCH_THAT_1: ; if ((!object.Equals(selfIdent, Defs.SelfInfo.create_NoSelf())) && ((_304_next).Equals(Dafny.Sequence.UnicodeFromString("_this")))) { RAST._IExpr _305_selfCloned; - Defs._IOwnership _306___v114; - Dafny.ISet> _307___v115; + Defs._IOwnership _306___v112; + Dafny.ISet> _307___v113; RAST._IExpr _out245; Defs._IOwnership _out246; Dafny.ISet> _out247; (this).GenIdent(Dafny.Sequence.UnicodeFromString("self"), selfIdent, Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out245, out _out246, out _out247); _305_selfCloned = _out245; - _306___v114 = _out246; - _307___v115 = _out247; + _306___v112 = _out246; + _307___v113 = _out247; _303_allReadCloned = (_303_allReadCloned).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_MUT(), Dafny.Sequence.UnicodeFromString("_this"), Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(_305_selfCloned))); } else if (!((_293_paramNames).Contains(_304_next))) { RAST._IExpr _308_copy; @@ -6528,14 +6522,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out252 = (this).GenType((((_310_values).Select(_321_i)).dtor__0).dtor_typ, Defs.GenTypeContext.@default()); _322_typeGen = _out252; RAST._IExpr _323_valueGen; - Defs._IOwnership _324___v116; + Defs._IOwnership _324___v114; Dafny.ISet> _325_recIdents; RAST._IExpr _out253; Defs._IOwnership _out254; Dafny.ISet> _out255; (this).GenExpr(((_310_values).Select(_321_i)).dtor__1, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out253, out _out254, out _out255); _323_valueGen = _out253; - _324___v116 = _out254; + _324___v114 = _out254; _325_recIdents = _out255; r = (r).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), Defs.__default.escapeVar((((_310_values).Select(_321_i)).dtor__0).dtor_name), Std.Wrappers.Option.create_Some(_322_typeGen), Std.Wrappers.Option.create_Some(_323_valueGen))); readIdents = Dafny.Set>.Union(readIdents, _325_recIdents); @@ -6572,14 +6566,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _333_iifeBody = _source0.dtor_iifeBody; { RAST._IExpr _334_valueGen; - Defs._IOwnership _335___v117; + Defs._IOwnership _335___v115; Dafny.ISet> _336_recIdents; RAST._IExpr _out261; Defs._IOwnership _out262; Dafny.ISet> _out263; (this).GenExpr(_332_value, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out261, out _out262, out _out263); _334_valueGen = _out261; - _335___v117 = _out262; + _335___v115 = _out262; _336_recIdents = _out263; readIdents = _336_recIdents; RAST._IType _337_valueTypeGen; @@ -6589,14 +6583,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _338_iifeVar; _338_iifeVar = Defs.__default.escapeVar(_330_name); RAST._IExpr _339_bodyGen; - Defs._IOwnership _340___v118; + Defs._IOwnership _340___v116; Dafny.ISet> _341_bodyIdents; RAST._IExpr _out265; Defs._IOwnership _out266; Dafny.ISet> _out267; (this).GenExpr(_333_iifeBody, selfIdent, (env).AddAssigned(_338_iifeVar, _337_valueTypeGen), Defs.Ownership.create_OwnershipOwned(), out _out265, out _out266, out _out267); _339_bodyGen = _out265; - _340___v118 = _out266; + _340___v116 = _out266; _341_bodyIdents = _out267; readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_341_bodyIdents, Dafny.Set>.FromElements(_338_iifeVar))); r = RAST.Expr.create_Block((RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _338_iifeVar, Std.Wrappers.Option.create_Some(_337_valueTypeGen), Std.Wrappers.Option.create_Some(_334_valueGen))).Then(_339_bodyGen)); @@ -6616,14 +6610,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _343_args = _source0.dtor_args; { RAST._IExpr _344_funcExpr; - Defs._IOwnership _345___v119; + Defs._IOwnership _345___v117; Dafny.ISet> _346_recIdents; RAST._IExpr _out270; Defs._IOwnership _out271; Dafny.ISet> _out272; (this).GenExpr(_342_func, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out270, out _out271, out _out272); _344_funcExpr = _out270; - _345___v119 = _out271; + _345___v117 = _out271; _346_recIdents = _out272; readIdents = _346_recIdents; Dafny.ISequence _347_rArgs; @@ -6661,14 +6655,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _354_variant = _source0.dtor_variant; { RAST._IExpr _355_exprGen; - Defs._IOwnership _356___v120; + Defs._IOwnership _356___v118; Dafny.ISet> _357_recIdents; RAST._IExpr _out278; Defs._IOwnership _out279; Dafny.ISet> _out280; (this).GenExpr(_352_on, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out278, out _out279, out _out280); _355_exprGen = _out278; - _356___v120 = _out279; + _356___v118 = _out279; _357_recIdents = _out280; RAST._IExpr _358_variantExprPath; RAST._IExpr _out281; @@ -6803,14 +6797,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _376_of = _source0.dtor_of; { RAST._IExpr _377_exprGen; - Defs._IOwnership _378___v121; + Defs._IOwnership _378___v119; Dafny.ISet> _379_recIdents; RAST._IExpr _out302; Defs._IOwnership _out303; Dafny.ISet> _out304; (this).GenExpr(_376_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out302, out _out303, out _out304); _377_exprGen = _out302; - _378___v121 = _out303; + _378___v119 = _out303; _379_recIdents = _out304; r = ((_377_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); RAST._IExpr _out305; @@ -6830,14 +6824,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _381_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _382_exprGen; - Defs._IOwnership _383___v122; + Defs._IOwnership _383___v120; Dafny.ISet> _384_recIdents; RAST._IExpr _out307; Defs._IOwnership _out308; Dafny.ISet> _out309; (this).GenExpr(_380_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out307, out _out308, out _out309); _382_exprGen = _out307; - _383___v122 = _out308; + _383___v120 = _out308; _384_recIdents = _out309; r = ((_382_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_381_includeDuplicates)) { @@ -6860,14 +6854,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _386_includeDuplicates = _source0.dtor_includeDuplicates; { RAST._IExpr _387_exprGen; - Defs._IOwnership _388___v123; + Defs._IOwnership _388___v121; Dafny.ISet> _389_recIdents; RAST._IExpr _out312; Defs._IOwnership _out313; Dafny.ISet> _out314; (this).GenExpr(_385_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out312, out _out313, out _out314); _387_exprGen = _out312; - _388___v123 = _out313; + _388___v121 = _out313; _389_recIdents = _out314; r = ((_387_exprGen).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); if (!(_386_includeDuplicates)) { @@ -6889,14 +6883,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _390_of = _source0.dtor_of; { RAST._IExpr _391_exprGen; - Defs._IOwnership _392___v124; + Defs._IOwnership _392___v122; Dafny.ISet> _393_recIdents; RAST._IExpr _out317; Defs._IOwnership _out318; Dafny.ISet> _out319; (this).GenExpr(_390_of, selfIdent, env, Defs.Ownership.create_OwnershipBorrowed(), out _out317, out _out318, out _out319); _391_exprGen = _out317; - _392___v124 = _out318; + _392___v122 = _out318; _393_recIdents = _out319; r = ((((_391_exprGen).Sel(Dafny.Sequence.UnicodeFromString("keys"))).Apply0()).Sel(Dafny.Sequence.UnicodeFromString("iter"))).Apply0(); readIdents = _393_recIdents; @@ -6914,14 +6908,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir DAST._IExpression _394_of = _source0.dtor_of; { RAST._IExpr _395_exprGen; - Defs._IOwnership _396___v125; + Defs._IOwnership _396___v123; Dafny.ISet> _397_recIdents; RAST._IExpr _out322; Defs._IOwnership _out323; Dafny.ISet> _out324; (this).GenExpr(_394_of, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out322, out _out323, out _out324); _395_exprGen = _out322; - _396___v125 = _out323; + _396___v123 = _out323; _397_recIdents = _out324; r = ((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("iter"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("once"))).Apply1(_395_exprGen); readIdents = _397_recIdents; @@ -6942,24 +6936,24 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _401_up = _source0.dtor_up; { RAST._IExpr _402_lo; - Defs._IOwnership _403___v126; + Defs._IOwnership _403___v124; Dafny.ISet> _404_recIdentsLo; RAST._IExpr _out327; Defs._IOwnership _out328; Dafny.ISet> _out329; (this).GenExpr(_399_lo, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out327, out _out328, out _out329); _402_lo = _out327; - _403___v126 = _out328; + _403___v124 = _out328; _404_recIdentsLo = _out329; RAST._IExpr _405_hi; - Defs._IOwnership _406___v127; + Defs._IOwnership _406___v125; Dafny.ISet> _407_recIdentsHi; RAST._IExpr _out330; Defs._IOwnership _out331; Dafny.ISet> _out332; (this).GenExpr(_400_hi, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out330, out _out331, out _out332); _405_hi = _out330; - _406___v127 = _out331; + _406___v125 = _out331; _407_recIdentsHi = _out332; if (_401_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range"))).AsExpr()).Apply(Dafny.Sequence.FromElements(_402_lo, _405_hi)); @@ -6990,14 +6984,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir bool _410_up = _source0.dtor_up; { RAST._IExpr _411_start; - Defs._IOwnership _412___v128; + Defs._IOwnership _412___v126; Dafny.ISet> _413_recIdentStart; RAST._IExpr _out336; Defs._IOwnership _out337; Dafny.ISet> _out338; (this).GenExpr(_409_start, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out336, out _out337, out _out338); _411_start = _out336; - _412___v128 = _out337; + _412___v126 = _out337; _413_recIdentStart = _out338; if (_410_up) { r = (((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("integer_range_unbounded"))).AsExpr()).Apply1(_411_start); @@ -7071,14 +7065,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _out348 = (this).GenType(_420_elemType, Defs.GenTypeContext.@default()); _424_tpe = _out348; RAST._IExpr _425_collectionGen; - Defs._IOwnership _426___v129; + Defs._IOwnership _426___v127; Dafny.ISet> _427_recIdents; RAST._IExpr _out349; Defs._IOwnership _out350; Dafny.ISet> _out351; (this).GenExpr(_421_collection, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out349, out _out350, out _out351); _425_collectionGen = _out349; - _426___v129 = _out350; + _426___v127 = _out350; _427_recIdents = _out351; Dafny.ISequence _428_extraAttributes; _428_extraAttributes = Dafny.Sequence.FromElements(); @@ -7101,14 +7095,14 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir Dafny.ISequence _436_dt__update_hparams_h0 = _430_newFormals; _434_newLambda = DAST.Expression.create_Lambda(_436_dt__update_hparams_h0, (_435_dt__update__tmp_h1).dtor_retType, (_435_dt__update__tmp_h1).dtor_body); RAST._IExpr _437_lambdaGen; - Defs._IOwnership _438___v130; + Defs._IOwnership _438___v128; Dafny.ISet> _439_recLambdaIdents; RAST._IExpr _out352; Defs._IOwnership _out353; Dafny.ISet> _out354; (this).GenExpr(_434_newLambda, selfIdent, env, Defs.Ownership.create_OwnershipOwned(), out _out352, out _out353, out _out354); _437_lambdaGen = _out352; - _438___v130 = _out353; + _438___v128 = _out353; _439_recLambdaIdents = _out354; Dafny.ISequence _440_fn; if (_422_is__forall) { @@ -7187,7 +7181,7 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul BigInteger _hi2 = new BigInteger(((_5_allModules).dtor_keys).Count); for (BigInteger _8_i = BigInteger.Zero; _8_i < _hi2; _8_i++) { if (!((_5_allModules).dtor_values).Contains(((_5_allModules).dtor_keys).Select(_8_i))) { - goto continue_0; + goto continue_6; } RAST._IMod _9_m; _9_m = (Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select((_5_allModules).dtor_values,((_5_allModules).dtor_keys).Select(_8_i))).ToRust(); @@ -7197,9 +7191,9 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul } s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("\n")); s = Dafny.Sequence.Concat(s, (_9_m)._ToString(Dafny.Sequence.UnicodeFromString(""))); - continue_0: ; + continue_6: ; } - after_0: ; + after_6: ; return s; } public Dafny.ISequence EmitCallToMain(DAST._IExpression companion, Dafny.ISequence mainMethodName, bool hasArgs) @@ -7216,15 +7210,15 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul ")); } RAST._IExpr _0_call; - Defs._IOwnership _1___v131; - Dafny.ISet> _2___v132; + Defs._IOwnership _1___v129; + Dafny.ISet> _2___v130; RAST._IExpr _out0; Defs._IOwnership _out1; Dafny.ISet> _out2; (this).GenExpr(companion, Defs.SelfInfo.create_NoSelf(), Defs.Environment.Empty(), Defs.Ownership.create_OwnershipOwned(), out _out0, out _out1, out _out2); _0_call = _out0; - _1___v131 = _out1; - _2___v132 = _out2; + _1___v129 = _out1; + _2___v130 = _out2; _0_call = (_0_call).FSel(mainMethodName); if (hasArgs) { _0_call = (_0_call).Apply1(RAST.__default.Borrow(RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("dafny_args")))); diff --git a/Source/DafnyCore/GeneratedFromDafny/Defs.cs b/Source/DafnyCore/GeneratedFromDafny/Defs.cs index 454899a3d4e..be5a14b77e7 100644 --- a/Source/DafnyCore/GeneratedFromDafny/Defs.cs +++ b/Source/DafnyCore/GeneratedFromDafny/Defs.cs @@ -491,14 +491,19 @@ public static bool BecomesRightCallsLeft(DAST._IBinOp op) { return false; } } + public static RAST._IExpr Panic(Dafny.ISequence optText) { + if ((optText).Equals(Dafny.Sequence.UnicodeFromString(""))) { + return (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply0(); + } else { + return (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply1(RAST.Expr.create_LiteralString(optText, false, false)); + } + } public static RAST._IExpr UnreachablePanicIfVerified(Defs._IPointerType pointerType, Dafny.ISequence optText) { if ((pointerType).is_Raw) { return RAST.__default.Unsafe(RAST.Expr.create_Block(((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("hint"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("unreachable_unchecked"))).Apply0())); - } else if ((optText).Equals(Dafny.Sequence.UnicodeFromString(""))) { - return (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply0(); } else { - return (RAST.Expr.create_Identifier(Dafny.Sequence.UnicodeFromString("panic!"))).Apply1(RAST.Expr.create_LiteralString(optText, false, false)); + return Defs.__default.Panic(optText); } } public static RAST._IModDecl DefaultDatatypeImpl(Dafny.ISequence rTypeParamsDecls, RAST._IType datatypeType, RAST._IExpr datatypeName, Dafny.ISequence structAssignments) @@ -970,7 +975,8 @@ public interface _IEnvironment { bool NeedsAsRefForBorrow(Dafny.ISequence name); bool IsMaybePlacebo(Dafny.ISequence name); Defs._IEnvironment AddAssigned(Dafny.ISequence name, RAST._IType tpe); - Defs._IEnvironment merge(Defs._IEnvironment other); + Defs._IEnvironment Merge(Defs._IEnvironment other); + Defs._IEnvironment Join(Defs._IEnvironment thenBranch, Defs._IEnvironment elseBranch); Defs._IEnvironment RemoveAssigned(Dafny.ISequence name); Defs._IEnvironment AddAssignmentStatus(Dafny.ISequence name, Defs._IAssignmentStatus assignmentStatus); bool IsAssignmentStatusKnown(Dafny.ISequence name); @@ -1090,9 +1096,16 @@ public Defs._IEnvironment AddAssigned(Dafny.ISequence name, RAST._IT { return Defs.Environment.create(Dafny.Sequence>.Concat((this).dtor_names, Dafny.Sequence>.FromElements(name)), Dafny.Map, RAST._IType>.Update((this).dtor_types, name, tpe), Dafny.Set>.Difference((this).dtor_assignmentStatusKnown, Dafny.Set>.FromElements(name))); } - public Defs._IEnvironment merge(Defs._IEnvironment other) { + public Defs._IEnvironment Merge(Defs._IEnvironment other) { return Defs.Environment.create(Dafny.Sequence>.Concat((this).dtor_names, (other).dtor_names), Dafny.Map, RAST._IType>.Merge((this).dtor_types, (other).dtor_types), Dafny.Set>.Union((this).dtor_assignmentStatusKnown, (other).dtor_assignmentStatusKnown)); } + public Defs._IEnvironment Join(Defs._IEnvironment thenBranch, Defs._IEnvironment elseBranch) + { + Dafny.ISet> _0_removed = Dafny.Set>.Difference(((this).dtor_types).Keys, Dafny.Set>.Union(((thenBranch).dtor_types).Keys, ((elseBranch).dtor_types).Keys)); + return Defs.Environment.create(Std.Collections.Seq.__default.Filter>(Dafny.Helpers.Id>, Func, bool>>>((_1_removed) => ((System.Func, bool>)((_2_name) => { + return !(_1_removed).Contains(_2_name); +})))(_0_removed), (this).dtor_names), Dafny.Map, RAST._IType>.Subtract((this).dtor_types, _0_removed), Dafny.Set>.Difference((this).dtor_assignmentStatusKnown, _0_removed)); + } public Defs._IEnvironment RemoveAssigned(Dafny.ISequence name) { BigInteger _0_indexInEnv = Std.Collections.Seq.__default.IndexOf>((this).dtor_names, name); return Defs.Environment.create(Dafny.Sequence>.Concat(((this).dtor_names).Subsequence(BigInteger.Zero, _0_indexInEnv), ((this).dtor_names).Drop((_0_indexInEnv) + (BigInteger.One))), Dafny.Map, RAST._IType>.Subtract((this).dtor_types, Dafny.Set>.FromElements(name)), Dafny.Set>.Difference((this).dtor_assignmentStatusKnown, Dafny.Set>.FromElements(name))); diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy new file mode 100644 index 00000000000..9a2b614261d --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy @@ -0,0 +1,36 @@ +// NONUNIFORM: Rust does not support relaxed definite assignment +// RUN: %exits-with 3 %baredafny run --target=rs --relax-definite-assignment "%s" > "%t" +// RUN: %diff "%s.wrong.expect" "%t" +// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +datatype D = D(value: int) + +class Y { + var c: int + const d: D + constructor(c: int) ensures this.c == c && d.value == c { + this.c := c; + if c == 1 { + this.d := D(1); + } else { + this.d := D(c); + } + } + + constructor Two(c: int, b: bool) ensures this.c == c && d.value == c + requires b + { + this.c := c; // d not assigned, compilation error. + if b { + this.d := D(c); + } + // This will emit a conditional panick but Dafny will prove it's unreachable + } +} + +method Main() { + var y := new Y(1); + var y2 := new Y.Two(1, true); + print "Instantiation successful"; +} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.expect new file mode 100644 index 00000000000..ec136887e83 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 3 verified, 0 errors +Instantiation successful \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect new file mode 100644 index 00000000000..ecd5bfe4151 --- /dev/null +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect @@ -0,0 +1,3 @@ + +Dafny program verifier finished with 3 verified, 0 errors +(0,-1): Error: Microsoft.Dafny.UnsupportedInvalidOperationException: The Rust compiler does not support `--relax-definite-assignment` From b243b6e0abf53ed2a89e8adf8ca4b0ca2001d851 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Thu, 6 Feb 2025 17:21:14 -0600 Subject: [PATCH 55/69] Need to see if I'm breaking anyone's code --- .../Backends/Rust/Dafny-compiler-rust.dfy | 11 +++++++--- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 22 ++++++++++++------- .../BoogieGenerator.DefiniteAssignment.cs | 2 +- .../LitTests/LitTest/comp/rust/traits.dfy | 1 + 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index fc4b881dd10..9006cb73091 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -2132,7 +2132,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { onExpr } - method GenOwnedCallPart(ghost e: Expression, on: Expression, selfIdent: SelfInfo, name: CallName, typeArgs: seq, args: seq, env: Environment) returns (r: R.Expr, readIdents: set) + method GenCall(ghost e: Expression, on: Expression, selfIdent: SelfInfo, name: CallName, typeArgs: seq, args: seq, env: Environment) returns (r: R.Expr, readIdents: set) requires forall a <- args :: a < e requires on < e modifies this @@ -2402,7 +2402,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } case Call(on, name, typeArgs, args, maybeOutVars) => { assume {:axiom} Expression.Call(on, name, typeArgs, args) < stmt; - generated, readIdents := GenOwnedCallPart(Expression.Call(on, name, typeArgs, args), on, selfIdent, name, typeArgs, args, env); + generated, readIdents := GenCall(Expression.Call(on, name, typeArgs, args), on, selfIdent, name, typeArgs, args, env); newEnv := env; if maybeOutVars.Some? && |maybeOutVars.value| == 1 { var outVar := escapeVar(maybeOutVars.value[0]); @@ -3358,6 +3358,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { resultingOwnership := OwnershipOwned; } else if currentlyBorrowed { assert expectedOwnership == OwnershipBorrowed; + var needsRcWrapping := isSelf && selfIdent.IsRcWrappedDatatype(); + if needsRcWrapping { + r := rcNew(r.Clone()); + } resultingOwnership := OwnershipBorrowed; } else { assert expectedOwnership == OwnershipBorrowed; @@ -3810,6 +3814,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { match selfIdent { case ThisTyped(id, dafnyType) => { r, resultingOwnership, readIdents := GenIdent(id, selfIdent, env, expectedOwnership); + return; } case None => { r := Error("this outside of a method"); @@ -4151,7 +4156,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { return; } case Call(on, name, typeArgs, args) => { - r, readIdents := GenOwnedCallPart(e, on, selfIdent, name, typeArgs, args, env); + r, readIdents := GenCall(e, on, selfIdent, name, typeArgs, args, env); r, resultingOwnership := FromOwned(r, expectedOwnership); return; } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 324f6820471..161070e2bb2 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -2458,7 +2458,7 @@ public RAST._IExpr FromGeneralBorrowToSelfBorrow(RAST._IExpr onExpr, Defs._IOwne return onExpr; } } - public void GenOwnedCallPart(DAST._IExpression @on, Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequence typeArgs, Dafny.ISequence args, Defs._IEnvironment env, out RAST._IExpr r, out Dafny.ISet> readIdents) + public void GenCall(DAST._IExpression @on, Defs._ISelfInfo selfIdent, DAST._ICallName name, Dafny.ISequence typeArgs, Dafny.ISequence args, Defs._IEnvironment env, out RAST._IExpr r, out Dafny.ISet> readIdents) { r = RAST.Expr.Default(); readIdents = Dafny.Set>.Empty; @@ -3050,7 +3050,7 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv { RAST._IExpr _out50; Dafny.ISet> _out51; - (this).GenOwnedCallPart(_89_on, selfIdent, _90_name, _91_typeArgs, _92_args, env, out _out50, out _out51); + (this).GenCall(_89_on, selfIdent, _90_name, _91_typeArgs, _92_args, env, out _out50, out _out51); generated = _out50; readIdents = _out51; newEnv = env; @@ -4615,17 +4615,22 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden } resultingOwnership = Defs.Ownership.create_OwnershipOwned(); } else if (_2_currentlyBorrowed) { + bool _10_needsRcWrapping; + _10_needsRcWrapping = (_4_isSelf) && ((selfIdent).IsRcWrappedDatatype()); + if (_10_needsRcWrapping) { + r = Dafny.Helpers.Id>((this).rcNew)((r).Clone()); + } resultingOwnership = Defs.Ownership.create_OwnershipBorrowed(); } else { - bool _10_selfIsGeneralTrait; - _10_selfIsGeneralTrait = (_4_isSelf) && (((System.Func)(() => { + bool _11_selfIsGeneralTrait; + _11_selfIsGeneralTrait = (_4_isSelf) && (((System.Func)(() => { DAST._IType _source0 = (selfIdent).dtor_dafnyType; { if (_source0.is_UserDefined) { DAST._IResolvedType resolved0 = _source0.dtor_resolved; - DAST._IResolvedTypeBase _11_base = resolved0.dtor_kind; - Dafny.ISequence _12_attributes = resolved0.dtor_attributes; - return ((_11_base).is_Trait) && (((_11_base).dtor_traitType).is_GeneralTrait); + DAST._IResolvedTypeBase _12_base = resolved0.dtor_kind; + Dafny.ISequence _13_attributes = resolved0.dtor_attributes; + return ((_12_base).is_Trait) && (((_12_base).dtor_traitType).is_GeneralTrait); } } { @@ -5563,6 +5568,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir r = _out122; resultingOwnership = _out123; readIdents = _out124; + return ; } goto after_match1; } @@ -6379,7 +6385,7 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir { RAST._IExpr _out237; Dafny.ISet> _out238; - (this).GenOwnedCallPart(_285_on, selfIdent, _286_name, _287_typeArgs, _288_args, env, out _out237, out _out238); + (this).GenCall(_285_on, selfIdent, _286_name, _287_typeArgs, _288_args, env, out _out237, out _out238); r = _out237; readIdents = _out238; RAST._IExpr _out239; diff --git a/Source/DafnyCore/Verifier/BoogieGenerator.DefiniteAssignment.cs b/Source/DafnyCore/Verifier/BoogieGenerator.DefiniteAssignment.cs index ac55f79634b..9ac6e4d7fdf 100644 --- a/Source/DafnyCore/Verifier/BoogieGenerator.DefiniteAssignment.cs +++ b/Source/DafnyCore/Verifier/BoogieGenerator.DefiniteAssignment.cs @@ -30,7 +30,7 @@ bool NeedsDefiniteAssignmentTracker(bool isGhost, Type type, bool isField) { (options.DefiniteAssignmentLevel == 4 && isField && !options.ForbidNondeterminism)) { if (isGhost && type.IsNonempty) { return false; - } else if (!isGhost && type.HasCompilableValue) { + } else if (!isGhost && type.HasCompilableValue && options.DefiniteAssignmentLevel == 1) { return false; } } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy index bf9fa40f586..95f048cae4a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy @@ -76,6 +76,7 @@ module All { const d: int := 2 constructor(c: int) { this.c := c; + this.z := 3; } method AddZ() modifies this From 48b97c36e1b60456e9eef0fdf45d3561c07a3d1a Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 7 Feb 2025 12:42:34 -0600 Subject: [PATCH 56/69] Require --enforce-determinism --- Source/DafnyCore/Backends/Rust/RustBackend.cs | 14 ++++++++++++-- .../LitTests/LitTest/comp/rust/arc/tokiouser.dfy | 2 +- .../LitTests/LitTest/comp/rust/arrays.dfy | 2 +- .../LitTests/LitTest/comp/rust/autoinit.dfy | 2 +- .../LitTest/comp/rust/avoid_soundness_mut.dfy | 2 +- .../LitTests/LitTest/comp/rust/borrowing.dfy | 2 +- .../LitTests/LitTest/comp/rust/bymethod.dfy | 2 +- .../LitTest/comp/rust/cargoreleasefailure.dfy | 2 +- .../LitTests/LitTest/comp/rust/cargotest.dfy | 2 +- .../LitTests/LitTest/comp/rust/classes-relax.dfy | 4 ++-- .../LitTests/LitTest/comp/rust/classes.dfy | 4 ++-- .../LitTests/LitTest/comp/rust/constants.dfy | 2 +- .../LitTests/LitTest/comp/rust/continue.dfy | 4 ++-- .../LitTests/LitTest/comp/rust/conversions.dfy | 2 +- .../LitTests/LitTest/comp/rust/datatypes-impl.dfy | 2 +- .../LitTest/comp/rust/datatypes-scoping.dfy | 2 +- .../LitTests/LitTest/comp/rust/datatypes.dfy | 4 ++-- .../LitTests/LitTest/comp/rust/docstring.dfy | 2 +- .../LitTests/LitTest/comp/rust/elephant.dfy | 2 +- .../LitTest/comp/rust/externalclasses-errors.dfy | 2 +- .../LitTests/LitTest/comp/rust/externalclasses.dfy | 2 +- .../LitTests/LitTest/comp/rust/lambda.dfy | 4 +++- .../TestFiles/LitTests/LitTest/comp/rust/loops.dfy | 2 +- .../LitTests/LitTest/comp/rust/mapsubsets.dfy | 2 +- .../LitTests/LitTest/comp/rust/methods.dfy | 2 +- .../LitTests/LitTest/comp/rust/moduleordering.dfy | 2 +- .../LitTests/LitTest/comp/rust/nestedmodules.dfy | 2 +- .../LitTest/comp/rust/newtype-set-comp.dfy | 2 +- .../LitTests/LitTest/comp/rust/newtypes.dfy | 4 ++-- .../LitTests/LitTest/comp/rust/newtypesrefresh.dfy | 2 +- .../LitTests/LitTest/comp/rust/nomaybeplacebos.dfy | 2 +- .../LitTests/LitTest/comp/rust/operators.dfy | 2 +- .../LitTests/LitTest/comp/rust/reserved-names.dfy | 2 +- .../LitTests/LitTest/comp/rust/small/01-hash.dfy | 2 +- .../LitTests/LitTest/comp/rust/small/02-binary.dfy | 2 +- .../LitTest/comp/rust/small/03-methodnamed.dfy | 2 +- .../LitTest/comp/rust/small/04-mismatched.dfy | 2 +- .../LitTests/LitTest/comp/rust/small/05-coerce.dfy | 2 +- .../LitTest/comp/rust/small/06-type-bounds.dfy | 2 +- .../comp/rust/small/07-instantiated-methods.dfy | 2 +- .../small/08-not-all-trait-items-implemented.dfy | 2 +- .../LitTest/comp/rust/small/09-trait-method.dfy | 2 +- .../LitTests/LitTest/comp/rust/strings.dfy | 4 ++-- .../LitTest/comp/rust/subsetconstraints.dfy | 2 +- .../TestFiles/LitTests/LitTest/comp/rust/tests.dfy | 4 ++-- .../LitTest/comp/rust/traits-datatypes.dfy | 2 +- .../LitTests/LitTest/comp/rust/traits.dfy | 2 +- .../LitTests/LitTest/comp/rust/type-test.dfy | 4 ++-- 48 files changed, 69 insertions(+), 57 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/RustBackend.cs b/Source/DafnyCore/Backends/Rust/RustBackend.cs index 70d09b4b64a..4e517e72ede 100644 --- a/Source/DafnyCore/Backends/Rust/RustBackend.cs +++ b/Source/DafnyCore/Backends/Rust/RustBackend.cs @@ -48,8 +48,18 @@ public override string TargetBaseDir(string dafnyProgramName) => $"{Path.GetFileNameWithoutExtension(dafnyProgramName)}-rust/src"; protected override DafnyWrittenCodeGenerator CreateDafnyWrittenCompiler() { - if (Options.Get(CommonOptionBag.RelaxDefiniteAssignment)) { - throw new UnsupportedInvalidOperationException("The Rust compiler does not support `--relax-definite-assignment`"); + if (!Options.Get(CommonOptionBag.EnforceDeterminism)) { + // DEV: This requirement could be lifted in the future if + // BoogieGenerator.DefiniteAssignment.cs: + // the line + // if (!isGhost && type.HasCompilableValue) { + // could become + // if (!isGhost && type.HasCompilableValue && options.DefiniteAssignmentLevel == 1) { + // Meaning that the default behavior for fields and array initialization is the same as for local variables: + // Auto-init is not supported, fields have to be initialized. + + throw new UnsupportedInvalidOperationException( + "The Rust compiler requires `--enforce-determinism`. This requirement can"); } return new RustCodeGenerator(Options); } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arc/tokiouser.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arc/tokiouser.dfy index add2a31a9f0..8623ffe74c7 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arc/tokiouser.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arc/tokiouser.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny translate rs --rust-module-name=tokiouser --include-runtime=true --rust-sync "%s" > "%t" +// RUN: %baredafny translate rs --enforce-determinism --rust-module-name=tokiouser --include-runtime=true --rust-sync "%s" > "%t" // RUN: "%S/tokiouser-rust/cargo" run >> "%t" // RUN: %diff "%s.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy index 5f11c241c18..0d4e49fd99e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" module Origin.Imported { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy index aae1bce74e3..a53e4616db4 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Can't create class instances without constructors as Rust does not support Dafny defaults since subset types are erased -// RUN: %exits-with 3 %baredafny run --target=rs "%s" > "%t" +// RUN: %exits-with 3 %baredafny run --enforce-determinism --target=rs "%s" > "%t" // RUN: %diff "%s.expect" "%t" class Test { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy index 2335ca7bd41..b653ca6e830 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy @@ -1,4 +1,4 @@ -// RUN: %baredafny build -t:rs "%s" +// RUN: %baredafny build -t:rs --enforce-determinism "%s" // RUN: "%S/avoid_soundness_mut-rust/cargo" run --release > "%t" // RUN: %diff "%s.expect" "%t" // RUN: %baredafny build -t:rs --raw-pointers "%s" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy index e9759a8df57..b36d8fe3b56 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/borrowing.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --emit-uncompilable-code "%s" > "%t" +// RUN: %baredafny run --target=rs --emit-uncompilable-code --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype U8 = x: int | 0 <= x <= 255 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy index 913b7d42298..6dfbf341c0a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/bymethod.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargoreleasefailure.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargoreleasefailure.dfy index e247b923cfc..4b8fb20498c 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargoreleasefailure.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargoreleasefailure.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny build --target=rs "%s" +// RUN: %baredafny build --target=rs --enforce-determinism "%s" // If there is no '#[inline(never)]' in front of ::dafny_runtime::increment_strong_count // then the release will think it's safe to remove the strong count increment, resulting ins a segfault // RUN: "%S/cargoreleasefailure-rust/cargo" run --release diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargotest.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargotest.dfy index be2eee7921d..f977c83265e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargotest.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/cargotest.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Test of cargo test to support Dafny tests -// RUN: %baredafny build --target=rs "%s" > "%t" +// RUN: %baredafny build --target=rs "%s" --enforce-determinism > "%t" // RUN: %exits-with 101 "%S/cargotest-rust/cargo" test >> "%t" // RUN: %OutputCheck --file-to-check "%t" "%S/cargotest1.check" // RUN: %OutputCheck --file-to-check "%t" "%S/cargotest2.check" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy index 9a2b614261d..11aff7e12fc 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy @@ -1,7 +1,7 @@ // NONUNIFORM: Rust does not support relaxed definite assignment -// RUN: %exits-with 3 %baredafny run --target=rs --relax-definite-assignment "%s" > "%t" +// RUN: %exits-with 3 %baredafny run --target=rs "%s" > "%t" // RUN: %diff "%s.wrong.expect" "%t" -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" datatype D = D(value: int) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy index 5aa9fd3f3dd..00a660ca76a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes.dfy @@ -1,7 +1,7 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs "%s" --enforce-determinism > "%t" // RUN: %diff "%s.expect" "%t" -// RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" +// RUN: %baredafny run --target=rs --raw-pointers --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" datatype D = D(value: int) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy index aa003792960..361abda170a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/constants.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Tests that references to function constants are eta-expanded with an additional call and type annotations in Rust backend -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" const f: int -> int := x => x diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy index f964dbdb778..59f99839799 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/continue.dfy @@ -1,7 +1,7 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" -// RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" +// RUN: %baredafny run --target=rs --raw-pointers --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" method Main() { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy index a655ada01ce..67ce2882e61 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/conversions.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype Uint8 = x: int | 0 <= x < 256 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-impl.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-impl.dfy index 643a2592ec0..7c084843d64 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-impl.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-impl.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Tests generation of print, and equality in Rust for function / non-(==) type members -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" datatype F = F(i: nat, f: int -> int) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy index 67f6d43b0f4..13ef7682d63 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Tests that datatype members like hash do not shadow those generated by Rust backend -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" datatype Loop = Loop(loop: Loop) | Point() { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy index ef835701c2e..9d22f5fc68d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes.dfy @@ -1,7 +1,7 @@ // NONUNIFORM: Demonstration of the use of the external Rust Option<> type -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" -// RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --raw-pointers "%s" > "%t" // RUN: %diff "%s.expect" "%t" module {:compile false} {:extern "::std::option"} RustStdOption { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy index fbe65714621..45747b185b9 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Test that the Rust generated code contains docstrings -// RUN: %baredafny build --target:rs "%s" > "%t" +// RUN: %baredafny build --target:rs --enforce-determinism "%s" > "%t" // RUN: %OutputCheck --file-to-check "%S/docstring-rust/src/docstring.rs" "%S/docstring.check" // RUN: "%S/docstring-rust/cargo" test --doc diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy index ec117b68b5c..7b823dea94d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/elephant.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Tests generation of elephant assignment to shadowed variable -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" datatype Option = Some(value: string) | None() { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy index ebec1203fcf..896ae8aac06 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses-errors.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %exits-with 3 %baredafny run --target=rs --input "%S/externalclasses.rs" "%s" > "%t" +// RUN: %exits-with 3 %baredafny run --target=rs --enforce-determinism --input "%S/externalclasses.rs" "%s" > "%t" // RUN: %diff "%s.expect" "%t" module {:extern} ExternalClassContainer { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy index 7fea88f510e..5392aa83f4a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/externalclasses.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests. Extern abstract types only compile with the Rust compiler for now. -// RUN: %baredafny run --target=rs --input "%S/externalclasses.rs" "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --input "%S/externalclasses.rs" "%s" > "%t" // RUN: %diff "%s.expect" "%t" module {:extern "External.Class.Container"} ExternalClassContainer { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy index 48c223f62e6..0873aab5f42 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy @@ -1,4 +1,6 @@ -// RUN: %testDafnyForEachCompiler --refresh-exit-code=0 "%s" +// NONUNIFORM: Rust-specific tests +// RUN: %baredafny run --target=rs --enforce-determinism --input "%S/externalclasses.rs" "%s" > "%t" +// RUN: %diff "%s.expect" "%t" newtype uint8 = x: int | 0 <= x < 256 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy index 4edda6ead2b..75ad3fccc79 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype u8 = x: int | 0 <= x < 10 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy index 06db986522e..0d143414966 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/mapsubsets.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --unicode-char=false "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --unicode-char=false "%s" > "%t" // RUN: %diff "%s.expect" "%t" function Map(m: map): map { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy index 816c9ca9f03..20ca04e23ca 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/methods.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype NativeNotZero = x: int | 1 <= x < 255 witness 1 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/moduleordering.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/moduleordering.dfy index 543a05b0e48..e1d145a3473 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/moduleordering.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/moduleordering.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Test of the Rust compiler to ensure it emits modules in a deterministic order. -// RUN: %baredafny translate rs "%s" > "%t" +// RUN: %baredafny translate rs --enforce-determinism "%s" > "%t" // RUN: %OutputCheck --file-to-check "%S/moduleordering-rust/src/moduleordering.rs" "%s" // CHECK-L: pub mod A { // CHECK-L: pub mod B { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy index c8284779462..432c56071a2 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nestedmodules.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" // Checks that, despite module B being prefixed with A, there will be a "mod B" somewhere // and not an encoding like "mod A_B". diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy index fe08c8d50e0..2471201a45e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtype-set-comp.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Testing explicit newtype conversion of bounded ranges in Rust backend -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype uint8 = x: int | 0 <= x < 0x100 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy index 79f6a2ac4de..98377e2ab62 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy @@ -1,6 +1,6 @@ // NONUNIFORM: Test of Rust's ability to support newtypes -// RUN: %baredafny run -t:rs "%s" -// RUN: %baredafny run -t:rs --unicode-char=false "%s" +// RUN: %baredafny run -t:rs --enforce-determinism "%s" +// RUN: %baredafny run -t:rs --unicode-char=false --enforce-determinism "%s" /// %testDafnyForEachCompiler --refresh-exit-code=0 "%s" newtype int2 = x: int | -2 <= x < 2 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy index 572d54490b3..4adba11b7a4 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypesrefresh.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Test of Rust's ability to support newtypes -// RUN: %baredafny run -t:rs --type-system-refresh --general-newtypes "%s" +// RUN: %baredafny run -t:rs --type-system-refresh --general-newtypes --enforce-determinism "%s" newtype BoolWrapper = bool { const n: int := if this then 1 else 0 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nomaybeplacebos.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nomaybeplacebos.dfy index c1e2d2101ca..d4e006b9ce1 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nomaybeplacebos.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/nomaybeplacebos.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Test of the output of the Rust translation -// RUN: %baredafny translate rs "%s" > "%t" +// RUN: %baredafny translate rs --enforce-determinism "%s" > "%t" // RUN: %OutputCheck --file-to-check "%S/nomaybeplacebos-rust/src/nomaybeplacebos.rs" "%S/nomaybeplacebos.check" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy index 663b59551c4..534372f50ec 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/operators.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" ghost const TWO_TO_THE_8: int := 0x100 ghost const TWO_TO_THE_16: int := 0x10000 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy index e90b5bc69af..860de2db1d3 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/reserved-names.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Tests output of Rust translation from input Dafny that uses Rust reserved names -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" datatype X = diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy index e2dc2ed5615..0480566e84e 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/01-hash.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait Super { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy index e886248a139..67452b91abc 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/02-binary.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait Super { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy index 389e4cc8215..9f856cad7ad 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/03-methodnamed.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait Super { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy index c98e30d3ca6..3293982cb3f 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/04-mismatched.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait Super { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy index 5a6d276eb6f..cf535da2dce 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/05-coerce.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait Q { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy index 7da139919c9..0e26632e7b7 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/06-type-bounds.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --type-system-refresh --general-traits=datatype --general-newtypes "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=datatype --general-newtypes "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait SuperTrait { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy index 1e99245306a..50ffe337230 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/07-instantiated-methods.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait Super { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy index f94e3236e69..e345b09d519 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/08-not-all-trait-items-implemented.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait Reversible { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy index 022f03db2d1..4b364514a33 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/09-trait-method.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --emit-uncompilable-code "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --emit-uncompilable-code "%s" > "%t" datatype Super = Super diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy index 44b1a168f10..408f72063b8 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/strings.dfy @@ -1,8 +1,8 @@ // NONUNIFORM: Test of the output of the Rust translation -// RUN: %baredafny run --target=rs --unicode-char=true "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --unicode-char=true "%s" > "%t" // RUN: %diff "%s.expect" "%t" // RUN: %OutputCheck --file-to-check "%S/strings-rust/src/strings.rs" "%S/strings-unicode.check" -// RUN: %baredafny run --target=rs --unicode-char=false "%s" +// RUN: %baredafny run --target=rs --enforce-determinism --unicode-char=false "%s" // RUN: %diff "%s.expect" "%t" // RUN: %OutputCheck --file-to-check "%S/strings-rust/src/strings.rs" "%S/strings-utf16.check" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy index cad15372a6b..6a5f5d3febd 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/subsetconstraints.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" // RUN: %OutputCheck --file-to-check "%S/subsetconstraints-rust/src/subsetconstraints.rs" "%S/subsetconstraints.check" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/tests.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/tests.dfy index e431975b417..c1214daeb0a 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/tests.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/tests.dfy @@ -1,7 +1,7 @@ // NONUNIFORM: Test of the Dafny-to-Rust tests -// RUN: %baredafny test --target=rs "%s" > "%t" +// RUN: %baredafny test --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t -// RUN: %baredafny build --compile-suffix --target=rs "%s" > "%t" +// RUN: %baredafny build --compile-suffix --target=rs --enforce-determinism "%s" > "%t" // RUN: "%S/tests-rust/cargo" run -- Hello > "%t" // RUN: %diff "%s.main.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy index 42bffb89968..ada5639be1f 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --type-system-refresh --general-traits=datatype "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=datatype "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait SuperTrait { function GetBool(): bool diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy index 95f048cae4a..69dc1922d1d 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" module InterfaceHolder { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy index 75ee7a0c39c..7e84abc1143 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/type-test.dfy @@ -1,7 +1,7 @@ // NONUNIFORM: Tests that type tests work in the Rust backend -// RUN: %baredafny run --target=rs "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" -// RUN: %baredafny run --target=rs --raw-pointers "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --raw-pointers "%s" > "%t" // RUN: %diff "%s.expect" "%t" trait T { } From 384eae63b95280d823f0fa3c8addd519f0652987 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 7 Feb 2025 15:40:33 -0600 Subject: [PATCH 57/69] Fixed tests --- Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy | 7 ++++++- Source/DafnyCore/Backends/Rust/RustBackend.cs | 2 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 10 +++++++++- .../LitTests/LitTest/comp/rust/arrays.dfy.expect | 2 +- .../LitTest/comp/rust/classes-relax.dfy.wrong.expect | 2 +- .../LitTest/comp/rust/datatypes-scoping.dfy.expect | 2 +- .../TestFiles/LitTests/LitTest/comp/rust/lambda.dfy | 2 +- .../LitTests/LitTest/comp/rust/lambda.dfy.expect | 2 ++ .../LitTests/LitTest/comp/rust/loops.dfy.expect | 2 +- .../TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy | 2 +- .../comp/rust/small/10-type-parameter-equality.dfy | 2 +- .../LitTests/LitTest/comp/rust/traits.dfy.expect | 2 +- .../comp/rust/translate-additional/more_dafny.dfy | 2 +- 13 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 9006cb73091..c5b5462dffe 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -2118,11 +2118,16 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } + const rcDatatypeThis := rcNew(R.self.Clone()) + const borrowedRcDatatypeThis := R.Borrow(rcDatatypeThis) + // General borrow include &Box, but for dynamic dispatch we need &dyn Type function FromGeneralBorrowToSelfBorrow(onExpr: R.Expr, onExprOwnership: Ownership, env: Environment): R.Expr { if onExpr.Identifier? && env.NeedsAsRefForBorrow(onExpr.name) then onExpr.Sel("as_ref").Apply0() // It's not necessarily the trait, it's usually Box::as_ref or Rc::as_ref - else if onExprOwnership.OwnershipBorrowed? && onExpr != R.self then + else if onExpr == R.self || onExpr == rcDatatypeThis || onExpr == borrowedRcDatatypeThis then + R.self + else if onExprOwnership.OwnershipBorrowed? then // If the resulting expression is a borrow, e.g. &something() or datatype.field(), it means the trait was owned. // In our case we want dynamic dispatch, so we need to get the bare reference. // Because "on" is a general trait, we need to call as_ref() instead to get the bare expression diff --git a/Source/DafnyCore/Backends/Rust/RustBackend.cs b/Source/DafnyCore/Backends/Rust/RustBackend.cs index 4e517e72ede..4e351c0d0b2 100644 --- a/Source/DafnyCore/Backends/Rust/RustBackend.cs +++ b/Source/DafnyCore/Backends/Rust/RustBackend.cs @@ -59,7 +59,7 @@ protected override DafnyWrittenCodeGenerator CreateDafnyWrittenCompiler() { // Auto-init is not supported, fields have to be initialized. throw new UnsupportedInvalidOperationException( - "The Rust compiler requires `--enforce-determinism`. This requirement can"); + "The Rust compiler requires `--enforce-determinism`"); } return new RustCodeGenerator(Options); } diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 161070e2bb2..7dd608c0771 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -2452,7 +2452,9 @@ public RAST._IExpr FromGeneralBorrowToSelfBorrow(RAST._IExpr onExpr, Defs._IOwne { if (((onExpr).is_Identifier) && ((env).NeedsAsRefForBorrow((onExpr).dtor_name))) { return ((onExpr).Sel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply0(); - } else if (((onExprOwnership).is_OwnershipBorrowed) && (!object.Equals(onExpr, RAST.__default.self))) { + } else if (((object.Equals(onExpr, RAST.__default.self)) || (object.Equals(onExpr, (this).rcDatatypeThis))) || (object.Equals(onExpr, (this).borrowedRcDatatypeThis))) { + return RAST.__default.self; + } else if ((onExprOwnership).is_OwnershipBorrowed) { return (((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("convert"))).MSel(Dafny.Sequence.UnicodeFromString("AsRef"))).AsExpr()).FSel(Dafny.Sequence.UnicodeFromString("as_ref"))).Apply1(onExpr); } else { return onExpr; @@ -7407,6 +7409,12 @@ public RAST._IType AnyTrait { get { return RAST.Type.create_IntersectionType(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType(), (this).SyncSendType); } } } + public RAST._IExpr rcDatatypeThis { get { + return Dafny.Helpers.Id>((this).rcNew)((RAST.__default.self).Clone()); + } } + public RAST._IExpr borrowedRcDatatypeThis { get { + return RAST.__default.Borrow((this).rcDatatypeThis); + } } public RAST._IExpr read__mutable__field__macro { get { return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("read_field!"))).AsExpr(); } } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy.expect index 2f22d47cee8..3e2cf8d0f69 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/arrays.dfy.expect @@ -1,3 +1,3 @@ -Dafny program verifier finished with 3 verified, 0 errors +Dafny program verifier finished with 4 verified, 0 errors ok \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect index ecd5bfe4151..85b25e3a4d4 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/classes-relax.dfy.wrong.expect @@ -1,3 +1,3 @@ Dafny program verifier finished with 3 verified, 0 errors -(0,-1): Error: Microsoft.Dafny.UnsupportedInvalidOperationException: The Rust compiler does not support `--relax-definite-assignment` +(0,-1): Error: Microsoft.Dafny.UnsupportedInvalidOperationException: The Rust compiler requires `--enforce-determinism` diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect index 4fdc6d557bf..d2b9c221688 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect @@ -1,4 +1,4 @@ -Dafny program verifier finished with 0 verified, 0 errors +Dafny program verifier finished with 1 verified, 0 errors This is Dafny Hash This is Dafny hash 2 \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy index 0873aab5f42..503686ef470 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --enforce-determinism --input "%S/externalclasses.rs" "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" newtype uint8 = x: int | 0 <= x < 256 diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect index 27ba77ddaf6..3fa12358d12 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect @@ -1 +1,3 @@ + +Dafny program verifier finished with 3 verified, 0 errors true diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy.expect index 565ec0b036a..5740940b809 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/loops.dfy.expect @@ -1,4 +1,4 @@ -Dafny program verifier finished with 5 verified, 0 errors +Dafny program verifier finished with 6 verified, 0 errors hello world hello world{1} \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy index 98377e2ab62..b83173b10b7 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/newtypes.dfy @@ -141,7 +141,7 @@ method Main(){ print [0, 1, 2][Zero], "\n"; print [0, 1, 2][Zero..INT2_MAX], "\n"; var f: CodeUnit -> byte := c => c as byte; - var arr := new bool[INT2_MAX]; + var arr := new bool[INT2_MAX](i => true); print arr.Length, "\n"; print DChar as uint32, "\n"; diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy index a41ea691202..0c57025a656 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/small/10-type-parameter-equality.dfy @@ -1,5 +1,5 @@ // NONUNIFORM: Rust-specific tests -// RUN: %baredafny run --target=rs --emit-uncompilable-code --type-system-refresh --general-traits=full "%s" > "%t" +// RUN: %baredafny run --target=rs --enforce-determinism --type-system-refresh --general-traits=full "%s" > "%t" // RUN: %diff "%s.expect" "%t" datatype I_ = I_(t: T, u: U) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect index 506e5ca1d4c..6dc0be4af2c 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits.dfy.expect @@ -1,3 +1,3 @@ -Dafny program verifier finished with 21 verified, 0 errors +Dafny program verifier finished with 23 verified, 0 errors Main passed all the tests diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/translate-additional/more_dafny.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/translate-additional/more_dafny.dfy index c55fc26cb3f..f51583bc45b 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/translate-additional/more_dafny.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/translate-additional/more_dafny.dfy @@ -1,4 +1,4 @@ -// RUN: %baredafny translate rs --rust-module-name additional_module "%S/more_dafny_extern.rs" "%s" +// RUN: %baredafny translate rs --enforce-determinism --rust-module-name additional_module "%S/more_dafny_extern.rs" "%s" // RUN: %exits-with -any %rm -f "%S/project_depending_on_dafny/src/additional_module.rs" // RUN: %exits-with -any %rm -f "%S/project_depending_on_dafny/src/more_dafny_extern.rs" // RUN: %mv "%S/more_dafny-rust/src/more_dafny.rs" "%S/project_depending_on_dafny/src/additional_module.rs" From d928f2fbccbcffd519b19ee2aac15cadd0c6a1c9 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Mon, 10 Feb 2025 17:07:59 -0600 Subject: [PATCH 58/69] Removed definite assignment change. --- Source/DafnyCore/Verifier/BoogieGenerator.DefiniteAssignment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DafnyCore/Verifier/BoogieGenerator.DefiniteAssignment.cs b/Source/DafnyCore/Verifier/BoogieGenerator.DefiniteAssignment.cs index 9ac6e4d7fdf..ac55f79634b 100644 --- a/Source/DafnyCore/Verifier/BoogieGenerator.DefiniteAssignment.cs +++ b/Source/DafnyCore/Verifier/BoogieGenerator.DefiniteAssignment.cs @@ -30,7 +30,7 @@ bool NeedsDefiniteAssignmentTracker(bool isGhost, Type type, bool isField) { (options.DefiniteAssignmentLevel == 4 && isField && !options.ForbidNondeterminism)) { if (isGhost && type.IsNonempty) { return false; - } else if (!isGhost && type.HasCompilableValue && options.DefiniteAssignmentLevel == 1) { + } else if (!isGhost && type.HasCompilableValue) { return false; } } From c044738facf479d4ee5ab25ae71d7638cba19894 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Tue, 11 Feb 2025 08:01:22 -0600 Subject: [PATCH 59/69] Fixed an issue --- Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy | 1 + Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 1 + .../LitTests/LitTest/comp/rust/datatypes-scoping.dfy | 4 ++++ .../LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index c5b5462dffe..35db6368953 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -2183,6 +2183,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } else { // The self type of any other type is borrowed onExpr, recOwnership, recIdents := GenExpr(on, selfIdent, env, OwnershipBorrowed); + onExpr := FromGeneralBorrowToSelfBorrow(onExpr, recOwnership, env); readIdents := readIdents + recIdents; } r := fullPath.ApplyType(onTypeExprs).FSel(escapeName(name.name)).ApplyType(typeExprs).Apply([onExpr] + argExprs); diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 7dd608c0771..2211a97cc87 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -2541,6 +2541,7 @@ public void GenCall(DAST._IExpression @on, Defs._ISelfInfo selfIdent, DAST._ICal _9_onExpr = _out15; _10_recOwnership = _out16; _11_recIdents = _out17; + _9_onExpr = (this).FromGeneralBorrowToSelfBorrow(_9_onExpr, _10_recOwnership, env); readIdents = Dafny.Set>.Union(readIdents, _11_recIdents); } r = ((((_7_fullPath).ApplyType(_8_onTypeExprs)).FSel(Defs.__default.escapeName((name).dtor_name))).ApplyType(_2_typeExprs)).Apply(Dafny.Sequence.Concat(Dafny.Sequence.FromElements(_9_onExpr), _0_argExprs)); diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy index 13ef7682d63..a4abdb8d3b5 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy @@ -12,6 +12,10 @@ datatype Loop2 = Loop2(loop: Loop) { method hash() { print "\nThis is Dafny hash 2"; } + + method doHash() { + hash(); + } } method Main() { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect index d2b9c221688..9f527b44866 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/datatypes-scoping.dfy.expect @@ -1,4 +1,4 @@ -Dafny program verifier finished with 1 verified, 0 errors +Dafny program verifier finished with 2 verified, 0 errors This is Dafny Hash This is Dafny hash 2 \ No newline at end of file From 00f72655ba6616dc6e41aa6432e1e484ef2243be Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Wed, 12 Feb 2025 14:15:20 -0600 Subject: [PATCH 60/69] Fixed a test --- Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy | 2 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 35db6368953..f30262b6ca8 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -3366,7 +3366,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { assert expectedOwnership == OwnershipBorrowed; var needsRcWrapping := isSelf && selfIdent.IsRcWrappedDatatype(); if needsRcWrapping { - r := rcNew(r.Clone()); + r := R.Borrow(rcNew(r.Clone())); } resultingOwnership := OwnershipBorrowed; } else { diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 2211a97cc87..79d0dc6ba69 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -4621,7 +4621,7 @@ public void GenIdent(Dafny.ISequence rName, Defs._ISelfInfo selfIden bool _10_needsRcWrapping; _10_needsRcWrapping = (_4_isSelf) && ((selfIdent).IsRcWrappedDatatype()); if (_10_needsRcWrapping) { - r = Dafny.Helpers.Id>((this).rcNew)((r).Clone()); + r = RAST.__default.Borrow(Dafny.Helpers.Id>((this).rcNew)((r).Clone())); } resultingOwnership = Defs.Ownership.create_OwnershipBorrowed(); } else { From 3390b6d997f85036f83359e94b98ab56d088182f Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Thu, 13 Feb 2025 09:36:51 -0600 Subject: [PATCH 61/69] Fixed hopefully all tests --- Source/DafnyCore/Backends/Rust/RustBackend.cs | 13 ------------- .../DafnyCore/Backends/Rust/RustCodeGenerator.cs | 14 ++++++++++++++ .../LitTests/LitTest/comp/rust/autoinit.dfy | 2 +- .../LitTests/LitTest/comp/rust/autoinit.dfy.expect | 5 ++--- .../LitTest/comp/rust/avoid_soundness_mut.dfy | 2 +- .../LitTests/LitTest/comp/rust/docstring.check | 3 ++- .../LitTests/LitTest/comp/rust/docstring.dfy | 4 ++++ .../LitTests/LitTest/git-issues/git-issue-5644.dfy | 3 +-- .../LitTest/git-issues/git-issue-5644.dfy.expect | 5 +---- ...consistentCompilerBehavior.dfy.testdafny.expect | 7 ------- .../TestBeyondVerifierExpect.dfy.testdafny.expect | 7 ------- 11 files changed, 26 insertions(+), 39 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/RustBackend.cs b/Source/DafnyCore/Backends/Rust/RustBackend.cs index 4e351c0d0b2..6e948c748b8 100644 --- a/Source/DafnyCore/Backends/Rust/RustBackend.cs +++ b/Source/DafnyCore/Backends/Rust/RustBackend.cs @@ -48,19 +48,6 @@ public override string TargetBaseDir(string dafnyProgramName) => $"{Path.GetFileNameWithoutExtension(dafnyProgramName)}-rust/src"; protected override DafnyWrittenCodeGenerator CreateDafnyWrittenCompiler() { - if (!Options.Get(CommonOptionBag.EnforceDeterminism)) { - // DEV: This requirement could be lifted in the future if - // BoogieGenerator.DefiniteAssignment.cs: - // the line - // if (!isGhost && type.HasCompilableValue) { - // could become - // if (!isGhost && type.HasCompilableValue && options.DefiniteAssignmentLevel == 1) { - // Meaning that the default behavior for fields and array initialization is the same as for local variables: - // Auto-init is not supported, fields have to be initialized. - - throw new UnsupportedInvalidOperationException( - "The Rust compiler requires `--enforce-determinism`"); - } return new RustCodeGenerator(Options); } diff --git a/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs b/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs index b3a35ea5f96..10424e22074 100644 --- a/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs +++ b/Source/DafnyCore/Backends/Rust/RustCodeGenerator.cs @@ -39,6 +39,20 @@ public override void Compile(Sequence program, Sequence "%t" +// RUN: %exits-with 2 %baredafny run %args --enforce-determinism --target=rs "%s" > "%t" // RUN: %diff "%s.expect" "%t" class Test { diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy.expect index 37c2ed71ea8..2d4b7485fd5 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/autoinit.dfy.expect @@ -1,3 +1,2 @@ - -Dafny program verifier finished with 2 verified, 0 errors -(0,-1): Error: Microsoft.Dafny.UnsupportedInvalidOperationException: Creation of object of type Test requires a constructor +autoinit.dfy(5,6): Error: since fields are initialized arbitrarily, constructor-less classes are forbidden by the --enforce-determinism option +1 resolution/type errors detected in autoinit.dfy diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy index b653ca6e830..0c9cc1c045b 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/avoid_soundness_mut.dfy @@ -1,7 +1,7 @@ // RUN: %baredafny build -t:rs --enforce-determinism "%s" // RUN: "%S/avoid_soundness_mut-rust/cargo" run --release > "%t" // RUN: %diff "%s.expect" "%t" -// RUN: %baredafny build -t:rs --raw-pointers "%s" +// RUN: %baredafny build -t:rs --enforce-determinism --raw-pointers "%s" // RUN: "%S/avoid_soundness_mut-rust/cargo" run --release > "%t" // RUN: %diff "%s.expect" "%t" diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.check b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.check index 729d2cd907b..3104041c564 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.check +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.check @@ -13,5 +13,6 @@ // CHECK: .*/// Docstring for module.* // CHECK: .*/// Docstring for classes 2.* // CHECK: .*/// Allocates an UNINITIALIZED instance. Only the Dafny compiler should use that.* +// CHECK: .*/// Docstring for class constructor.* // CHECK: .*/// Docstring for predicate.* -// CHECK: .*/// Docstring for const.* +// CHECK: .*/// Docstring for const.* \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy index 45747b185b9..6b150021094 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/docstring.dfy @@ -44,6 +44,10 @@ module SubModule { class TestClass { /** Docstring for const */ const testConst: bool + /** Docstring for class constructor */ + constructor() { + testConst := true; + } predicate SingleLineFunction() { true } // Docstring for predicate } } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy index 5be7c59ea24..c1acad3ecce 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy @@ -1,9 +1,8 @@ // NONUNIFORM: Testing robustness of Dafny/Rust backends wrt set comprehension -// RUN: %baredafny -noVerify -compileTarget:rs -compile:0 -functionSyntax:3 -spillTargetCode:3 "%s" > "%t" +// RUN: %baredafny build --function-syntax:3 --target:rs --enforce-determinism "%s" > "%t" // RUN: %diff "%s.expect" "%t" module Spoo { - newtype uint8 = x: int | 0 <= x < 0x100 newtype uint16 = x: int | 0 <= x < 0x10000 function method UInt16ToSeq(x: uint16): (ret: seq) diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy.expect index 39be9965f21..ba00363fc08 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5644.dfy.expect @@ -1,5 +1,2 @@ -Warning: this way of using the CLI is deprecated. Use 'dafny --help' to see help for the new Dafny CLI format -Dafny program verifier did not attempt verification -Wrote textual form of target program to git-issue-5644-rust/src/git_issue_5644.rs -Additional output written to git-issue-5644-rust/src/git-issue-5644-rs.dtr +Dafny program verifier finished with 4 verified, 0 errors diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/InconsistentCompilerBehavior.dfy.testdafny.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/InconsistentCompilerBehavior.dfy.testdafny.expect index 7e24d9e430a..8a9c5026e3f 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/InconsistentCompilerBehavior.dfy.testdafny.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/InconsistentCompilerBehavior.dfy.testdafny.expect @@ -44,11 +44,4 @@ Diff (changing expected into actual): Executing on C++... Executing on Rust... -AssertEqualWithDiff() Failure -Diff (changing expected into actual): --Different than any output -+0 - - -(non-blocking) The Rust code generator is internal. Not having a '*.rs.check' file is acceptable for now. Executing on ResolvedDesugaredExecutableDafny... diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/TestBeyondVerifierExpect.dfy.testdafny.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/TestBeyondVerifierExpect.dfy.testdafny.expect index a881545e3bb..18486ce88ce 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/TestBeyondVerifierExpect.dfy.testdafny.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/metatests/TestBeyondVerifierExpect.dfy.testdafny.expect @@ -44,11 +44,4 @@ Diff (changing expected into actual): Executing on C++... Executing on Rust... -AssertEqualWithDiff() Failure -Diff (changing expected into actual): --good bye -+hello - - -(non-blocking) The Rust code generator is internal. Not having a '*.rs.check' file is acceptable for now. Executing on ResolvedDesugaredExecutableDafny... From 644c05a12a7357c447ab1453b59ebfe08fcca160 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Thu, 13 Feb 2025 21:24:56 -0600 Subject: [PATCH 62/69] Fixed a verification issue --- .../DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy | 7 +++++-- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 12 ++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index f30262b6ca8..6b4dcd2fb70 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -86,6 +86,9 @@ module {:extern "DCOMP"} DafnyToRustCompiler { this.optimizations := [ ExpressionOptimization.apply, FactorPathsOptimization.apply(thisFile)]; + var thisAsSelf := rcNew(R.self.Clone()); + this.rcDatatypeThis := thisAsSelf; + this.borrowedRcDatatypeThis := R.Borrow(thisAsSelf); new; } @@ -2118,8 +2121,8 @@ module {:extern "DCOMP"} DafnyToRustCompiler { } } - const rcDatatypeThis := rcNew(R.self.Clone()) - const borrowedRcDatatypeThis := R.Borrow(rcDatatypeThis) + const rcDatatypeThis: R.Expr + const borrowedRcDatatypeThis: R.Expr // General borrow include &Box, but for dynamic dispatch we need &dyn Type function FromGeneralBorrowToSelfBorrow(onExpr: R.Expr, onExprOwnership: Ownership, env: Environment): R.Expr { diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 79d0dc6ba69..a3d4357b305 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -23,6 +23,8 @@ public COMP() { this._charType = Defs.CharType.Default(); this._pointerType = Defs.PointerType.Default(); this._syncType = Defs.SyncType.Default(); + this._rcDatatypeThis = RAST.Expr.Default(); + this._borrowedRcDatatypeThis = RAST.Expr.Default(); } public RAST._IType Object(RAST._IType underlying) { if (((this).pointerType).is_Raw) { @@ -41,6 +43,10 @@ public void __ctor(Defs._ICharType charType, Defs._IPointerType pointerType, Def (this)._syncType = syncType; (this).error = Std.Wrappers.Option>.create_None(); (this).optimizations = Dafny.Sequence>.FromElements(ExpressionOptimization.__default.apply, FactorPathsOptimization.__default.apply((this).thisFile)); + RAST._IExpr _0_thisAsSelf; + _0_thisAsSelf = Dafny.Helpers.Id>((this).rcNew)((RAST.__default.self).Clone()); + (this)._rcDatatypeThis = _0_thisAsSelf; + (this)._borrowedRcDatatypeThis = RAST.__default.Borrow(_0_thisAsSelf); } public bool HasAttribute(Dafny.ISequence attributes, Dafny.ISequence name) { @@ -7410,11 +7416,13 @@ public RAST._IType AnyTrait { get { return RAST.Type.create_IntersectionType(((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("Any"))).AsType(), (this).SyncSendType); } } } + public RAST._IExpr _rcDatatypeThis {get; set;} public RAST._IExpr rcDatatypeThis { get { - return Dafny.Helpers.Id>((this).rcNew)((RAST.__default.self).Clone()); + return this._rcDatatypeThis; } } + public RAST._IExpr _borrowedRcDatatypeThis {get; set;} public RAST._IExpr borrowedRcDatatypeThis { get { - return RAST.__default.Borrow((this).rcDatatypeThis); + return this._borrowedRcDatatypeThis; } } public RAST._IExpr read__mutable__field__macro { get { return ((RAST.__default.dafny__runtime).MSel(Dafny.Sequence.UnicodeFromString("read_field!"))).AsExpr(); From d8482233c9f7ff4e0d3997c9344f0b7636cee26c Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 14 Feb 2025 09:42:14 -0600 Subject: [PATCH 63/69] Change in verification --- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 36 ++++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index a3d4357b305..1e79fe67cd9 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -464,13 +464,13 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _out8 = (this).GenType(_13_typeArg, Defs.GenTypeContext.@default()); _15_rTypeArg = _out8; if ((_6_usedTypeParams).Contains((_14_typeParam).dtor_name)) { - goto continue_1; + goto continue_0; } _4_fields = Dafny.Sequence.Concat(_4_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(_12_typeParamI)), RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_15_rTypeArg)))))); _5_fieldInits = Dafny.Sequence.Concat(_5_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_12_typeParamI)), (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsExpr()))); - continue_1: ; + continue_0: ; } - after_1: ; + after_0: ; Dafny.ISequence _16_className; Defs._IExternAttribute _17_extern; Dafny.ISequence _out9; @@ -1134,7 +1134,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _54_types = Dafny.Sequence.Concat(_54_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_59_rTypeArg)))); if (((_55_typeI) < (new BigInteger((_7_typeParamInfos).Count))) && ((((_7_typeParamInfos).Select(_55_typeI)).dtor_variance).is_Nonvariant)) { _48_coerceTypes = Dafny.Sequence.Concat(_48_coerceTypes, Dafny.Sequence.FromElements(_59_rTypeArg)); - goto continue_2; + goto continue_2_0; } DAST._ITypeArgDecl _60_coerceTypeParam; DAST._ITypeArgDecl _61_dt__update__tmp_h0 = _56_typeParam; @@ -1159,9 +1159,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _66_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_55_typeI)); _53_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_53_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_59_rTypeArg, _65_rCoerceType), (RAST.Expr.create_Identifier(_66_coerceFormal)).Clone()))); _50_coerceArguments = Dafny.Sequence.Concat(_50_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_66_coerceFormal, Dafny.Helpers.Id>((this).rc)(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_59_rTypeArg), _65_rCoerceType)), RAST.__default.StaticTrait))))); - continue_2: ; + continue_2_0: ; } - after_2: ; + after_2_0: ; if ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1) { _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_67_tpe) => { return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _67_tpe); @@ -1225,7 +1225,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) DAST._IType _82_c; _82_c = ((c).dtor_superTraitTypes).Select(_81_i); if ((((_82_c).is_UserDefined) && ((((_82_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_82_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { - goto continue_3; + goto continue_3_0; } RAST._IType _83_cType; RAST._IType _out19; @@ -1243,9 +1243,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } else { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_85_downcastImplementationsOpt).dtor_value)); } - continue_3: ; + continue_3_0: ; } - after_3: ; + after_3_0: ; } Dafny.ISequence _87_printImplBodyCases; _87_printImplBodyCases = Dafny.Sequence.FromElements(); @@ -2249,13 +2249,13 @@ public void GenStmts(Dafny.ISequence stmts, Defs._ISelfInfo se readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_18_recIdents, _0_declarations)); generated = (generated).Then(_17_stmtExpr); if ((_17_stmtExpr).is_Return) { - goto after_4; + goto after_0; } _1_i = (_1_i) + (BigInteger.One); } - continue_4: ; + continue_0: ; } - after_4: ; + after_0: ; } public void GenDeclareVarAssign(Dafny.ISequence name, DAST._IType typ, DAST._IExpression rhs, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, out RAST._IExpr generated, out Dafny.ISet> readIdents, out Defs._IEnvironment newEnv) { @@ -2998,7 +2998,7 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _80_param; _80_param = ((_74_oldEnv).dtor_names).Select(_79_paramI); if ((_80_param).Equals(Dafny.Sequence.UnicodeFromString("_accumulator"))) { - goto continue_5; + goto continue_4_0; } RAST._IExpr _81_paramInit; Defs._IOwnership _82___v43; @@ -3020,9 +3020,9 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv newEnv = (newEnv).AddAssigned(_84_recVar, _85_declaredType); } _78_loopBegin = (_78_loopBegin).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _80_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_84_recVar)))); - continue_5: ; + continue_4_0: ; } - after_5: ; + after_4_0: ; RAST._IExpr _86_bodyExpr; Dafny.ISet> _87_bodyIdents; Defs._IEnvironment _88_bodyEnv; @@ -7196,7 +7196,7 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul BigInteger _hi2 = new BigInteger(((_5_allModules).dtor_keys).Count); for (BigInteger _8_i = BigInteger.Zero; _8_i < _hi2; _8_i++) { if (!((_5_allModules).dtor_values).Contains(((_5_allModules).dtor_keys).Select(_8_i))) { - goto continue_6; + goto continue_0; } RAST._IMod _9_m; _9_m = (Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select((_5_allModules).dtor_values,((_5_allModules).dtor_keys).Select(_8_i))).ToRust(); @@ -7206,9 +7206,9 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul } s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("\n")); s = Dafny.Sequence.Concat(s, (_9_m)._ToString(Dafny.Sequence.UnicodeFromString(""))); - continue_6: ; + continue_0: ; } - after_6: ; + after_0: ; return s; } public Dafny.ISequence EmitCallToMain(DAST._IExpression companion, Dafny.ISequence mainMethodName, bool hasArgs) From a1d92de008bb081a10a6849e6cded777cd75a09c Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 14 Feb 2025 16:38:00 -0600 Subject: [PATCH 64/69] Fixed a warning in generated code + support for printing functions --- .../Backends/Rust/Dafny-compiler-rust.dfy | 2 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 38 +++++++++---------- .../DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 2 +- .../LitTests/LitTest/comp/rust/lambda.dfy | 4 +- .../LitTest/comp/rust/lambda.dfy.expect | 1 + 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 6b4dcd2fb70..228bc628aef 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -3629,10 +3629,10 @@ module {:extern "DCOMP"} DafnyToRustCompiler { var typeExpr := GenType(typeArgs[i], GenTypeContext.default()); genTypeArgs := genTypeArgs + [typeExpr]; } + r := r.FSel(escapeName(variant)); if |typeArgs| > 0 { r := r.ApplyType(genTypeArgs); } - r := r.FSel(escapeName(variant)); readIdents := {}; var assignments: seq := []; diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index 1e79fe67cd9..ab112b952c1 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -464,13 +464,13 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _out8 = (this).GenType(_13_typeArg, Defs.GenTypeContext.@default()); _15_rTypeArg = _out8; if ((_6_usedTypeParams).Contains((_14_typeParam).dtor_name)) { - goto continue_0; + goto continue_1; } _4_fields = Dafny.Sequence.Concat(_4_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(_12_typeParamI)), RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_15_rTypeArg)))))); _5_fieldInits = Dafny.Sequence.Concat(_5_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_12_typeParamI)), (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsExpr()))); - continue_0: ; + continue_1: ; } - after_0: ; + after_1: ; Dafny.ISequence _16_className; Defs._IExternAttribute _17_extern; Dafny.ISequence _out9; @@ -1134,7 +1134,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _54_types = Dafny.Sequence.Concat(_54_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_59_rTypeArg)))); if (((_55_typeI) < (new BigInteger((_7_typeParamInfos).Count))) && ((((_7_typeParamInfos).Select(_55_typeI)).dtor_variance).is_Nonvariant)) { _48_coerceTypes = Dafny.Sequence.Concat(_48_coerceTypes, Dafny.Sequence.FromElements(_59_rTypeArg)); - goto continue_2_0; + goto continue_2; } DAST._ITypeArgDecl _60_coerceTypeParam; DAST._ITypeArgDecl _61_dt__update__tmp_h0 = _56_typeParam; @@ -1159,9 +1159,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _66_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_55_typeI)); _53_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_53_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_59_rTypeArg, _65_rCoerceType), (RAST.Expr.create_Identifier(_66_coerceFormal)).Clone()))); _50_coerceArguments = Dafny.Sequence.Concat(_50_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_66_coerceFormal, Dafny.Helpers.Id>((this).rc)(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_59_rTypeArg), _65_rCoerceType)), RAST.__default.StaticTrait))))); - continue_2_0: ; + continue_2: ; } - after_2_0: ; + after_2: ; if ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1) { _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_67_tpe) => { return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _67_tpe); @@ -1225,7 +1225,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) DAST._IType _82_c; _82_c = ((c).dtor_superTraitTypes).Select(_81_i); if ((((_82_c).is_UserDefined) && ((((_82_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_82_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { - goto continue_3_0; + goto continue_3; } RAST._IType _83_cType; RAST._IType _out19; @@ -1243,9 +1243,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } else { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_85_downcastImplementationsOpt).dtor_value)); } - continue_3_0: ; + continue_3: ; } - after_3_0: ; + after_3: ; } Dafny.ISequence _87_printImplBodyCases; _87_printImplBodyCases = Dafny.Sequence.FromElements(); @@ -2249,13 +2249,13 @@ public void GenStmts(Dafny.ISequence stmts, Defs._ISelfInfo se readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_18_recIdents, _0_declarations)); generated = (generated).Then(_17_stmtExpr); if ((_17_stmtExpr).is_Return) { - goto after_0; + goto after_4; } _1_i = (_1_i) + (BigInteger.One); } - continue_0: ; + continue_4: ; } - after_0: ; + after_4: ; } public void GenDeclareVarAssign(Dafny.ISequence name, DAST._IType typ, DAST._IExpression rhs, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, out RAST._IExpr generated, out Dafny.ISet> readIdents, out Defs._IEnvironment newEnv) { @@ -2998,7 +2998,7 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _80_param; _80_param = ((_74_oldEnv).dtor_names).Select(_79_paramI); if ((_80_param).Equals(Dafny.Sequence.UnicodeFromString("_accumulator"))) { - goto continue_4_0; + goto continue_5; } RAST._IExpr _81_paramInit; Defs._IOwnership _82___v43; @@ -3020,9 +3020,9 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv newEnv = (newEnv).AddAssigned(_84_recVar, _85_declaredType); } _78_loopBegin = (_78_loopBegin).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _80_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_84_recVar)))); - continue_4_0: ; + continue_5: ; } - after_4_0: ; + after_5: ; RAST._IExpr _86_bodyExpr; Dafny.ISet> _87_bodyIdents; Defs._IEnvironment _88_bodyEnv; @@ -5125,10 +5125,10 @@ public void GenExpr(DAST._IExpression e, Defs._ISelfInfo selfIdent, Defs._IEnvir _54_typeExpr = _out49; _52_genTypeArgs = Dafny.Sequence.Concat(_52_genTypeArgs, Dafny.Sequence.FromElements(_54_typeExpr)); } + r = (r).FSel(Defs.__default.escapeName(_49_variant)); if ((new BigInteger((_48_typeArgs).Count)).Sign == 1) { r = (r).ApplyType(_52_genTypeArgs); } - r = (r).FSel(Defs.__default.escapeName(_49_variant)); readIdents = Dafny.Set>.FromElements(); Dafny.ISequence _55_assignments; _55_assignments = Dafny.Sequence.FromElements(); @@ -7196,7 +7196,7 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul BigInteger _hi2 = new BigInteger(((_5_allModules).dtor_keys).Count); for (BigInteger _8_i = BigInteger.Zero; _8_i < _hi2; _8_i++) { if (!((_5_allModules).dtor_values).Contains(((_5_allModules).dtor_keys).Select(_8_i))) { - goto continue_0; + goto continue_6; } RAST._IMod _9_m; _9_m = (Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select((_5_allModules).dtor_values,((_5_allModules).dtor_keys).Select(_8_i))).ToRust(); @@ -7206,9 +7206,9 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul } s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("\n")); s = Dafny.Sequence.Concat(s, (_9_m)._ToString(Dafny.Sequence.UnicodeFromString(""))); - continue_0: ; + continue_6: ; } - after_0: ; + after_6: ; return s; } public Dafny.ISequence EmitCallToMain(DAST._IExpression companion, Dafny.ISequence mainMethodName, bool hasArgs) diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index e25385608fc..43c65e42573 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -2088,7 +2088,7 @@ macro_rules! dafny_print_function { // Convert the DafnyPrint above into a macro so that we can create it for functions of any input arity macro_rules! dafny_print_function { ($($n:tt)*) => { - impl $crate::DafnyPrint for $crate::Rc B> { + impl $crate::DafnyPrint for $crate::Rc B> { fn fmt_print(&self, f: &mut ::std::fmt::Formatter<'_>, _in_seq: bool) -> ::std::fmt::Result { write!(f, "") } diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy index 503686ef470..0fc3c6f25e0 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy @@ -21,5 +21,7 @@ predicate p'(b: seq) { if |b| > 0 then !b[0] else false } predicate X''() { F'(p') } method Main() { - print Fn((a: uint8, b: uint8) => a == b, 2 as uint8), "\n"; + var f := (a: uint8, b: uint8) => a == b; + print f, "\n"; + print Fn(f, 2 as uint8), "\n"; } \ No newline at end of file diff --git a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect index 3fa12358d12..eb269495cdd 100644 --- a/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect +++ b/Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/lambda.dfy.expect @@ -1,3 +1,4 @@ Dafny program verifier finished with 3 verified, 0 errors + true From 04098e937e891f364f0efdc376f1c493ea824b32 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Tue, 18 Feb 2025 15:10:23 -0600 Subject: [PATCH 65/69] merge fixup --- .../Backends/Rust/Dafny-compiler-rust.dfy | 2 +- Source/DafnyCore/GeneratedFromDafny/DCOMP.cs | 36 +++++++++---------- Source/DafnyRuntime/DafnyRuntimeRust/Makefile | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy index 228bc628aef..a018fb5b39c 100644 --- a/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy +++ b/Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy @@ -2316,7 +2316,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler { readIdents := readIdents + thnIdents; var els, elsIdents, elsEnv := GenStmts(elsDafny, selfIdent, env, isLast, earlyReturn); readIdents := readIdents + elsIdents; - + // All variables that both thnEnv and elsEnv remove can be removed from the environment newEnv := env.Join(thnEnv, elsEnv); generated := R.IfExpr(cond, thn, els); diff --git a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs index ab112b952c1..5ec3c109194 100644 --- a/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs +++ b/Source/DafnyCore/GeneratedFromDafny/DCOMP.cs @@ -464,13 +464,13 @@ public void GetName(Dafny.ISequence attributes, Dafny.ISequenc _out8 = (this).GenType(_13_typeArg, Defs.GenTypeContext.@default()); _15_rTypeArg = _out8; if ((_6_usedTypeParams).Contains((_14_typeParam).dtor_name)) { - goto continue_1; + goto continue_0; } _4_fields = Dafny.Sequence.Concat(_4_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(_12_typeParamI)), RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_15_rTypeArg)))))); _5_fieldInits = Dafny.Sequence.Concat(_5_fieldInits, Dafny.Sequence.FromElements(RAST.AssignIdentifier.create(Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("_phantom_type_param_"), Std.Strings.__default.OfNat(_12_typeParamI)), (((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsExpr()))); - continue_1: ; + continue_0: ; } - after_1: ; + after_0: ; Dafny.ISequence _16_className; Defs._IExternAttribute _17_extern; Dafny.ISequence _out9; @@ -1134,7 +1134,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _54_types = Dafny.Sequence.Concat(_54_types, Dafny.Sequence.FromElements(RAST.Type.create_TypeApp((((RAST.__default.std).MSel(Dafny.Sequence.UnicodeFromString("marker"))).MSel(Dafny.Sequence.UnicodeFromString("PhantomData"))).AsType(), Dafny.Sequence.FromElements(_59_rTypeArg)))); if (((_55_typeI) < (new BigInteger((_7_typeParamInfos).Count))) && ((((_7_typeParamInfos).Select(_55_typeI)).dtor_variance).is_Nonvariant)) { _48_coerceTypes = Dafny.Sequence.Concat(_48_coerceTypes, Dafny.Sequence.FromElements(_59_rTypeArg)); - goto continue_2; + goto continue_2_0; } DAST._ITypeArgDecl _60_coerceTypeParam; DAST._ITypeArgDecl _61_dt__update__tmp_h0 = _56_typeParam; @@ -1159,9 +1159,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) _66_coerceFormal = Dafny.Sequence.Concat(Dafny.Sequence.UnicodeFromString("f_"), Std.Strings.__default.OfNat(_55_typeI)); _53_coerceMapToArg = Dafny.Map<_System._ITuple2, RAST._IExpr>.Merge(_53_coerceMapToArg, Dafny.Map<_System._ITuple2, RAST._IExpr>.FromElements(new Dafny.Pair<_System._ITuple2, RAST._IExpr>(_System.Tuple2.create(_59_rTypeArg, _65_rCoerceType), (RAST.Expr.create_Identifier(_66_coerceFormal)).Clone()))); _50_coerceArguments = Dafny.Sequence.Concat(_50_coerceArguments, Dafny.Sequence.FromElements(RAST.Formal.create(_66_coerceFormal, Dafny.Helpers.Id>((this).rc)(RAST.Type.create_IntersectionType(RAST.Type.create_ImplType(RAST.Type.create_FnType(Dafny.Sequence.FromElements(_59_rTypeArg), _65_rCoerceType)), RAST.__default.StaticTrait))))); - continue_2: ; + continue_2_0: ; } - after_2: ; + after_2_0: ; if ((new BigInteger((_21_unusedTypeParams).Count)).Sign == 1) { _6_ctors = Dafny.Sequence.Concat(_6_ctors, Dafny.Sequence.FromElements(RAST.EnumCase.create(Dafny.Sequence.UnicodeFromString(""), Dafny.Sequence.UnicodeFromString("_PhantomVariant"), RAST.Fields.create_NamelessFields(Std.Collections.Seq.__default.Map(((System.Func)((_67_tpe) => { return RAST.NamelessField.create(RAST.Visibility.create_PRIV(), _67_tpe); @@ -1225,7 +1225,7 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) DAST._IType _82_c; _82_c = ((c).dtor_superTraitTypes).Select(_81_i); if ((((_82_c).is_UserDefined) && ((((_82_c).dtor_resolved).dtor_kind).is_Trait)) && ((new BigInteger((((_82_c).dtor_resolved).dtor_extendedTypes).Count)).Sign == 0)) { - goto continue_3; + goto continue_3_0; } RAST._IType _83_cType; RAST._IType _out19; @@ -1243,9 +1243,9 @@ public RAST._IExpr writeStr(Dafny.ISequence s, bool final) } else { s = Dafny.Sequence.Concat(s, Dafny.Sequence.FromElements((_85_downcastImplementationsOpt).dtor_value)); } - continue_3: ; + continue_3_0: ; } - after_3: ; + after_3_0: ; } Dafny.ISequence _87_printImplBodyCases; _87_printImplBodyCases = Dafny.Sequence.FromElements(); @@ -2249,13 +2249,13 @@ public void GenStmts(Dafny.ISequence stmts, Defs._ISelfInfo se readIdents = Dafny.Set>.Union(readIdents, Dafny.Set>.Difference(_18_recIdents, _0_declarations)); generated = (generated).Then(_17_stmtExpr); if ((_17_stmtExpr).is_Return) { - goto after_4; + goto after_0; } _1_i = (_1_i) + (BigInteger.One); } - continue_4: ; + continue_0: ; } - after_4: ; + after_0: ; } public void GenDeclareVarAssign(Dafny.ISequence name, DAST._IType typ, DAST._IExpression rhs, Defs._ISelfInfo selfIdent, Defs._IEnvironment env, out RAST._IExpr generated, out Dafny.ISet> readIdents, out Defs._IEnvironment newEnv) { @@ -2998,7 +2998,7 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv Dafny.ISequence _80_param; _80_param = ((_74_oldEnv).dtor_names).Select(_79_paramI); if ((_80_param).Equals(Dafny.Sequence.UnicodeFromString("_accumulator"))) { - goto continue_5; + goto continue_4_0; } RAST._IExpr _81_paramInit; Defs._IOwnership _82___v43; @@ -3020,9 +3020,9 @@ public void GenStmt(DAST._IStatement stmt, Defs._ISelfInfo selfIdent, Defs._IEnv newEnv = (newEnv).AddAssigned(_84_recVar, _85_declaredType); } _78_loopBegin = (_78_loopBegin).Then(RAST.Expr.create_DeclareVar(RAST.DeclareType.create_CONST(), _80_param, Std.Wrappers.Option.create_None(), Std.Wrappers.Option.create_Some(RAST.Expr.create_Identifier(_84_recVar)))); - continue_5: ; + continue_4_0: ; } - after_5: ; + after_4_0: ; RAST._IExpr _86_bodyExpr; Dafny.ISet> _87_bodyIdents; Defs._IEnvironment _88_bodyEnv; @@ -7196,7 +7196,7 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul BigInteger _hi2 = new BigInteger(((_5_allModules).dtor_keys).Count); for (BigInteger _8_i = BigInteger.Zero; _8_i < _hi2; _8_i++) { if (!((_5_allModules).dtor_values).Contains(((_5_allModules).dtor_keys).Select(_8_i))) { - goto continue_6; + goto continue_0; } RAST._IMod _9_m; _9_m = (Dafny.Map, DafnyCompilerRustUtils._IGatheringModule>.Select((_5_allModules).dtor_values,((_5_allModules).dtor_keys).Select(_8_i))).ToRust(); @@ -7206,9 +7206,9 @@ public RAST._IExpr Error(Dafny.ISequence message, RAST._IExpr defaul } s = Dafny.Sequence.Concat(s, Dafny.Sequence.UnicodeFromString("\n")); s = Dafny.Sequence.Concat(s, (_9_m)._ToString(Dafny.Sequence.UnicodeFromString(""))); - continue_6: ; + continue_0: ; } - after_6: ; + after_0: ; return s; } public Dafny.ISequence EmitCallToMain(DAST._IExpression companion, Dafny.ISequence mainMethodName, bool hasArgs) diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/Makefile b/Source/DafnyRuntime/DafnyRuntimeRust/Makefile index 3602a45d885..bca42243469 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/Makefile +++ b/Source/DafnyRuntime/DafnyRuntimeRust/Makefile @@ -8,7 +8,7 @@ GENERATED_SYSTEM_MODULE_TARGET=src/system/mod.rs all: check-system-module test build-system-module: - $(DAFNY) translate rs --no-verify --use-basename-for-filename --optimize-erasable-datatype-wrapper:false --system-module:OmitAllOtherModules ../systemModulePopulator.dfy --output:../obj/systemModulePopulator + $(DAFNY) translate rs --no-verify --enforce-determinism --use-basename-for-filename --optimize-erasable-datatype-wrapper:false --system-module:OmitAllOtherModules ../systemModulePopulator.dfy --output:../obj/systemModulePopulator python -c "import sys; data = sys.stdin.read(); sys.stdout.write(data.replace('::dafny_runtime', 'crate').replace('pub use ::std::rc::Rc;', '#[cfg(feature = \"sync\")] pub use ::std::sync::{Arc as Rc}; #[cfg(not(feature = \"sync\"))] pub use ::std::rc::Rc;'))" < $(GENERATED_SYSTEM_MODULE_SOURCE) > $(GENERATED_SYSTEM_MODULE_SOURCE).tmp && mv $(GENERATED_SYSTEM_MODULE_SOURCE).tmp $(GENERATED_SYSTEM_MODULE_SOURCE) check-system-module: build-system-module From 090558ff6bb9a2761298bfcebcfa2b489bd4d68b Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Thu, 20 Feb 2025 09:54:27 -0600 Subject: [PATCH 66/69] Fixed printability of functions in async --- .../DafnyRuntimeRustTest/Cargo.lock | 14 -------------- Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs | 2 +- .../DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs | 4 ++-- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/Source/DafnyRuntime.Tests/DafnyRuntimeRustTest/Cargo.lock b/Source/DafnyRuntime.Tests/DafnyRuntimeRustTest/Cargo.lock index c1b0654506e..de7c7230ede 100644 --- a/Source/DafnyRuntime.Tests/DafnyRuntimeRustTest/Cargo.lock +++ b/Source/DafnyRuntime.Tests/DafnyRuntimeRustTest/Cargo.lock @@ -9,12 +9,6 @@ dependencies = [ "dafny_runtime", ] -[[package]] -name = "as-any" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a30a44e99a1c83ccb2a6298c563c888952a1c9134953db26876528f84c93a" - [[package]] name = "autocfg" version = "1.3.0" @@ -25,11 +19,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" name = "dafny_runtime" version = "0.1.0" dependencies = [ - "as-any", "itertools", "num", "once_cell", - "paste", ] [[package]] @@ -125,9 +117,3 @@ name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs index 43c65e42573..6e1606c5dc7 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs @@ -2077,7 +2077,7 @@ impl DafnyPrint for LazyFieldWrapper { // Convert the DafnyPrint above into a macro so that we can create it for functions of any input arity macro_rules! dafny_print_function { ($($n:tt)*) => { - impl $crate::DafnyPrint for $crate::Rc B + Send + Sync> { + impl $crate::DafnyPrint for $crate::Rc B + Send + Sync> { fn fmt_print(&self, f: &mut ::std::fmt::Formatter<'_>, _in_seq: bool) -> ::std::fmt::Result { write!(f, "") } diff --git a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs index 8e2665eea15..c3b9e528cee 100644 --- a/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs +++ b/Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs @@ -673,9 +673,9 @@ mod tests { #[test] fn test_function_wrappers() { #[cfg(feature = "sync")] - let f: Rc i32 + Send + Sync> = Rc::new(|i: i32| i + 1); + let f: Rc i32 + Send + Sync> = Rc::new(|i: &i32| *i + 1); #[cfg(not(feature = "sync"))] - let f: Rc i32> = Rc::new(|i: i32| i + 1); + let f: Rc i32> = Rc::new(|i: &i32| *i + 1); let g = f.clone(); let _h = seq![g]; } From 81d0a3fc43b8052f75ee9234d00c67dd7171862e Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 21 Feb 2025 13:33:25 -0600 Subject: [PATCH 67/69] typo --- Source/DafnyCore/AST/TypeDeclarations/Declaration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs b/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs index 67c81c6b675..6d9fa21a33d 100644 --- a/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs +++ b/Source/DafnyCore/AST/TypeDeclarations/Declaration.cs @@ -147,7 +147,7 @@ public string GetQualificationName(DafnyOptions options) { return enclosingModuleName; } -s public Attributes? Attributes; // readonly, except during class merging in the refinement transformations and when changed by Compiler.MarkCapitalizationConflict + public Attributes? Attributes; // readonly, except during class merging in the refinement transformations and when changed by Compiler.MarkCapitalizationConflict Attributes? IAttributeBearingDeclaration.Attributes { get => Attributes; set => Attributes = value; From 89948d448bab1a4f2383ed85c1aa48e1c7e020d0 Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 21 Feb 2025 20:58:42 -0600 Subject: [PATCH 68/69] Renaming missed --- Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs b/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs index 286b4d4612d..6c607194e79 100644 --- a/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs +++ b/Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs @@ -44,7 +44,7 @@ private static void InferEqualitySupport(List declarations, ErrorR ctor.Formals.Any(arg => InferAndSetEqualitySupport(tp, arg.Type, reporter) ) - ) || dt.ParentTraits.Any(parentType => + ) || dt.Traits.Any(parentType => InferAndSetEqualitySupport(tp, parentType, reporter) ); } From 68e5cde19ce3486debbc1e9d0c2ba07d37c9e84e Mon Sep 17 00:00:00 2001 From: Mikael Mayer Date: Fri, 21 Feb 2025 23:44:28 -0600 Subject: [PATCH 69/69] Renaming missed --- Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs b/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs index 48ccc105d61..900d15b19d4 100644 --- a/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs +++ b/Source/DafnyCore/AST/TypeDeclarations/TraitDecl.cs @@ -52,7 +52,7 @@ public List DowncastableSubTraitsIfMonomorphized() { var downcastableTraits = new List(); foreach (var subTrait in TraitDeclsCanBeDowncastedTo) { // Recovers which of the parent traits of the subTraits is the current trait declaration - var parentTrait = subTrait.ParentTraits.FirstOrDefault(t => t.AsTraitType == this); + var parentTrait = subTrait.Traits.FirstOrDefault(t => t.AsTraitType == this); Type downcastType = null; if (parentTrait is UserDefinedType { TypeArgs: var parentTypeArguments } && CanDowncastIfMonomorphized(parentTypeArguments, subTrait, ref downcastType)) { + /// Given an instantiated parent type of the given subTrait, + /// return true if it's possible to describe the trait subTrait from the parent's own type parameters. + /// and an instantiation of such type. + /// This makes it possible to downcast the trait at run-time. + /// For example: + /// + /// trait Sub extends Parent where trait Parent + /// ===? true and Sub + /// trait Sub extends Parent> where trait Parent + /// ==> true and Sub (could have been Sub too) + /// trait Sub extends Parent where trait Parent + /// ==> true and Sub + /// trait Sub extends Parent> where trait Parent + /// ==> false and null + /// trait Sub extends Parent where trait Parent + /// ==> false and null + ///