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

fix: Make datatype cycle detection independent of auto-init #4997

Merged
merged 24 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5d45706
chore: Add documentation and sanity assertions
RustanLeino Jan 18, 2024
c868719
Compute IsObviouslyEmpty for inductive datatypes
RustanLeino Jan 18, 2024
d205272
Fix typo in comment
RustanLeino Jan 19, 2024
4036d59
Don’t use cache (that conflates all type-parrameter instantiations)
RustanLeino Jan 19, 2024
013546b
Also check cycles going through result type of total arrows
RustanLeino Jan 19, 2024
6fea52f
Add tests, and adjust for ordering for checks
RustanLeino Jan 19, 2024
a1f78c5
Simplify tests
RustanLeino Jan 19, 2024
bc9354b
Rename test file
RustanLeino Jan 19, 2024
98a3240
Add verification tests to confirm not auto-init
RustanLeino Jan 19, 2024
d6343ed
Set grounding-ctor-type-parameters and test compilation
RustanLeino Jan 19, 2024
8079558
Fix typo in comment
RustanLeino Jan 19, 2024
2fe447a
Merge branch 'master' into issue-4939
RustanLeino Jan 19, 2024
77f6046
Add release notes
RustanLeino Jan 19, 2024
2018422
Merge branch 'master' into issue-4939
RustanLeino Jan 19, 2024
5d1aec4
Merge branch 'master' into issue-4939
RustanLeino Jan 19, 2024
aec8edc
Fix whitespace
RustanLeino Jan 19, 2024
e660898
Don’t bother with cyclicity test if datatype had refinement error dur…
RustanLeino Jan 19, 2024
0cbc0dd
Change no-instance-because-of-datatype-cycle error into warning
RustanLeino Jan 22, 2024
a1275b1
Add a test that shows an empty datatype is provably empty
RustanLeino Jan 22, 2024
fc44f01
chore: Improve C#
RustanLeino Jan 23, 2024
2a660b5
fix: Box function-body results and let-RHS from datatype to trait
RustanLeino Jan 23, 2024
53ee5a4
Merge branch 'master' into issue-4939
RustanLeino Jan 23, 2024
84a81d5
Merge branch 'master' into issue-4939
ssomayyajula Jan 23, 2024
aad6805
Merge branch 'master' into issue-4939
RustanLeino Jan 24, 2024
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
Prev Previous commit
Next Next commit
Set grounding-ctor-type-parameters and test compilation
  • Loading branch information
RustanLeino committed Jan 19, 2024
commit d6343ed91b18c870bfa98e9ca085cd1b42e9f632
22 changes: 19 additions & 3 deletions Source/DafnyCore/AST/TypeDeclarations/IndDatatypeDecl.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

namespace Microsoft.Dafny;

public class IndDatatypeDecl : DatatypeDecl {
public override string WhatKind { get { return "datatype"; } }
public DatatypeCtor GroundingCtor; // set during resolution
[FilledInDuringResolution] public DatatypeCtor GroundingCtor; // set during resolution (possibly to null)

public override DatatypeCtor GetGroundingCtor() {
return GroundingCtor;
return GroundingCtor ?? Ctors.FirstOrDefault(ctor => ctor.IsGhost, Ctors[0]);;
}

public bool[] TypeParametersUsedInConstructionByGroundingCtor; // set during resolution; has same length as the number of type arguments
private bool[] typeParametersUsedInConstructionByGroundingCtor = null;

public bool[] TypeParametersUsedInConstructionByGroundingCtor {
ssomayyajula marked this conversation as resolved.
Show resolved Hide resolved
get {
if (typeParametersUsedInConstructionByGroundingCtor == null) {
typeParametersUsedInConstructionByGroundingCtor = new bool[TypeArgs.Count];
for (var i = 0; i < typeParametersUsedInConstructionByGroundingCtor.Length; i++) {
typeParametersUsedInConstructionByGroundingCtor[i] = true;
}
}
return typeParametersUsedInConstructionByGroundingCtor;
}
set {
typeParametersUsedInConstructionByGroundingCtor = value;
}
}

public enum ES { NotYetComputed, Never, ConsultTypeArguments }
public ES EqualitySupport = ES.NotYetComputed;
Expand Down
2 changes: 1 addition & 1 deletion Source/DafnyCore/Resolver/ModuleResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2941,7 +2941,7 @@ public ReportOtherAdditionalInformation_Visitor(ModuleResolver resolver)
}

/// <summary>
/// Check that the datatype has some constructor all whose argument types can be constructed.
/// Check if the datatype has some constructor all whose argument types can be constructed.
/// Returns 'true' and sets dt.GroundingCtor if that is the case.
/// </summary>
bool ComputeGroundingCtor(IndDatatypeDecl dt) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %testDafnyForEachCompiler "%s" -- --general-traits=datatype

module NoAutoInit {
trait GeneralTrait { }
trait ReferenceTrait extends object { }

datatype A = A(g: GeneralTrait)
datatype B = B(h: ReferenceTrait)

method Main() {
// Test that code generation succeeds, even thought "a" and "b" are never defined or used
var a: A := *;
var b: B := *;
print "done\n";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
done