Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat rust exactboundedpool #5706

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/DafnyCore/Backends/Dafny/AST.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ module {:extern "DAST"} DAST {
SetBoundedPool(of: Expression) |
MapBoundedPool(of: Expression) |
SeqBoundedPool(of: Expression, includeDuplicates: bool) |
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)
Expand Down
8 changes: 6 additions & 2 deletions Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public void AddUnsupportedFeature(IToken token, Feature feature) {
Feature.NonSequentializableForallStatements,
Feature.MapItems,
Feature.RunAllTests,
Feature.ExactBoundedPool,
Feature.SequenceDisplaysOfCharacters,
Feature.TypeTests,
Feature.SubsetTypeTests,
Expand Down Expand Up @@ -3091,7 +3090,12 @@ protected override void EmitNull(Type _, ConcreteSyntaxTree wr) {

protected override void EmitSingleValueGenerator(Expression e, bool inLetExprBody, string type,
ConcreteSyntaxTree wr, ConcreteSyntaxTree wStmts) {
AddUnsupportedFeature(e.Tok, Feature.ExactBoundedPool);
if (GetExprConverter(wr, wStmts, out var builder, out var convert)) {
var eBuild = convert(e);
builder.Builder.AddExpr((DAST.Expression)DAST.Expression.create_ExactBoundedPool(eBuild));
} else {
throw new InvalidOperationException();
}
}

protected override void OrganizeModules(Program program, out List<ModuleDefinition> modules) {
Expand Down
8 changes: 7 additions & 1 deletion Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -5454,6 +5454,12 @@ module {:extern "DCOMP"} DafnyToRustCompiler {
readIdents := recIdents;
r, resultingOwnership := FromOwned(r, expectedOwnership);
}
case ExactBoundedPool(of) => {
var exprGen, _, recIdents := GenExpr(of, selfIdent, env, OwnershipOwned);
r := R.std.MSel("iter").AsExpr().FSel("once").Apply1(exprGen);
readIdents := recIdents;
r, resultingOwnership := FromOwned(r, expectedOwnership);
}
case IntRange(typ, lo, hi, up) => {
var lo, _, recIdentsLo := GenExpr(lo, selfIdent, env, OwnershipOwned);
var hi, _, recIdentsHi := GenExpr(hi, selfIdent, env, OwnershipOwned);
Expand Down Expand Up @@ -5504,7 +5510,7 @@ module {:extern "DCOMP"} DafnyToRustCompiler {
// Integer collections are owned because they are computed number by number.
// Sequence bounded pools are also owned
var extraAttributes := [];
if collection.IntRange? || collection.UnboundedIntRange? || collection.SeqBoundedPool? {
if collection.IntRange? || collection.UnboundedIntRange? || collection.SeqBoundedPool? || collection.ExactBoundedPool? {
extraAttributes := [AttributeOwned];
}

Expand Down
41 changes: 37 additions & 4 deletions Source/DafnyCore/GeneratedFromDafny/DAST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5881,6 +5881,7 @@ public interface _IExpression {
bool is_SetBoundedPool { get; }
bool is_MapBoundedPool { get; }
bool is_SeqBoundedPool { get; }
bool is_ExactBoundedPool { get; }
bool is_IntRange { get; }
bool is_UnboundedIntRange { get; }
bool is_Quantifier { get; }
Expand Down Expand Up @@ -6105,6 +6106,9 @@ public static _IExpression create_MapBoundedPool(DAST._IExpression of) {
public static _IExpression create_SeqBoundedPool(DAST._IExpression of, bool includeDuplicates) {
return new Expression_SeqBoundedPool(of, includeDuplicates);
}
public static _IExpression create_ExactBoundedPool(DAST._IExpression of) {
return new Expression_ExactBoundedPool(of);
}
public static _IExpression create_IntRange(DAST._IType elemType, DAST._IExpression lo, DAST._IExpression hi, bool up) {
return new Expression_IntRange(elemType, lo, hi, up);
}
Expand Down Expand Up @@ -6160,6 +6164,7 @@ public static _IExpression create_Quantifier(DAST._IType elemType, DAST._IExpres
public bool is_SetBoundedPool { get { return this is Expression_SetBoundedPool; } }
public bool is_MapBoundedPool { get { return this is Expression_MapBoundedPool; } }
public bool is_SeqBoundedPool { get { return this is Expression_SeqBoundedPool; } }
public bool is_ExactBoundedPool { get { return this is Expression_ExactBoundedPool; } }
public bool is_IntRange { get { return this is Expression_IntRange; } }
public bool is_UnboundedIntRange { get { return this is Expression_UnboundedIntRange; } }
public bool is_Quantifier { get { return this is Expression_Quantifier; } }
Expand Down Expand Up @@ -6575,7 +6580,8 @@ public DAST._IExpression dtor_of {
var d = this;
if (d is Expression_SetBoundedPool) { return ((Expression_SetBoundedPool)d)._of; }
if (d is Expression_MapBoundedPool) { return ((Expression_MapBoundedPool)d)._of; }
return ((Expression_SeqBoundedPool)d)._of;
if (d is Expression_SeqBoundedPool) { return ((Expression_SeqBoundedPool)d)._of; }
return ((Expression_ExactBoundedPool)d)._of;
}
}
public bool dtor_includeDuplicates {
Expand Down Expand Up @@ -8159,6 +8165,33 @@ public override string ToString() {
return s;
}
}
public class Expression_ExactBoundedPool : Expression {
public readonly DAST._IExpression _of;
public Expression_ExactBoundedPool(DAST._IExpression of) : base() {
this._of = of;
}
public override _IExpression DowncastClone() {
if (this is _IExpression dt) { return dt; }
return new Expression_ExactBoundedPool(_of);
}
public override bool Equals(object other) {
var oth = other as DAST.Expression_ExactBoundedPool;
return oth != null && object.Equals(this._of, oth._of);
}
public override int GetHashCode() {
ulong hash = 5381;
hash = ((hash << 5) + hash) + 46;
hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._of));
return (int) hash;
}
public override string ToString() {
string s = "DAST.Expression.ExactBoundedPool";
s += "(";
s += Dafny.Helpers.ToString(this._of);
s += ")";
return s;
}
}
public class Expression_IntRange : Expression {
public readonly DAST._IType _elemType;
public readonly DAST._IExpression _lo;
Expand All @@ -8180,7 +8213,7 @@ public override bool Equals(object other) {
}
public override int GetHashCode() {
ulong hash = 5381;
hash = ((hash << 5) + hash) + 46;
hash = ((hash << 5) + hash) + 47;
hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._elemType));
hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._lo));
hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._hi));
Expand Down Expand Up @@ -8218,7 +8251,7 @@ public override bool Equals(object other) {
}
public override int GetHashCode() {
ulong hash = 5381;
hash = ((hash << 5) + hash) + 47;
hash = ((hash << 5) + hash) + 48;
hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._start));
hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._up));
return (int) hash;
Expand Down Expand Up @@ -8254,7 +8287,7 @@ public override bool Equals(object other) {
}
public override int GetHashCode() {
ulong hash = 5381;
hash = ((hash << 5) + hash) + 48;
hash = ((hash << 5) + hash) + 49;
hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._elemType));
hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._collection));
hash = ((hash << 5) + hash) + ((ulong)Dafny.Helpers.GetHashCode(this._is__forall));
Expand Down
Loading
Loading