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: Per-backend code support in standard libraries, FileIO library #4790

Merged

Conversation

robin-aws
Copy link
Member

@robin-aws robin-aws commented Nov 16, 2023

Description

Adds build support for standard libraries with different Dafny and target language source code per backend, and imports the FileIO library.

The build support mainly adds a set of DafnyStandardLibraries-<target>.doo files, and a common DafnyStandardLibraries-notarget.doo file with only the abstract interface. The pattern looks a lot like replaceable modules, but is less efficient for now because it re-verifies common code rather than relying on refinement.

Please pay particular attention to the documentation updates as this does slightly affect the user experience with standard libraries!

Major changes to FileIO on the way in:

  • Refactored to separate the externs into its own module, so it could be defined differently per backend without duplicating the common wrapper logic.
  • Added support for Go and Javascript.
  • Removed the comments about additional source files in the README.md since it's all automatic now (yay!)

Other supporting changes:

  • Fixes {:compile false} has no effect on modules #4782, as otherwise Go was messy to implement and Python nearly impossible.
  • Added utilities in the Go runtime for converting between _dafny.Sequence and []byte.
  • Added an automatic build of Dafny itself at the end of make update-binary, since failing to do that and therefore not picking up the new versions of the .doo files was a common gotcha.
  • Switched CI job that tests the standard libraries from Ubuntu to Mac OS: diffing checked in .doo files against fresh builds of them was failing for what looks like whitespace/newline variation. It makes more sense to stick to Mac OS for verification of production Dafny code anyway, however, since most contributors are developing on macs and verification is not guaranteed to be consistent across platforms.

How has this been tested?

StandardLibraries_TargetSpecific.dfy for the general support, FileIOExamples.dfy for FileIO itself (mainly the same as the original library, adapted as Dafny tests instead of lit tests)

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

…-backend-code-support-in-stdlibs

# Conflicts:
#	Source/DafnyDriver/Commands/DafnyCli.cs
#	Source/DafnyPipeline/DafnyPipeline.csproj
#	Source/DafnyStandardLibraries/Makefile
#	Source/DafnyStandardLibraries/binaries/DafnyStandardLibraries.doo
#	Source/DafnyStandardLibraries/src/dfyconfig.toml
(just capturing to come back to later)
…in-aws/dafny into per-backend-code-support-in-stdlibs

# Conflicts:
#	Source/DafnyStandardLibraries/binaries/DafnyStandardLibraries-arithmetic.doo
#	Source/DafnyStandardLibraries/binaries/DafnyStandardLibraries.doo
@robin-aws robin-aws changed the title Per backend code support in stdlibs feat: Per backend code support in standard libraries, FileIO library Nov 16, 2023
@robin-aws robin-aws changed the title feat: Per backend code support in standard libraries, FileIO library feat: Per-backend code support in standard libraries, FileIO library Nov 16, 2023
@robin-aws robin-aws marked this pull request as ready for review November 16, 2023 17:17
Source/DafnyStandardLibraries/CONTRIBUTING.md Outdated Show resolved Hide resolved
Source/DafnyStandardLibraries/CONTRIBUTING.md Outdated Show resolved Hide resolved
Source/DafnyStandardLibraries/CONTRIBUTING.md Outdated Show resolved Hide resolved
Source/DafnyStandardLibraries/CONTRIBUTING.md Outdated Show resolved Hide resolved
Source/DafnyStandardLibraries/CONTRIBUTING.md Show resolved Hide resolved
*
* File path symbols including . and .. are allowed.
*/
module DafnyStdLibs.FileIO {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: It seems a bit strange to name this file with all the different target languages it supports. In particular, once we add support for another target language, we'd change the filename but not its contents.

edit: I see now that the Makefile uses the filename to detect in which languages the file should be included - this seems a bit hacky, but I don't think it's a blocker for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is definitely a bit hacky, but the cleanest thing I could figure out without a lot of code duplication. We'll want to design a better solution for all multi-target Dafny projects in the future for sure.

// But it makes debugging the translated output a little clearer.
{:compile false}
{:extern "DafnyStdLibs_FileIOInternalExterns"}
{:dummyImportMember "INTERNAL__ReadBytesFromFile", false}
Copy link
Contributor

Choose a reason for hiding this comment

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

(not blocking) What does this attribute do? I don't see it in (the current development version of) the reference manual.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was added in #4713, it's working around #2953 (which fortunately should be addressed soon: #4777)

robin-aws and others added 4 commits November 16, 2023 11:23
Co-authored-by: Alex Chew <alex-chew@users.noreply.github.com>
…n-aws/dafny into per-backend-code-support-in-stdlibs

# Conflicts:
#	Source/DafnyStandardLibraries/CONTRIBUTING.md
alex-chew
alex-chew previously approved these changes Nov 16, 2023
Copy link
Contributor

@alex-chew alex-chew left a comment

Choose a reason for hiding this comment

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

LGTM

Appears to be a race condition
@robin-aws robin-aws enabled auto-merge (squash) November 16, 2023 23:33
@robin-aws robin-aws merged commit 7c91ceb into dafny-lang:master Nov 17, 2023
20 checks passed
@robin-aws robin-aws deleted the per-backend-code-support-in-stdlibs branch November 17, 2023 00:24
@keyboardDrummer
Copy link
Member

Awesome!

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.

{:compile false} has no effect on modules
3 participants