-
Notifications
You must be signed in to change notification settings - Fork 271
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
Support all option types in the project file #4506
Merged
keyboardDrummer
merged 21 commits into
dafny-lang:master
from
keyboardDrummer:supportAllOptionTypesInProjectFile
Sep 12, 2023
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0beaffb
Support all option types in the project file
keyboardDrummer 4946ac6
Merge branch 'master' into supportAllOptionTypesInProjectFile
keyboardDrummer 7a6914d
Add release note and fix path resolution in Dafny project file
keyboardDrummer 81c7863
Merge branch 'supportAllOptionTypesInProjectFile' of github.com:keybo…
keyboardDrummer 8b3b1ee
Merge branch 'master' into supportAllOptionTypesInProjectFile
keyboardDrummer 32c61ba
Merge branch 'master' into supportAllOptionTypesInProjectFile
keyboardDrummer e913591
Fixes for using library in options
keyboardDrummer c89fd32
Update release notes
keyboardDrummer 327817f
Merge branch 'master' into supportAllOptionTypesInProjectFile
keyboardDrummer 8df76c8
Run formatter
keyboardDrummer 9e29a2a
Merge branch 'supportAllOptionTypesInProjectFile' of github.com:keybo…
keyboardDrummer 7dde794
More fixes
keyboardDrummer 19ca042
Merge branch 'master' into supportAllOptionTypesInProjectFile
keyboardDrummer 177f6cb
Trigger CI
keyboardDrummer 3146dc2
Merge branch 'supportAllOptionTypesInProjectFile' of github.com:keybo…
keyboardDrummer e6a4a50
usesLibrary test now passes
keyboardDrummer d52dd2c
Merge branch 'master' into supportAllOptionTypesInProjectFile
keyboardDrummer e7c0a23
Merge branch 'master' into supportAllOptionTypesInProjectFile
keyboardDrummer 282a0ec
Merge branch 'master' into supportAllOptionTypesInProjectFile
keyboardDrummer 5e499c2
Make test more stable
keyboardDrummer bbab8ae
Merge branch 'master' into supportAllOptionTypesInProjectFile
keyboardDrummer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Tomlyn.Model; | ||
|
||
namespace DafnyCore.Generic; | ||
|
||
public static class TomlUtil { | ||
|
||
public static bool TryGetValueFromToml(TextWriter errorWriter, string sourceDir, string tomlPath, Type type, object tomlValue, out object value) { | ||
if (tomlValue == null) { | ||
value = null; | ||
return false; | ||
} | ||
|
||
if (type.IsAssignableFrom(typeof(List<string>))) { | ||
return TryGetListValueFromToml<string>(errorWriter, sourceDir, tomlPath, (TomlArray)tomlValue, out value); | ||
} | ||
if (type.IsAssignableFrom(typeof(List<FileInfo>))) { | ||
return TryGetListValueFromToml<FileInfo>(errorWriter, sourceDir, tomlPath, (TomlArray)tomlValue, out value); | ||
} | ||
|
||
if (tomlValue is string tomlString) { | ||
if (type == typeof(FileInfo)) { | ||
// Need to make sure relative paths are interpreted relative to the source of the value, | ||
// not the current directory. | ||
var fullPath = sourceDir != null ? Path.GetFullPath(tomlString, sourceDir) : tomlString; | ||
value = new FileInfo(fullPath); | ||
return true; | ||
} | ||
|
||
if (typeof(Enum).IsAssignableFrom(type)) { | ||
try { | ||
value = Enum.Parse(type, tomlString); | ||
return true; | ||
} catch (ArgumentException) { | ||
value = null; | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
if (!type.IsInstanceOfType(tomlValue)) { | ||
if (type == typeof(string)) { | ||
value = tomlValue.ToString(); | ||
return true; | ||
} | ||
errorWriter.WriteLine( | ||
$"Error: property '{tomlPath}' is of type '{tomlValue.GetType()}' but should be of type '{type}'"); | ||
value = null; | ||
return false; | ||
} | ||
|
||
value = tomlValue; | ||
return true; | ||
} | ||
|
||
private static bool TryGetListValueFromToml<T>(TextWriter errorWriter, string sourceDir, string tomlPath, TomlArray tomlValue, out object value) { | ||
var success = true; | ||
value = tomlValue.Select((e, i) => { | ||
if (TryGetValueFromToml(errorWriter, sourceDir, $"{tomlPath}[{i}]", typeof(T), e, out var elementValue)) { | ||
return (T)elementValue; | ||
} | ||
success = false; | ||
return default(T); | ||
}).ToList(); | ||
return success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ Warning: only Dafny project files named dfyconfig.toml are recognised by the Daf | |
Warning: option 'does-not-exist' that was specified in the project file, is not a valid Dafny option. | ||
|
||
Dafny program verifier did not attempt verification | ||
Error: property 'warn-shadowing' is of type 'System.Int64' but should be of type 'System.Boolean' | ||
Error: Could not parse value '3' for option 'warn-shadowing' that has type 'Boolean' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much better error message. |
||
input.dfy(6,8): Warning: Shadowed local-variable name: x | ||
moreInput.dfy(6,8): Warning: Shadowed local-variable name: x | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
The Dafny IDE now has improved behavior when working with a Dafny file that's part of a Dafny project. A Dafny file is part of a project if a `dfyconfig.toml` can be found somewhere in the file's path hierarchy, such as in the same folder or in the parent folder. A `dfyconfig.toml` can specify which Dafny options to use for that project, and can specify which Dafny files are part of the project. By default, the project will include all .dfy files reachable from the folder in which the `dfyconfig.toml` resides. Project related features of the IDE are: | ||
- Whenever one file in the project is opened, diagnostics for all files in the Dafny project are shown. When including a file with errors that's part of the same project, the message "the included file contains errors" is no longer shown. Instead, the included file's errors are shown directly. | ||
- If any file in the project in changed, diagnostics for all files in the project are updated. Without a project, changing an included file will not update diagnostics for the including file until the including file is also changed. | ||
- If any file in the project is resolved, all files in the project are resolved. Opening a file in a project that's already resolved means the opened file is resolved instantly. | ||
- The IDE's memory consumption stays the same regardless of how many files in a project are opened. Without a project, the IDE increases it's memory usage for each open file. | ||
- If any file in the project is changed, diagnostics for all files in the project are updated. Without a project, changing an included file will not update diagnostics for the including file until the including file is also changed. | ||
- The find references feature (also added in this release), works better in files that are part of a project, since only then can it find references that are inside files that include the current file. | ||
- The assisted rename feature (also added in this release), only works for files that are part of a project. | ||
- For files that are part of a project, the Dafny IDE does not require the use of include directives to work, and neither does the CLI if you run it using the project file. This means that Dafny projects can be used without use include directives for files inside the project. When using library files that are outside the project, it's still necessary to use includes. | ||
- When using a project file, it is no longer necessary to use include directives. In the previous version of Dafny, it was already the case that the Dafny CLI, when passed a Dafny project file, does not require include directives to process the Dafny program. The same now holds for the Dafny IDE when working with Dafny files for which a project file can be found. | ||
- If any file in the project is resolved, all files in the project are resolved. Opening a file in a project that's already resolved means the opened file is resolved instantly. | ||
- The IDE's memory consumption stays the same regardless of how many files in a project are opened. Without a project, the IDE increases it's memory usage for each open file. | ||
|
||
Try out the IDE's project support now by creating an empty `dfyconfig.toml` file in the root of your project repository. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Support all types of options in the Dafny project file (dfyconfig.toml) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your test, could you please add an option that was otherwise translated to an enum or otherwise processed?
For example:
test-assumptions = externs
It serves no purpose for your example other than testing that the parsing mechanism works (which it did not until this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quantifier-syntax
is an enum type option, even though it looks like an int. If I just addtest-assumptions = externs
without testing its effects, then it's not testing much is it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh great, you got my point and that's perfect then.