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

C# runtime's tuple deconstruction incompatible with .NET Framework pre-4.7 #1951

Closed
alex-chew opened this issue Mar 30, 2022 · 7 comments
Closed
Labels
kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny lang: c# Dafny's C# transpiler and its runtime part: runtime Happens in Dafny's runtime (Add a `lang` tag if relevant)

Comments

@alex-chew
Copy link
Contributor

The C# runtime in Dafny v3.5.0 uses tuple deconstruction (see first and last lines):

var (leftBuffer, rightBuffer) = (left, right);
if (left == null || right == null) {
// elmts can't be .IsDefault while either left, or right are null
return elmts;
}
toVisit.Push(rightBuffer);
toVisit.Push(leftBuffer);
while (toVisit.Count != 0) {
var seq = toVisit.Pop();
if (seq is ConcatSequence<T> cs && cs.elmts.IsDefault) {
(leftBuffer, rightBuffer) = (cs.left, cs.right);

This is problematic because it fails to compile on .NET Framework versions below 4.7, which are missing runtime support for this feature:

error CS8179: Predefined type 'System.ValueTuple`2' is not defined or imported [/home/runner/work/Foobar.csproj]
error CS8130: Cannot infer the type of implicitly-typed deconstruction variable 'leftBuffer'.
error CS8130: Cannot infer the type of implicitly-typed deconstruction variable 'rightBuffer'.
error CS8179: Predefined type 'System.ValueTuple`2' is not defined or imported

This seems to be a known issue that can be worked around either by manually deconstructing the tuple, or by depending on the System.ValueTuple package.

@alex-chew
Copy link
Contributor Author

To add some context - we want to support .NET Framework 4.6.2 because Microsoft hasn't announced an end-of-support date: https://docs.microsoft.com/en-us/lifecycle/products/microsoft-net-framework

@texastony
Copy link

Ideally, Dafny would advertise the details of the supported compiled languages:
i.e.: Dafny's compiled output uses features from JavaScript X, Java Y, Go Z, etc.

@cpitclaudel
Copy link
Member

Ideally, Dafny would advertise the details of the supported compiled languages:

Or even better it would target a version so old that this issue doesn't even pop up

texastony added a commit to aws/aws-encryption-sdk-dafny that referenced this issue Mar 30, 2022
Ran `dotnet add package "System.ValueTuple"` to add System.ValueTuple
as a dependency of the AWSEncryptionSDK.
@alex-chew
Copy link
Contributor Author

Ideally, Dafny would advertise the details of the supported compiled languages:

Or even better it would target a version so old that this issue doesn't even pop up

Regardless of the age of language runtime versions that Dafny supports, I'd still prefer that Dafny be explicit about which versions it supports.

@alex-chew
Copy link
Contributor Author

(To clarify, the workaround of depending on System.ValueTuple works fine for us, and we're not in a rush to remove that workaround.)

@fabiomadge fabiomadge added lang: c# Dafny's C# transpiler and its runtime kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: runtime Happens in Dafny's runtime (Add a `lang` tag if relevant) labels Mar 31, 2022
@robin-aws
Copy link
Member

Ideally, Dafny would advertise the details of the supported compiled languages:
i.e.: Dafny's compiled output uses features from JavaScript X, Java Y, Go Z, etc.

Split off #1983 to track this as a separate and actually more important ask.

@atomb
Copy link
Member

atomb commented Apr 16, 2024

I believe that this issue is fixed. Looking at the latest version of the runtime, it no longer uses tuple destruction. We're also building the runtime for framework net452, which I would imagine would fail if we were using features introduced more recently.

@atomb atomb closed this as completed Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny lang: c# Dafny's C# transpiler and its runtime part: runtime Happens in Dafny's runtime (Add a `lang` tag if relevant)
Projects
None yet
Development

No branches or pull requests

6 participants