statement
stringlengths
1
4.4k
proof
stringlengths
0
42.3k
type
stringclasses
15 values
symbolic_name
stringlengths
1
66
library
stringclasses
158 values
filename
stringlengths
31
124
imports
listlengths
0
0
deps
listlengths
0
64
docstring
stringclasses
1 value
source_url
stringclasses
1 value
commit
stringclasses
1 value
NeedsUnwrappingConversion(tpe: Type)
{ match tpe { case UserDefined(ResolvedType(path, typeArgs, Newtype(base, range, erase), _, _, _)) => NewtypeRangeToUnwrappedBoundedRustType(base, range).None? case _ => false } }
predicate
NeedsUnwrappingConversion
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Newtype", "NewtypeRangeToUnwrappedBoundedRustType", "None", "ResolvedType", "Type", "base" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
IsNewtype(tpe: Type)
{ tpe.UserDefined? && tpe.resolved.kind.Newtype? }
predicate
IsNewtype
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Type" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
CoveredAllNewtypeCases(tpe: Type) requires GetUnwrappedBoundedRustType(tpe).None? requires !NeedsUnwrappingConversion(tpe) ensures !IsNewtype(tpe)
{ }
lemma
CoveredAllNewtypeCases
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "GetUnwrappedBoundedRustType", "IsNewtype", "NeedsUnwrappingConversion", "None", "Type" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
IsNewtypeCopy(range: NewtypeRange)
{ && NewtypeRangeToRustType(range).Some? && (range.HasArithmeticOperations() || range.Bool?) }
predicate
IsNewtypeCopy
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "NewtypeRange", "NewtypeRangeToRustType" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
OwnershipGuarantee(expectedOwnership: Ownership, resultingOwnership: Ownership)
{ && (expectedOwnership != OwnershipAutoBorrowed ==> resultingOwnership == expectedOwnership) && resultingOwnership != OwnershipAutoBorrowed // We know what's going on }
predicate
OwnershipGuarantee
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Ownership" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
BecomesLeftCallsRight(op: BinOp)
{ match op { case SetMerge() | SetSubtraction() | SetIntersection() | SetDisjoint() | MapMerge() | MapSubtraction() | MultisetMerge() | MultisetSubtraction() | MultisetIntersection() | MultisetDisjoint() | Concat() => true...
predicate
BecomesLeftCallsRight
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "BinOp", "Concat" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
BecomesRightCallsLeft(op: BinOp)
{ match op { case In() => true case _ => false } }
predicate
BecomesRightCallsLeft
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "BinOp", "In" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
BecomesExclusive(op: BinOp) ensures BecomesRightCallsLeft(op) ==> !BecomesLeftCallsRight(op) ensures BecomesLeftCallsRight(op) ==> !BecomesRightCallsLeft(op)
{}
lemma
BecomesExclusive
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "BecomesLeftCallsRight", "BecomesRightCallsLeft", "BinOp" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
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
Panic
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply0", "Apply1" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
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 Panic(optText) }
function
UnreachablePanicIfVerified
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply0", "AsExpr", "FSel", "Panic", "PointerType", "pointerType" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DefaultDatatypeImpl( rTypeParamsDecls: seq<R.TypeParamDecl>, datatypeType: R.Type, datatypeName: R.Expr, structAssignments: seq<R.AssignIdentifier> ): R.ModDecl
{ var defaultConstrainedTypeParams := R.TypeParamDecl.AddConstraintsMultiple( rTypeParamsDecls, [R.DefaultTrait] ); R.ImplDecl( R.ImplFor( defaultConstrainedTypeParams, R.DefaultTrait, datatypeType, ...
function
DefaultDatatypeImpl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "default" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
AsRefDatatypeImpl(rTypeParamsDecls: seq<R.TypeParamDecl>, datatypeType: R.Type): R.ModDecl
{ R.ImplDecl( R.ImplFor( rTypeParamsDecls, R.std.MSel("convert").MSel("AsRef").AsType().Apply1(datatypeType), datatypeType, [R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, R.Fn("as_ref", [], [R.Formal.selfBorrowed], Some(R.SelfBorrowed), S...
function
AsRefDatatypeImpl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply1", "AsType", "MSel" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DebugImpl(rTypeParamsDecls: seq<R.TypeParamDecl>, datatypeType: R.Type, rTypeParams: seq<R.Type>): R.ModDecl
{ R.ImplDecl( R.ImplFor( rTypeParamsDecls, R.std.MSel("fmt").MSel("Debug").AsType(), datatypeType, [ R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "fmt", [], [R.Formal.selfBorrowed, R.Formal("...
function
DebugImpl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply", "AsExpr", "AsType", "DafnyPrint", "Debug", "FSel", "MSel", "Result" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
PrintImpl(rTypeParamsDecls: seq<R.TypeParamDecl>, datatypeType: R.Type, rTypeParams: seq<R.Type>, printImplBody: R.Expr): R.ModDecl
{ R.ImplDecl( R.ImplFor( rTypeParamsDecls, R.DafnyPrint, datatypeType, [R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "fmt_print", [], [R.Formal.selfBorrowed, R.Formal("_formatter", R.BorrowedMut(R.std.MSel("...
function
PrintImpl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "AsType", "MSel", "Result", "std" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
EqImpl(rTypeParamsDeclsWithEq: seq<R.TypeParamDecl>, datatypeType: R.Type, rTypeParams: seq<R.Type>, eqImplBody: R.Expr): seq<R.ModDecl>
{ [ 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)],...
function
EqImpl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "eq" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
CoerceImpl( rc: R.Type -> R.Type, rcNew: R.Expr -> R.Expr, rTypeParamsDecls: seq<R.TypeParamDecl>, datatypeName: string, datatypeType: R.Type, rCoerceTypeParams: seq<R.TypeParamDecl>, coerceArguments: seq<R.Formal>, coerceTypes: seq<R.Type>, coerceImplBody: R.Expr ): R.ModDecl
{ R.ImplDecl( R.Impl( rTypeParamsDecls, datatypeType, [R.FnDecl( "Given type parameter conversions, returns a lambda to convert this structure", R.NoAttr, R.PUB, R.Fn( "coerce", rCoerceTypeParams, coerceArguments, ...
function
CoerceImpl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "conversions", "rc", "rcNew", "to" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
SingletonsImpl( rTypeParamsDecls: seq<R.TypeParamDecl>, datatypeType: R.Type, instantiationType: R.Type, singletonConstructors: seq<R.Expr>): R.ModDecl
{ R.ImplDecl( R.Impl( rTypeParamsDecls, datatypeType, [R.FnDecl( "Enumerates all possible values of " + datatypeType.ToString(""), [], R.PUB, R.Fn( "_AllSingletonConstructors", [], [], Some(R.dafny_runtime.MSel("Se...
function
SingletonsImpl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply", "Apply0", "AsExpr", "AsType", "Sel", "iter", "values" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
HashImpl( rTypeParamsDeclsWithHash: seq<R.TypeParamDecl>, datatypeOrNewtypeType: R.Type, hashImplBody: R.Expr ): R.ModDecl
{ R.ImplDecl( R.ImplFor( rTypeParamsDeclsWithHash, R.Hash, datatypeOrNewtypeType, [R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "hash", hash_type_parameters, hash_parameters, None, Some(hashImplB...
function
HashImpl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "None", "hash", "hash_parameters", "hash_type_parameters" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
hash_type_parameters := [R.TypeParamDecl("_H", [R.std.MSel("hash").MSel("Hasher").AsType()])]
const
hash_type_parameters
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "AsType", "MSel", "hash" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
hash_parameters := [ R.Formal.selfBorrowed, R.Formal("_state", R.BorrowedMut(R.TIdentifier("_H")))]
const
hash_parameters
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
hash_function := R.std.MSel("hash").MSel("Hash").AsExpr().FSel("hash")
const
hash_function
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "AsExpr", "FSel", "Hash", "MSel", "hash" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
hasher_trait(supportsEquality: bool, pointerType: PointerType): R.ImplMember
{ R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_hash", [], [R.Formal.selfBorrowed], Some(R.Type.U64), Some( if supportsEquality then R.DeclareVar(R.MUT, "hasher", None, Some(R.std.MSel("hash").MSel("DefaultHasher").AsExpr().FSel("new").Apply0())).Then( ...
function
hasher_trait
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply0", "Apply1", "AsExpr", "FSel", "MSel", "None", "PointerType", "Sel", "Then", "UnreachablePanicIfVerified", "hash", "not", "pointerType" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
eq_trait(fullTraitPath: R.Type, fullTraitExpr: R.Expr, supportsEquality: bool, pointerType: PointerType): R.ImplMember
{ R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_eq", [], [R.Formal.selfBorrowed, R.Formal("other", R.Borrowed(R.Box(R.DynType(fullTraitPath))))], Some(R.Type.Bool), Some( if supportsEquality then fullTraitExpr.FSel("_as_any").Apply1(R.Identifier("other").Sel("a...
function
eq_trait
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply", "Apply0", "Apply1", "ApplyType", "None", "PointerType", "Sel", "UnreachablePanicIfVerified", "not", "pointerType" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
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())))) }
function
clone_trait
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply0" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
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")]))))
const
print_trait
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply", "fmt_print_parameters", "fmt_print_result" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
as_any_trait := R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_as_any", [], [R.Formal.selfBorrowed], Some(R.Borrowed(R.DynType(R.AnyTrait))), Some(R.self)))
const
as_any_trait
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
UnaryOpsImpl( op: char, rTypeParamsDecls: seq<R.TypeParamDecl>, newtypeType: R.Type, newtypeConstructor: string ): R.ModDecl requires op in "!"
{ var (traitName, methodName) := match op { case '!' => ("Not", "not") }; R.ImplDecl( R.ImplFor( rTypeParamsDecls, R.std.MSel("ops").MSel(traitName).AsType(), newtypeType, [ R.TypeDeclMember("Output", newtypeType), R.FnDecl( R.NoDoc, R.NoAttr...
function
UnaryOpsImpl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply1", "AsType", "MSel", "Not", "not" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
OpsImpl( op: char, rTypeParamsDecls: seq<R.TypeParamDecl>, newtypeType: R.Type, newtypeConstructor: string ): R.ModDecl requires op in "+-/*"
{ var (traitName, methodName) := match op { case '+' => ("Add", "add") case '-' => ("Sub", "sub") case '/' => ("Div", "div") case '*' => ("Mul", "mul") }; R.ImplDecl( R.ImplFor( rTypeParamsDecls, R.std.MSel("ops").MSel(traitName).AsType(), newtypeType, ...
function
OpsImpl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Add", "Apply1", "AsType", "Div", "MSel", "Mul", "Sel", "Sub", "add", "mul", "sub" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
PartialOrdImpl( rTypeParamsDecls: seq<R.TypeParamDecl>, newtypeType: R.Type, newtypeConstructor: string ): R.ModDecl
{ R.ImplDecl( R.ImplFor( rTypeParamsDecls, R.std.MSel("cmp").MSel("PartialOrd").AsType(), newtypeType, [ R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "partial_cmp", [], [R.Formal.selfBorrowed, R.Formal...
function
PartialOrdImpl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply", "Apply1", "AsExpr", "AsType", "FSel", "MSel", "Option", "Sel" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
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_parameters
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "AsType", "MSel" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
fmt_print_result := R.std.MSel("fmt").MSel("Result").AsType()
const
fmt_print_result
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "AsType", "MSel", "Result" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DowncastTraitDeclFor( rTypeParamsDecls: seq<R.TypeParamDecl>, fullType: R.Type ): Option<R.ModDecl>
{ var downcast_type :- fullType.ToDowncast(); Some( R.TraitDecl( R.Trait( R.NoDoc, R.NoAttr, rTypeParamsDecls, downcast_type, [], [ R.FnDecl( R.NoDoc, R.NoAttr, R.PRIV, R.Fn( "_is", [], ...
function
DowncastTraitDeclFor
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "None", "Option" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DowncastImplFor( rcNew: R.Expr -> R.Expr, rTypeParamsDecls: seq<R.TypeParamDecl>, datatypeType: R.Type ): Option<R.ModDecl>
{ 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.se...
function
DowncastImplFor
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply0", "ApplyType", "Option", "Sel", "rcNew" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DowncastNotImplFor( rTypeParamsDecls: seq<R.TypeParamDecl>, traitType: R.Type, datatypeType: R.Type ): Option<R.ModDecl>
{ 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( ...
function
DowncastNotImplFor
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply0", "Option", "not" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DowncastImplTraitFor( rTypeParamsDecls: seq<R.TypeParamDecl>, traitType: R.Type, implementsTrait: bool, datatypeType: R.Type ): Option<R.ModDecl>
{ 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...
function
DowncastImplTraitFor
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Option" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
UpcastDynTraitFor( rTypeParamsDecls: seq<R.TypeParamDecl>, 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)]), forBoxedTraitT...
function
UpcastDynTraitFor
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Apply", "Apply0", "Apply1", "AsType", "upcast" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
AssignmentStatus
= NotAssigned | SurelyAssigned | Unknown {
datatype
AssignmentStatus
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
Join(other: AssignmentStatus): AssignmentStatus
{ if SurelyAssigned? && other.SurelyAssigned? then SurelyAssigned else if NotAssigned? && other.NotAssigned? then NotAssigned else Unknown }
function
Join
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "AssignmentStatus" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
Then(other: AssignmentStatus): AssignmentStatus
{ if SurelyAssigned? then SurelyAssigned else if NotAssigned? then other else Unknown // It's not as simple. If there are two paths leading to one being assigned, the other not, // Rust won't be able to figure out the rules }
function
Then
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "AssignmentStatus" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DetectAssignmentStatus(stmts_remainder: seq<Statement>, dafny_name: VarName): AssignmentStatus
{ if |stmts_remainder| == 0 then NotAssigned else var stmt := stmts_remainder[0]; var tailAssigned := DetectAssignmentStatus(stmts_remainder[1..], dafny_name); var stop := stmt.Return? || stmt.EarlyReturn? || stmt.JumpTailCallStart? || (stmt.DeclareVar? && stmt.name == dafny_name); var thisAssign :=...
function
DetectAssignmentStatus
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[ "Assign", "AssignmentStatus", "Call", "Ident", "If", "Join", "Print", "Return", "Statement", "VarName", "method", "name", "to" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
prefixWith2(s: string): string
{ if |s| >= 2 && s[..2] == "r#" then "_2_" + s[2..] else "_2_" + s }
function
prefixWith2
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
apply(mod: Mod): Mod
{ ExprSimplifier().ReplaceMod(mod, crate.MSel(mod.name)) }
function
apply
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-expression-optimization.dfy
[]
[ "ExprSimplifier", "Mod", "ReplaceMod" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
ExprSimplifier(): RASTBottomUpReplacer
{ RASTBottomUpReplacer( ReplaceModSingle := (m: Mod, SelfPath: Path) => m, ReplaceTypeSingle := (t: Type) => t, ReplaceExprSingle := (e: Expr) => match e { case UnaryOp("!", BinaryOp(op, left, right, format), CombineFormat()) => mat...
function
ExprSimplifier
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-expression-optimization.dfy
[]
[ "Assign", "Call", "Expr", "Mod", "None", "Path", "RASTBottomUpReplacer", "StmtExpr", "Type", "UnaryOp", "base", "dafny_runtime", "global", "last", "left", "name", "right" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
ShouldBeEqual(a: Mod, b: Mod)
{ var sA := a.ToString(""); var sB := b.ToString(""); if sA != sB { print "Got:\n" + sA + "\n"; print "Expected:\n" + sB + "\n"; expect sA == sB; } }
method
ShouldBeEqual
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[ "Mod", "sA" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
TestApply()
{ var T_Decl := TypeParamDecl("T", [DafnyType]); var T_Decl_simp := TypeParamDecl("T", [TIdentifier("DafnyType")]); var T := TIdentifier("T"); var std_any_Any := global.MSel("std").MSel("any").MSel("Any"); var Any := TIdentifier("Any"); ShouldBeEqual( apply(crate)( Mod( N...
method
TestApply
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[ "Apply", "Apply1", "ApplyType", "AsExpr", "AsType", "Constant", "DafnyType", "Default", "FSel", "Field", "Formal", "Identifier", "Impl", "MSel", "Mod", "NoAttr", "NoDoc", "RcPath", "ShouldBeEqual", "Something", "StmtExpr", "Struct", "Trait", "TypeParamDecl", "Use", ...
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
apply(root: Path): Mod -> Mod
{ (mod: Mod) => applyPrefix(mod, root.MSel(mod.name)) }
function
apply
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[ "Mod", "Path", "applyPrefix" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
applyPrefix(mod: Mod, SelfPath: Path): Mod decreases mod, 1
{ if mod.ExternMod? then mod else var mappings: Mapping := PathsVisitor().VisitMod(Mapping(map[], []), mod, SelfPath); var pathsToRemove := mappings.ToFinalReplacement(SelfPath); var imports := mappings.ToUseStatements(pathsToRemove, SelfPath); var mod := PathSimplifier(mod, pathsToRemove).ReplaceMo...
function
applyPrefix
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[ "Mapping", "Mod", "Path", "PathSimplifier", "PathsVisitor", "ReplaceMod", "VisitMod" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
UniqueElementOf<T>(s: set<T>): (r: T) requires |s| == 1 ensures r in s
{ assert forall e: T, e': T | e in s && e' in s :: e == e' by { forall e: T, e': T | e in s && e' in s ensures e == e' { if e != e' { assert e' in (s - {e}); assert |s - {e}| == 0; } } } var e :| e in s; e }
function
UniqueElementOf
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
FinalReplacement
= map<string, Path>
type
FinalReplacement
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[ "Path" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
Mapping
= Mapping( provenance: map<string, set<Path>>, keys: seq<string> ) {
datatype
Mapping
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[ "Path" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
Add(k: string, path: Path): Mapping
{ if k in provenance then this.(provenance := provenance[k := provenance[k] + {path}]) else this.(provenance := provenance[k := {path}], keys := keys + [k]) }
function
Add
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[ "Mapping", "Path" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
ToFinalReplacement(SelfPath: Path): FinalReplacement
{ map identifier <- provenance, paths | paths == provenance[identifier] && (|| |paths| == 1 || SelfPath in paths || dafny_runtime in paths) :: identifier := if |paths| == 1 then UniqueElementOf(paths) else if SelfPath in paths then ...
function
ToFinalReplacement
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[ "FinalReplacement", "Path", "UniqueElementOf", "dafny_runtime" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
ToUseStatements(finalReplacement: FinalReplacement, SelfPath: Path): seq<ModDecl> requires finalReplacement == ToFinalReplacement(SelfPath)
{ var toUse := Std.Collections.Seq.Filter( (key: string) => key in finalReplacement && finalReplacement[key] != SelfPath, keys); seq(|toUse|, i requires 0 <= i < |toUse| => UseDecl(Use(PUB, finalReplacement[toUse[i]].MSel(toUse[i])))) }
function
ToUseStatements
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[ "FinalReplacement", "MSel", "ModDecl", "Path", "ToFinalReplacement", "Use", "key" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
PathsVisitor(): RASTTopDownVisitor<Mapping>
{ RASTTopDownVisitor( VisitTypeSingle := (current: Mapping, t: Type) => match t { case TypeFromPath(PMemberSelect(base, name)) => if base == Self() then current else current.Add(name, base) case _ => current }, VisitExprSingle := (current: Mapping, e: Expr...
function
PathsVisitor
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[ "Expr", "Mapping", "ModDecl", "Path", "RASTTopDownVisitor", "TopFnDecl", "Type", "base", "id", "name", "struct" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
PathSimplifier(ghost mParent: Mod, replacement: FinalReplacement): RASTBottomUpReplacer decreases mParent, 0
{ RASTBottomUpReplacer( ReplaceModSingle := (m: Mod, SelfPath: Path) requires m < mParent => applyPrefix(m, SelfPath.MSel(m.name)), ReplaceTypeSingle := (t: Type) => match t { case TypeFromPath(PMemberSelect(base, id)) => if id in replacement && replacemen...
function
PathSimplifier
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-path-simplification.dfy
[]
[ "Expr", "FinalReplacement", "Identifier", "Mod", "Path", "RASTBottomUpReplacer", "Type", "applyPrefix", "base", "id" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
AboutGatherSimpleQuotes(docstring: string, acc: string) ensures var r := GatherSimpleQuotes(docstring, acc); && |acc| <= |r| && |r[|acc|..]| <= |docstring| && r == acc + docstring[..|r[|acc|..]|] && (forall i | |acc| <= i < |r| :: r[i] == '`') && (|docstring| > |r[|acc|..]| ==> ...
{ var r := GatherSimpleQuotes(docstring, acc); if |docstring| == 0 || docstring[0] != '`' { } else { } } } @Compile(false)
lemma
AboutGatherSimpleQuotes
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "Compile", "GatherSimpleQuotes" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
IsDafnyId(s: string)
{ && |s| > 0 && s[0] in "aqkhd" && IsDafnyIdTail(s[1..]) }
predicate
IsDafnyId
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "IsDafnyIdTail" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
IsDafnyIdTail(s: string)
{ |s| == 0 || (s[0] in "aqkhd_?'#." && IsDafnyIdTail(s[1..])) }
predicate
IsDafnyIdTail
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
IsDafnyIdImpliesDafnyIdTail(s: string) requires IsDafnyId(s) ensures IsDafnyIdTail(s)
{}
lemma
IsDafnyIdImpliesDafnyIdTail
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "IsDafnyId", "IsDafnyIdTail" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DafnyEscape(s: string): string
{ if |s| == 0 then "" else if s[0] == '_' then "__" + DafnyEscape(s[1..]) else if s[0] == '?' then "_q" + DafnyEscape(s[1..]) else if s[0] == '\'' then "_k" + DafnyEscape(s[1..]) else if s[0] == '#' then "_h" + DafnyEscape(s[1..]) else [s[0]] + DafnyEscape(s[1..]) }
function
DafnyEscape
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DafnyUnescape(s: string): string
{ if |s| <= 1 then s else if s[0] == '_' then if s[1] == '_' then "_" + DafnyUnescape(s[2..]) else if s[1] == 'q' then "?" + DafnyUnescape(s[2..]) else if s[1] == 'k' then "'" + DafnyUnescape(s[2..]) else if s[1] == 'h' then "#" + DafnyUnescape(s[2..]) else s[..1] + DafnyUnescape(s...
function
DafnyUnescape
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DafnyEscapeBijective(s: string) ensures DafnyUnescape(DafnyEscape(s)) == s
{ if |s| == 0 { } else { DafnyEscapeBijective(s[1..]); if s[0] == '_' { } else if s[0] == '?' { } else if s[0] == '\'' { } else if s[0] == '#' { } else { } } }
lemma
DafnyEscapeBijective
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "DafnyEscape", "DafnyUnescape" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DafnyEscapeCharacteristic(s: string) requires IsDafnyIdTail(s) ensures IsDafnyEncodedIdTail(DafnyEscape(s))
{ if |s| == 0 { } else { DafnyEscapeCharacteristic(s[1..]); if s[0] == '_' { } else if s[0] == '?' { } else if s[0] == '\'' { } else if s[0] == '#' { } else { } } }
lemma
DafnyEscapeCharacteristic
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "DafnyEscape", "IsDafnyEncodedIdTail", "IsDafnyIdTail" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
ReverseReplaceDots(i: string): string
{ if |i| <= 1 then i else if i[0] == '_' then if i[1] == 'd' then "." + ReverseReplaceDots(i[2..]) else [i[0]] + [i[1]] + ReverseReplaceDots(i[2..]) else [i[0]] + ReverseReplaceDots(i[1..]) }
function
ReverseReplaceDots
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
IsDafnyEncodedIdTail(i: string)
{ if |i| == 0 then true else if i[0] == '_' then |i| >= 2 && i[1] in ESCAPING && IsDafnyEncodedIdTail(i[2..]) else (i[0] in SAMPLE_LETTERS || i[0] == '.') && IsDafnyEncodedIdTail(i[1..]) }
predicate
IsDafnyEncodedIdTail
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "ESCAPING", "SAMPLE_LETTERS" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
SAMPLE_LETTERS := "aqkhd"
const
SAMPLE_LETTERS
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
ESCAPING := "_qkh"
const
ESCAPING
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
IsDafnyEncodedId(i: string)
{ if |i| == 0 then false else i[0] in SAMPLE_LETTERS && IsDafnyEncodedIdTail(i[1..]) }
predicate
IsDafnyEncodedId
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "IsDafnyEncodedIdTail", "SAMPLE_LETTERS" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DafnyEscapeCorrect(s: string) requires IsDafnyIdTail(s) ensures IsDafnyEncodedIdTail(DafnyEscape(s)) && (IsDafnyId(s) && |s| > 0 ==> DafnyEscape(s)[0] in "aqkhd")
{ if |s| == 0 { } else { if s[0] == '_' { // "__" + DafnyEscape(s[1..]) } else if s[0] == '?' { // "_q" + DafnyEscape(s[1..]) else } else if s[0] == '\'' { // "_k" + DafnyEscape(s[1..]) else } else if s[0] == '#' { // "_h" + DafnyEscape(s[1..]) else= } else { // [s[0]] + DafnyEscap...
lemma
DafnyEscapeCorrect
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "DafnyEscape", "IsDafnyEncodedIdTail", "IsDafnyId", "IsDafnyIdTail" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
ReplaceDotsNotInvertible() ensures replaceDots("_d") == replaceDots(".") ensures !IsDafnyEncodedIdTail("_d")
{} // However, if we restrict ourself to a Dafny encoding, it's invertible @ResourceLimit("2500e3") @IsolateAssertions
lemma
ReplaceDotsNotInvertible
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "IsDafnyEncodedIdTail", "replaceDots" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
ReplaceDotsInvertible(i: string) requires IsDafnyEncodedIdTail(i) ensures ReverseReplaceDots(replaceDots(i)) == i
{ if |i| == 0 { } else if i[0] == '.' { //"_d" + replaceDots(i[1..]) ReplaceDotsInvertible(i[1..]); assert ReverseReplaceDots(replaceDots(i)) == i; } else { // [i[0]] + replaceDots(i[1..]) assert replaceDots(i) == [i[0]] + replaceDots(i[1..]); if i[0] == '_' { assert |i| >= 2...
lemma
ReplaceDotsInvertible
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "IsDafnyEncodedIdTail", "ReverseReplaceDots", "replaceDots" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
BetterTupleBuilderNameNotRsharp(i: string) ensures is_tuple_builder(i) ==> var s := better_tuple_builder_name(i); s[0..2] != "r#"
{}
lemma
BetterTupleBuilderNameNotRsharp
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "better_tuple_builder_name", "is_tuple_builder" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
IdiomaticRustNotRsharp(i: string) ensures !has_special(i) ==> |idiomatic_rust(i)| < 1 || idiomatic_rust(i)[0] != '#'
{ if !has_special(i) { var s := idiomatic_rust(i); if |i| == 0 { } else if i[0] == '_' { var s := "_" + idiomatic_rust(i[2..]); assert s[0] == '_'; } else { var s := [i[0]] + idiomatic_rust(i[1..]); assert s[0] == i[0]; } } } @Fuel(2, 3, "has_sp...
lemma
IdiomaticRustNotRsharp
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "has_special", "idiomatic_rust" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
EscapeIdentExamples() ensures escapeIdent("i") == "i" // Loop variable ensures escapeIdent("_1") == "_1" // tuple deconstructor ensures escapeIdent("_m") == "_m" // any hidden variable ensures escapeIdent("___hMake1") == "_T1" // tuple deconstructor ensures escapeIdent("h__w") == "h_w" // only let...
{ assert has_special("h_kw"); }
lemma
EscapeIdentExamples
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "escapeIdent", "has_special" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
ReverseIdiomaticRust(s: string): string
{ if |s| == 0 then "" else if s[0] == '_' then "__" + ReverseIdiomaticRust(s[1..]) else [s[0]] + ReverseIdiomaticRust(s[1..]) }
function
ReverseIdiomaticRust
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
{:rlimit 200} IdiomaticRustInvertible(i: string) requires !has_special(i) ensures ReverseIdiomaticRust(idiomatic_rust(i)) == i
{ if |i| == 0 { } else if i[0] == '_' { IdiomaticRustInvertible(i[2..]); assert 2 <= |i| && i[1] == '_'; var ss := ['_'] + idiomatic_rust(i[2..]); assert ss[0] == '_' && |ss| != 0; } else { IdiomaticRustInvertible(i[1..]); } }
lemma
IdiomaticRustInvertible
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "ReverseIdiomaticRust", "has_special", "idiomatic_rust", "ss" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
UnescapeIdent(s: string): string
{ if |s| >= 1 && s[0] == '_' then if is_tuple_numeric(s) then s else if |s| >= 2 && s[1] == 'T' then "___hMake" + s[2..] // Tuple builder else if s == "_self" || s == "_Self" then s[1..] else ReverseReplaceDots(s[1..]) // We remove the extra "_" prefix and pla...
function
UnescapeIdent
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "ReverseIdiomaticRust", "ReverseReplaceDots", "is_tuple_numeric" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
TupleIdentInvertible(i: string) requires is_tuple_numeric(i) ensures UnescapeIdent(escapeIdent(i)) == i
{ }
lemma
TupleIdentInvertible
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "UnescapeIdent", "escapeIdent", "is_tuple_numeric" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
{:rlimit 500} TupleBuilderInvertible(i: string) requires !is_tuple_numeric(i) requires is_tuple_builder(i) ensures UnescapeIdent(escapeIdent(i)) == i
{ var s := "_T" + i[8..]; calc { UnescapeIdent(escapeIdent(i)); UnescapeIdent(s); i[0..8] + s[2..]; i; } }
lemma
TupleBuilderInvertible
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "UnescapeIdent", "escapeIdent", "is_tuple_builder", "is_tuple_numeric" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
{:rlimit 800} ReservedRustInvertible(i: string) requires !is_tuple_numeric(i) requires !is_tuple_builder(i) requires i in reserved_rust ensures UnescapeIdent(escapeIdent(i)) == i
{ assert i[0] != '_'; var s := "r#" + i; calc { UnescapeIdent(escapeIdent(i)); UnescapeIdent(s); s[2..]; i; } }
lemma
ReservedRustInvertible
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "UnescapeIdent", "escapeIdent", "is_tuple_builder", "is_tuple_numeric", "reserved_rust" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
{:rlimit 800} EscapeIdentInvertibleForIdiomaticRust(i: string) requires IsDafnyEncodedId(i) // Needed to ensure i does not start with '_' requires !is_tuple_numeric(i) requires !is_tuple_builder(i) requires i !in reserved_rust requires is_idiomatic_rust_id(i) ensures UnescapeIdent(escapeIdent(i)...
{ var s := idiomatic_rust(i); IdiomaticRustNotRsharp(i); assert |s| < 2 || s[0..2] != "r#" by { if |s| >= 2 && s[0..2] == "r#" { assert s[1] == '#'; IdiomaticRustNotRsharp(i[1..]); } } assert s[0] != '_'; calc { UnescapeIdent(escapeIdent(i)); UnescapeIdent...
lemma
EscapeIdentInvertibleForIdiomaticRust
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "IdiomaticRustInvertible", "IdiomaticRustNotRsharp", "IsDafnyEncodedId", "ReverseIdiomaticRust", "UnescapeIdent", "escapeIdent", "idiomatic_rust", "is_idiomatic_rust_id", "is_tuple_builder", "is_tuple_numeric", "reserved_rust" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
{:rlimit 800} EscapeIdentInvertibleForDafnyGeneratedId(i: string) requires IsDafnyEncodedId(i) requires !is_tuple_numeric(i) requires !is_tuple_builder(i) requires i !in reserved_rust requires !is_idiomatic_rust_id(i) requires is_dafny_generated_id(i) ensures UnescapeIdent(escapeIdent(i)) ==...
{ assert escapeIdent(i) == i; var s := i; assert |s| >= 1 && s[0] == '_'; assert !(|s| >= 2 && s[1] == 'T'); assert !(s == "_self" || s == "_Self"); calc { UnescapeIdent(s); s; } }
lemma
EscapeIdentInvertibleForDafnyGeneratedId
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "IsDafnyEncodedId", "UnescapeIdent", "escapeIdent", "is_dafny_generated_id", "is_idiomatic_rust_id", "is_tuple_builder", "is_tuple_numeric", "reserved_rust" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
{:rlimit 800} EverythingElseInvertible(i: string) requires IsDafnyEncodedId(i) // Needed to ensure i does not start with '_' requires !is_tuple_numeric(i) requires !is_tuple_builder(i) requires i !in reserved_rust requires !is_idiomatic_rust_id(i) requires !is_dafny_generated_id(i) ensures U...
{ var r := replaceDots(i); var s := "_" + r; assert escapeIdent(i) == s; assert |s| >= 1 && s[0] == '_'; assert !(|s| >= 2 && s[1] == 'T'); assert !(s == "_self" || s == "_Self"); assert |i| > 0; if i[0] == '_' { assert i[0] == '_'; // So if i[0] is not '_' assert UnescapeIde...
lemma
EverythingElseInvertible
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "IsDafnyEncodedId", "ReplaceDotsInvertible", "ReverseReplaceDots", "UnescapeIdent", "escapeIdent", "is_dafny_generated_id", "is_idiomatic_rust_id", "is_tuple_builder", "is_tuple_numeric", "replaceDots", "reserved_rust" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
EscapeIdentInvertible(i: string) requires is_tuple_numeric(i) // _0 _1 ... => _0, _1 ... || is_tuple_builder(i) // ___hMake0, ____hMake1 ... => _T0, _T1 ... || i in reserved_rust // fn, impl, mod ... => r#fn, r#impl, r#mod... || IsDafnyEncodedId(i) // ...
{ if is_tuple_numeric(i) { TupleIdentInvertible(i); } else if is_tuple_builder(i) { TupleBuilderInvertible(i); } else if i in reserved_rust { assert UnescapeIdent(escapeIdent(i)) == i; } else if is_idiomatic_rust_id(i) { EscapeIdentInvertibleForIdiomaticRust(i); } else if is_...
lemma
EscapeIdentInvertible
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-proofs.dfy
[]
[ "EscapeIdentInvertibleForDafnyGeneratedId", "EscapeIdentInvertibleForIdiomaticRust", "EverythingElseInvertible", "IsDafnyEncodedId", "TupleBuilderInvertible", "TupleIdentInvertible", "UnescapeIdent", "escapeIdent", "is_dafny_generated_id", "is_idiomatic_rust_id", "is_tuple_builder", "is_tuple_...
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
MAX_TUPLE_SIZE := 12
const
MAX_TUPLE_SIZE
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
IND := " "
const
IND
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
DocStringPrefix: string := "/// "
const
DocStringPrefix
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
RASTTopDownVisitor<!T(!new)>
= RASTTopDownVisitor( nameonly VisitTypeSingle: (T, Type) -> T, nameonly VisitExprSingle: (T, Expr) -> T, nameonly VisitModDeclSingle: (T, ModDecl, Path) -> T, nameonly recurseSubmodules: bool := false ) {
datatype
RASTTopDownVisitor
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "Expr", "ModDecl", "Path", "Type" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitMod(acc: T, mod: Mod, SelfPath: Path): T
{ mod.Fold(acc, (acc, modDecl) requires modDecl < mod => VisitModMapping(acc, modDecl, SelfPath)) }
function
VisitMod
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "Mod", "Path", "VisitModMapping" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitTypeParams(acc: T, typeParams: seq<TypeParamDecl>): T
{ FoldLeft( (acc: T, t: TypeParamDecl) => FoldLeft( (acc: T, t: Type) => VisitType(acc, t), acc, t.constraints), acc, typeParams) }
function
VisitTypeParams
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "FoldLeft", "Type", "TypeParamDecl", "VisitType" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitFields(acc: T, fields: Fields): T
{ match fields { case NamedFields(sFields) => FoldLeft( (acc: T, f: Field) => VisitType(acc, f.formal.tpe), acc, sFields) case NamelessFields(sFields) => FoldLeft( (acc: T, f: NamelessField) => VisitType(acc, f.tpe...
function
VisitFields
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "Field", "Fields", "FoldLeft", "NamelessField", "VisitType" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitModMapping(acc: T, modDecl: ModDecl, SelfPath: Path): T
{ var acc := VisitModDeclSingle(acc, modDecl, SelfPath); match modDecl { case ModDecl(mod) => if recurseSubmodules then VisitMod(acc, mod, SelfPath.MSel(mod.name)) else acc case StructDecl(struct) => VisitStructMapping(acc, struct) case TypeDecl(TypeSynonym(attrib...
function
VisitModMapping
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "Constant", "Enum", "EnumCase", "FoldLeft", "ModDecl", "Path", "TopFnDecl", "TypeSynonym", "VisitFields", "VisitImplMapping", "VisitMod", "VisitStructMapping", "VisitTopFn", "VisitTraitDecl", "VisitType", "VisitTypeParams", "VisitUse", "attributes", "name", "struct", "value" ...
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitStructMapping(acc: T, struct: Struct): T
{ VisitTypeParams(acc, struct.typeParams) }
function
VisitStructMapping
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "Struct", "VisitTypeParams", "struct" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitTraitDecl(acc: T, tr: Trait): T
{ match tr { case Trait(_, _, typeParams, tpe, parents, body) => var acc := VisitTypeParams(acc, typeParams); var acc := tpe.Fold(acc, VisitTypeSingle); var acc := FoldLeft( (acc: T, parent: Type) => parent.Fold(acc, VisitTypeSingle),...
function
VisitTraitDecl
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "FoldLeft", "Trait", "Type", "VisitBody", "VisitTypeParams" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitTopFn(acc: T, t: TopFnDecl): T
{ match t { case TopFn(_, attributes, visibility, fn) => VisitFn(acc, fn) } }
function
VisitTopFn
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "TopFnDecl", "VisitFn", "attributes" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitUse(acc: T, u: Use): T
{ acc // Nothing to visit for now }
function
VisitUse
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "Use" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitType(acc: T, tpe: Type): T
{ tpe.Fold(acc, (acc: T, t: Type) => VisitTypeSingle(acc, t)) }
function
VisitType
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "Type" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitImplMapping(acc: T, impl: Impl): T
{ match impl { 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, body) =>...
function
VisitImplMapping
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "Impl", "VisitBody", "VisitType", "VisitTypeParams" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitBody(acc: T, members: seq<ImplMember>): T
{ FoldLeft( (acc: T, member: ImplMember) requires member in members => VisitMember(acc, member), acc, members ) }
function
VisitBody
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "FoldLeft", "ImplMember", "VisitMember" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae
VisitMember(acc: T, member: ImplMember): T
{ match member { case RawImplMember(content) => acc case FnDecl(docString, attributes, pub, fun) => VisitFn(acc, fun) case TypeDeclMember(name, tpe) => VisitType(acc, tpe) case ImplMemberMacro(expr: Expr) => expr.Fold(acc, VisitExprSingle, VisitTypeSin...
function
VisitMember
DafnyCore.Backends.Rust
Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy
[]
[ "Expr", "ImplMember", "VisitFn", "VisitType", "attributes", "name" ]
https://github.com/dafny-lang/dafny
8bb7795048d9252198380dec49ffac1e933e25ae