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

Dafny 4.0 suggestion: Break up {:extern} and support language specificities #2397

Open
MikaelMayer opened this issue Jul 12, 2022 · 4 comments
Labels
area: ffi The {:extern} attribute and otherwise interfacing with code in other languages kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny misc: cleanup Cleanups in the implementation or in corners of the language misc: language proposals Proposals for change to the language that go beyon simple enhancement requests

Comments

@MikaelMayer
Copy link
Member

Currently, the annotation {:extern} and {:compile false} are used intertwined in three different cases

  • {:extern "newName"} Here is how this method, module or function name should be compiled and accessed externally (this is what we export)
  • {:extern} This method or function is defined externally, here is their signature, don't compile it. (this is what we import)
  • {:extern "newName"} {:compile false}: this weird case is that, if we want to import a method or function with a different Dafny name that the real name, we need to use the export syntax but indicate we are not compiling it. Why we are not compiling it? It's not primarly because we want to deactivate compilation. It's because we want to import the definition.

My point is, it looks like hot and cold taps: We all want to adjust temperature and pressure independently, not the individual amounts of hot and hold. In our case, "hot" is {:extern} and "cold" is {:compile false}, and "temperature" is "I want to import this from external Dafny code" and "pressure" is "I want to export this". Moreover, in both cases, we want to be able to specify language-specific names.

Here is my breaking proposal for Dafny 4. We get rid of the existing {:extern [[<string>,] <string>]} and {:compile false}, and instead rely on two new attributes {:compile <string>} and {:import [[<string>,] <string|map<string,string>>]}, like this:

  • {:compile "name"} At the time of compilation, replaces Dafny's symbol by "name" at definition site and at call site. Should work for any language. Previously {:extern "name"}.
  • {:compile map["csharp" := "name"]} Same as before, except that we can associate a name for every language, and fail if the compile target does not support that language. Did not exist previously.
  • {:import} to import an existing external symbol in Dafny with the same name. Should work for any language. Previously {:extern} (which has an implicit {:compile false}).
  • {:import "F"} to import the existing external symbol F in Dafny, overriding Dafny's symbol "name". Should work for any language. Previously {:extern "F"} {:compile false}.
  • {:import map["csharp", "name"]} same as before, except we restrict the languages target from which we can import the symbol "name". Did not exist previously.
  • {:import "Module", "F"} to import the existing external symbol Module.F in Dafny. Should work for any language. Previously {:extern "Module", "F"} {:compile false}.
@MikaelMayer MikaelMayer added misc: cleanup Cleanups in the implementation or in corners of the language breaking-change Any change that will cause existing Dafny codebases to break (excluding verification instability) misc: language proposals Proposals for change to the language that go beyon simple enhancement requests labels Jul 12, 2022
@MikaelMayer MikaelMayer changed the title Dafny 4.0 suggestion: Break up {:extern} and support language-specific. Dafny 4.0 suggestion: Break up {:extern} and support language specificities Jul 12, 2022
@seebees
Copy link

seebees commented Jul 12, 2022

I like the name changes.
Why can I not {:compile "Module", "name"}?

While I can see some benefit for {:compile map["csharp" := "name"]} this adds a lot of complexity. How would you see using this?

{:import map["csharp", "name"]} I do not believe that the same function exists in different runtimes with different names, but the same "signature". Do you have an example?

@cpitclaudel
Copy link
Member

I have no strong feelings, but we should be careful to not create more confusing terminology do we know other languages that use "export" and "import" in this sense?

C uses extern like Dafny (to prevent a name from being mangled), and uses the absence of a body for what we call {:compile false}.

For me the main issue with Dafny's extern/compile attributes today is that {:extern} sometimes implies {:compile false}, and sometimes doesn't, depending on which kind of entity it is applied to.

@robin-aws robin-aws added the area: ffi The {:extern} attribute and otherwise interfacing with code in other languages label Jul 13, 2022
@robin-aws
Copy link
Member

Related prior discussion: #469

@robin-aws
Copy link
Member

I agree the FFI badly needs an overhaul in general. Another aspect you don't mention is the common use case, not directly supported at all, of wanting to expose a Dafny-idiomatic signature as a target language-idiomatic signature (e.g. mapping a Dafny string to a java.lang.String instead of a Dafny.Sequence<Character>).

Given this is a highly complex design space, I'd prefer not to rush getting it right so that it can make the Dafny 4.0 train. It looks like we're leaning towards fresh terms and deprecating the existing ones anyway, which we can do with deprecation and doesn't require an immediate major version bump.

@robin-aws robin-aws removed the breaking-change Any change that will cause existing Dafny codebases to break (excluding verification instability) label Sep 13, 2022
@keyboardDrummer keyboardDrummer added the kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ffi The {:extern} attribute and otherwise interfacing with code in other languages kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny misc: cleanup Cleanups in the implementation or in corners of the language misc: language proposals Proposals for change to the language that go beyon simple enhancement requests
Projects
None yet
Development

No branches or pull requests

5 participants