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

Feature request: specifying the target language parent namespace when compiling #4322

Closed
robin-aws opened this issue Jul 21, 2023 · 0 comments · Fixed by #4591
Closed

Feature request: specifying the target language parent namespace when compiling #4322

robin-aws opened this issue Jul 21, 2023 · 0 comments · Fixed by #4591
Assignees
Labels
kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag

Comments

@robin-aws
Copy link
Member

Projects that want to embed compiled Dafny code inside libraries will frequently want to isolate the compiled code under a specific namespace. For example:

module {:extern "software.amazon.cryptography.materialproviders.internaldafny.types" } AwsCryptographyMaterialProvidersTypes

The challenge with using :extern for this is that it's not realistic to expect a single symbol to make sense for all target languages. Several suggestions have been made to allow specifying extern names per language somehow:

For the specific case of just relocating the compiled code, however, it would be a lot simpler to just provide a prefix namespace when building the code on a per-language basis. This would be adequate for smithy-dafny, since the user-facing target language symbols are generated from Smithy models instead anyway, so there is actually no need for precise control over extern attributes.

As a strawperson proposal, this could just be an option like --compile-prefix "software.amazon.cryptography.materialproviders.internaldafny", although it may be poor UX to have a single term across all languages, even if the build or configuration of a project can provide different values for each target language.

@robin-aws robin-aws added the kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny label Jul 21, 2023
@alex-chew alex-chew added the part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag label Jul 26, 2023
@keyboardDrummer keyboardDrummer self-assigned this Sep 19, 2023
@robin-aws robin-aws added this to the Dafny Standard Libraries milestone Oct 11, 2023
keyboardDrummer added a commit that referenced this issue Oct 17, 2023
Fixes #4322

Depends on #4601

### Changes
- For C#, add the option `--outer-namespace`: `All generated code will
be nested inside the outer namespace. Option can be specified multiple
times for deeper nesting`.
- For Java, add the option `--outer-package`: `All generated code will
be nested inside the outer package. Option can be specified multiple
times for deeper nesting`.
- In some back-ends, the presence of a default module could be
translated away, but this is troublesome when using an
`--outer-namespace` in which the default module should also be placed.
This PR lets the default module behave more like other modules when
translating, so more `_module` ends up in the generated code. If we want
to get rid of this, I suggest we don't add special casing for the
default module, but instead try to avoid qualifying references more than
needed during translation.

### Testing
- Add test that verifies that all back-ends can run code when using
`--outer-namespace`
- Add tests for C#, Java and Javascript that checks that the code
generated by these back-ends uses `--outer-namespac` when it is
specified.

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants