Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Conversation

@bamarsha
Copy link
Contributor

@bamarsha bamarsha commented Aug 19, 2020

This PR updates the naming scheme in the generated C# to avoid conflicts with Q# identifiers. It assumes the Q# compiler reserves __ and _. anywhere in an identifier or namespace name, and _ at the end of namespace names.

C# generation also has its own list of reserved words. If these words are used, there is no error, but the name has __ appended to it to avoid a conflict:

  • Data
  • Deconstruct
  • Info
  • Run
  • ItemN where N is a natural number
  • The name of the enclosing operation, function, or UDT class

Any built-in member names that are defined in a generated class need to be:

  1. In the reserved word list, or
  2. Surrounded on both sides by __, or
  3. Implemented via an explicit interface.

The protected properties in an operation class that are generated for referenced callables use this encoding:

  • If the property name uses the fully-qualified name of the callable, . is replaced with __.
  • Otherwise, __ is appended to the end (but not the beginning, to avoid conflicts with built-in property names like __Body__).

TODO:

  • Update tests.
  • Add test cases for resolved issues.
  • Run an end-to-end build.
  • Enable the Data test after it is removed from the compiler's reserved words.

Related issues:

@bamarsha bamarsha marked this pull request as ready for review August 19, 2020 23:46
@bamarsha
Copy link
Contributor Author

Also, tip for reviewers: this PR looks scarier than it is. :) The main changes are in:

  • AbstractCallable.cs
  • EntryPoint.fs
  • Function.cs
  • MemberNames.qs
  • Operation.cs
  • SimulationCode.fs

The rest I think should only be trivial renamings in response to these changes.

Copy link
Contributor

@ScottCarda-MS ScottCarda-MS left a comment

Choose a reason for hiding this comment

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

Thanks for pointing out where to find the main changes. That made reviewing much easier.

@bamarsha bamarsha merged commit 4a3eca4 into master Aug 28, 2020
@bamarsha bamarsha deleted the samarsha/csharp-naming branch August 28, 2020 21:58
bamarsha added a commit to microsoft/QuantumKatas that referenced this pull request Aug 28, 2020
This updates the QuantumKatas repo for the breaking changes to the Q# runtime that will be made by microsoft/qsharp-runtime#349:

* Rename `Body` to `__Body__` in CounterSimulator.cs

Co-authored-by: Sarah Marshall <samarsha@microsoft.com>
Co-authored-by: Mariia Mykhailova <mamykhai@microsoft.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

4 participants