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

Request: converting/adapting Dafny values to native language values #73

Open
robin-aws opened this issue Jan 26, 2023 · 2 comments
Open
Assignees

Comments

@robin-aws
Copy link
Member

Very broad category, probably at least will become one library per target language.

Nearly all compiled Dafny code needs to convert between Dafny string values and native language string values for example. Projects like the Dafny ESDK have utilities for this, but not only is this not something Dafny users should have to implement themselves, but the linked implementation is coupled to Dafny compiler/runtime internals that are not guaranteed to remain stable across releases (and have definitely changed in the past, for good reasons).

In the long term it would be wonderful to not only provide these conversion functions, but also provide meta-utilities to generate the calls to these conversions automatically via something like annotations.

@robin-aws
Copy link
Member Author

Also note another goal is to avoid making independent copies of data where possible. E.g. the Java backend allows you to wrap a java.lang.String as a Dafny.Sequence<Character> (with --unicode-char disabled at least).

@robin-aws robin-aws self-assigned this Mar 7, 2023
@mattmccutchen-amazon
Copy link

I asked about a way to convert between a Java String and the DafnySequence<CodePoint> representing a Dafny unicode string, and Robin pointed me to this existing issue. I'm adding some keywords in the hope of making it easier for the next person to find in a web search.

In the meantime, as of this writing, the conversion can be done via DafnySequence.asUnicodeString and DafnySequence.verbatimString. Those are not officially supported APIs and may be removed at any time, but the alternative is basically to copy and paste them into your project, so pick the lesser evil between unconditionally duplicating that code now and taking the risk that your program breaks later and you have to copy/paste the code then.

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

No branches or pull requests

2 participants