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

Derive property of type access #1300

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

keyboardDrummer
Copy link
Member

@keyboardDrummer keyboardDrummer commented Jul 13, 2021

Use type information to generate code for Expression.SubExpressions, Statement.SubExpressions, Statement.SubStatements and ComponentTypes.

  • Reduce the size of DafnyAst.cs by about ~400 lines. Note that the absolute size change is smaller because auto-formatting has added extra lines such as white-lines between methods.
  • Prevent bugs like this and this
  • Add a missing SubExpressions implementation for AssignOrReturnStmt, ChainingExpression

We don't expect any relevant changes in performance. While the code generation uses reflection, which is slow, the generated code does not use reflection. The code generation only runs once per instance of Dafny so the time spent on that is negligible.

Caveats

  1. The generation code is much more complex than the code it generates, although we expect to rarely touch it.
  2. The generated code cannot be stepped into when debugging.
  3. When running 'Usages' on fields or properties that are used by the generated code, the usages don't appear.

Alternatives

Instead of runtime code generation, we can use compile-time code generation which resolves caveat 2 and 3 from above. With source generators we don't have the downside of having to run a separate generation process as part of the build and the IDE clearly identifies the generated code. Note that Source generators are still in preview.

@keyboardDrummer keyboardDrummer force-pushed the derivePropertyOfTypeAccess branch 3 times, most recently from 33c50d6 to bc8a6ac Compare July 19, 2021 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment