Skip to content

Allow custom ExternArgument in extern declaration #83

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

Merged
merged 6 commits into from
Nov 30, 2023

Conversation

anuragm
Copy link
Contributor

@anuragm anuragm commented Nov 29, 2023

This is useful if we want to specify ArrayReferenceType as an argument to an extern function. ArrayReferenceType require an explicit Access modifier (mutable or readonly). Since this is just one edge case, we can let users still specify just the type for all other extern declarations.

I have added a test that demos its usage.

This is useful if people want to specify ArrayReferenceType as an argument to an
extern function. ArrayReferenceType require an explicit Access
modifier (mutable or readonly). Since this is just one edge case, we can let
users still specify just the type for all other extern declarations.
Copy link
Collaborator

@jcjaskula-aws jcjaskula-aws left a comment

Choose a reason for hiding this comment

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

Great implementation, I have minor comments that should be easy to resolve.


SubroutineParams = [oqpy.Program, VarArg(AstConvertible)]

FnType = TypeVar("FnType", bound=Callable[..., Any])


@dataclass
class OqpyArgument:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we keep the style that we use for other classes? -> OQPyArgument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


name: str
dtype: ast.ClassicalType
access: Literal["readonly", "mutable"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add None and make it the default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jcjaskula-aws jcjaskula-aws merged commit d16f4af into openqasm:main Nov 30, 2023

name: str
dtype: ast.ClassicalType
access: Literal["readonly", "mutable"] | None = None
Copy link
Contributor

Choose a reason for hiding this comment

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

This follows the precedent established by the OpenQASM reference AST, so it's fine to have here. But I will say that I think the underlying premise is slightly mistaken. Access modifiers or type qualifiers make most sense as part of the type itself. In a subroutine, if you ask "what is the type of this variable" it's nice to be able to say "a mutable array reference".

Copy link
Collaborator

Choose a reason for hiding this comment

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

I might agree. After reading the reference AST code and the parser grammar, I think we should cut a ticket to gh/openqasm and fix it there first. ArrayReferenceType is only used with *Argument node but the modifier has been added to the *Argument node and not the type node.

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

Successfully merging this pull request may close these issues.

3 participants