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

Proposal for the Dyn Type #154

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Proposal for the Dyn Type #154

wants to merge 2 commits into from

Conversation

spignorel
Copy link

This proposal introduces a Dyn type to reflect values that are only known at runtime.

@spignorel spignorel marked this pull request as ready for review August 3, 2022 23:43
Copy link
Contributor

@cgranade cgranade 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 pinging me on this, @spignorel! I think my biggest overall question would be how we would document, explain, and expose this to users; a lot of the approximations, for instance, seem very reasonable but may take users by surprise unless we can offer good feedback as early as possible.

Approved/dyn-type.md Show resolved Hide resolved
Approved/dyn-type.md Outdated Show resolved Hide resolved
Approved/dyn-type.md Show resolved Hide resolved
Approved/dyn-type.md Show resolved Hide resolved
Approved/dyn-type.md Show resolved Hide resolved
Approved/dyn-type.md Show resolved Hide resolved

The analyzers are run for one callable at a time (same as it is the case today). They will be run once in (more or less) the same way as they are today, and produce the same attribute they are today - i.e. the first pass of the analyzers analyzes the requirements of the callable under the assumption that all arguments are non-dyn values.

Additionally, we will run the analyzers once for each parameter of the callable. This pass will produce an additional attribute per parameter that indicates the required runtime capability if a specific parameter is `dyn` instead of non-`dyn`. We hence end up with n+1 attribute on the callable, where n is the number of parameters. For each call to the callable, the required capability for that call is given by the sum of the required capabilities for the callable itself plus those for of the `dyn` arguments.
Copy link
Contributor

Choose a reason for hiding this comment

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

What will these attributes be called? If they exist on the final AST output by the compiler, then they will need to be public parts of the Core library API and would then need API review as well.

Approved/dyn-type.md Outdated Show resolved Hide resolved
Approved/dyn-type.md Outdated Show resolved Hide resolved
Approved/dyn-type.md Outdated Show resolved Hide resolved
@bamarsha
Copy link
Contributor

bamarsha commented Aug 23, 2022

Although dyn as a type was originally my idea, I think my opinion now is that dyn should not be a type, but rather an internal compiler property for values. We don't plan to expose dyn to users (and potentially it may never need to be exposed, given our inference rules), so I think it would be better to avoid cementing it in Q#'s type system.

For the compiler's static analysis, I think we only need:

  • A property on expressions that the compiler can track (there's already a mechanism for tracking "local quantum dependencies," which is like a weaker form of dyn - we can replace that with dyn).
  • Attributes on the callable indicating the capabilities required when each parameter is dyn.

So I'm not sure if this should be a QEP at all, since we didn't write a QEP for the earlier static analysis of hardware capabilities before, but left it as an internal compiler implementation detail.

@billti
Copy link
Member

billti commented Oct 5, 2022

Are we in agreement on this now? @spignorel do you need to update the proposal based on the latest from @SamarSha above?

@spignorel
Copy link
Author

Per @SamarSha there are questions as to which repo this should sit under. @billti stay tuned.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants