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

Use async main methods to avoid waiting for tasks at the top level #4585

Merged

Conversation

keyboardDrummer
Copy link
Member

@keyboardDrummer keyboardDrummer commented Sep 26, 2023

Changes

  • Update the legacy Dafny server code so it does not refer Console.Out/Error/In, so its can be run in parallel next to other Dafny tests.
  • Change the CoverageReport code so it does not depend on a static counter, which could cause issues when running multiple Dafny instances in parallel.
  • Change the legacy parser code so it does not print error message to Console.Error, which causes issues when running multiple Dafny instances in parallel.
  • Add a timeout to individual littish tests of 5 minutes. Currently a stuck littish test will cause the entire test suite to hang until it times out at the Github actions level, which we've configured to 120 minutes, after which we get no indication of which test it was stuck on !!
  • Refactoring of littish testing code
  • Remove two occurrences of #pragma warning disable VSTHRD002 by relying on async Main methods. An effect of this change might be that Dafny will use fewer threads. I was triggered to make this change when I was debugging Dafny and noticed some threads always waiting at the locations where this PR removes the Wait.

Testing

This is a refactoring which is covered by existing tests.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@robin-aws
Copy link
Member

Comment as a spin-off from #4798 - can we also add a link to an issue on the remaining pragmas this PR doesn't end up resolving?

@keyboardDrummer keyboardDrummer requested review from MikaelMayer and fabiomadge and removed request for robin-aws and MikaelMayer February 8, 2024 21:40
@keyboardDrummer keyboardDrummer requested review from MikaelMayer and removed request for fabiomadge February 12, 2024 10:48
Copy link
Member

@MikaelMayer MikaelMayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

var path = attempt + "." + extension;
while (File.Exists(path)) {
suffix++;
path = attempt + "_" + suffix + "." + extension;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@@ -8,6 +8,8 @@ namespace Microsoft.Dafny;

public class CommonOptionBag {

public static void EnsureStaticConstructorHasRun() { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this method doing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the name says it does. If you call a method in a class, dotnet will first ensure the class's static constructor was run.

using Microsoft.Dafny;

namespace Dafny;

public class Dafny {
public static int Main(string[] args) {
public static Task<int> Main(string[] args) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know you could do that. Interesting. I understand it's to be able to test this method directly; but how is it compiled? It will await for that task?

Copy link
Member Author

@keyboardDrummer keyboardDrummer Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea ! I'm pretty sure it won't exit before the Task is done though :-D

}
}
if (state.EncounteredErrors) {
ErrorWriter.WriteLine("Use /help for available options");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ErrorWriter.WriteLine("Use /help for available options");
ErrorWriter.WriteLine("Use --help for available options");

Since we can now customize this error message, I thought we could as well support the new CLI by default.

Copy link
Member Author

@keyboardDrummer keyboardDrummer Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should do that. This is printed when you're already using the old CLI.

@@ -50,4 +50,6 @@ static class TestCommand {
});
return result;
}

public static void EnsureStaticConstructorHasRun() { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, is it possible the static constructor to not run if you don't call this method?

Copy link
Member Author

@keyboardDrummer keyboardDrummer Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't use a class, then its static constructor is not run.

var withoutExtension = Path.GetFileNameWithoutExtension(desiredPath);
var actualPath = desiredPath;
while (File.Exists(actualPath)) {
actualPath = withoutExtension + "_" + index + extension;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like duplicate code from https://github.com/dafny-lang/dafny/pull/4585/files#diff-8f346d4cacb8d208b553e6e51abc34de1f262354c3901eff9416e148f0c6e19bR25
could you perhaps consolidate and define this code only once?

@@ -10,7 +10,7 @@
<body onload="window['PR_TAB_WIDTH']=4">
<div class="menu" id="menu">
<a href="./index_combined.html">Index</a>
<a href="ProofDependencies.dfy_tests_expected_2.html" class="el_report">Expected Test Coverage (coverage_testing)</a><a href="ProofDependencies.dfy_verification_3.html" class="el_report">Verification coverage (coverage_verification)</a>
<a href="ProofDependencies.dfy_tests_expected.html" class="el_report">Expected Test Coverage (coverage_testing)</a><a href="ProofDependencies.dfy_verification.html" class="el_report">Verification coverage (coverage_verification)</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, avoiding the global counter makes sure files with a different name don't get a useless suffice. Great!

Copy link
Member

@MikaelMayer MikaelMayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not expecting to delete the duplicate code, rather put it at the same place, but it looks like you figured out it was not necessary.

@keyboardDrummer keyboardDrummer merged commit 9604175 into dafny-lang:master Feb 13, 2024
20 checks passed
@keyboardDrummer keyboardDrummer deleted the doNotWaitForTasksAtTheTop branch February 13, 2024 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants