-
Notifications
You must be signed in to change notification settings - Fork 16
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
V3 Extended: Functions #198
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Syntactic AST: an instruction can be a gate, an assignment instruction, or a measure instruction. Semantic AST: a regular instruction can be a gate or a measure instruction. BuildTreeGenAstVisitor.cpp: visitFunctionDeclaration, visitFunctionParameters, and visitStatementBlock are unimplemented.
- Syntactic AST Instruction has been renamed to Gate. - After modifying the parser rules, some of the parser error messages are different.
Add return statement to function blocks. Add function declaration integration tests.
- Remove VOID keyword. Changes to the v3 parser: - Add returnStatement. - A statement can be a blockStatement, a functionDeclaration, or a returnStatement. Changes to the syntactic AST: - Add type, block_statement, function, return_statement, and variable_list nodes. - A type has a name and a size. - A variable has a name and a type (before, a name, a type, and a size). - A block_statement can be a variable, an initialization, or an instruction. Change v3 Real type to Float.
- The syntactic AST has a Type node. - The syntactic AST Variable nodes have a name and a type (before, a name, a type, and a size). - The semantic AST uses Float for types and values, not Real anymore. Change res/v3x/parsing/function files: - Remove '-> void' return type. - bell function does not apply Hadamard on qubit 1.
- Remove conditions from statements. - Change assignment_instruction to assignment_statement. - Change function's return_type from One<type> to Maybe<type>. - A function has statements and a return_statement. Changes to the semantic AST: - Remove conditions from instructions. - A statement can be an instruction, an assignment_statement, or a return_statement. - An instruction continues to be whether a gate or a measure_instruction. - Add function node.
…nstructor. Enable {v1x,v3x}/Instruction classes to be used via fmt.
- Add global and local block. A local block cannot contain function declarations. - Add type, quantum type, and classical type. A variable definition is a type and an identifier. A variable declaration is a classical type, an identifier, and an expression. Changes to the v3x/syntactic AST: - A program has a version and a global block. - A function has a name, parameters, a return type, and a local block. Changes to the v3x/semantic AST: - A program has a version, a block, a list of functions, and a list of variables. - A function has a name, a return type, a block, and a list of variables. Changes to the v3x/values: - Add function value. Changes to the v3x/Analyzer: - Add a stack of scopes. - Add methods to access the global scope, and the current scope. - Add methods to access the current block, the current list of variables, and the global list of functions. - Add methods to push and pop scopes. - Add methods to add statements, variables and functions to the current and global scopes. Changes to BuildTreeGenAstVisitor: - Add expandNodeAnnotation method. This is used for array types. Changes to AnalyzeTreeGenAstVisitor: - Add visit_function method. - Add build_semantic_type, to build a semantic type from a syntactic type. - Visitor methods do not update result_.root directly, but via the add_{statement,variable,function} methods. Changes to the v3x/resolver: - Add ResolutionFailure exception. - Change mapping name to variable. TODO: register_function is unimplemented. TODO: update res/v3x/parsing files, to follow the syntactic and semantic AST changes.
TODO: not sure if we will be able to unify these two tables (types of functions) in the future. Changes to the values tree-gen file: - Add a function_ref and a function_call value. Functions are registered as function_ref, pointing to a semantic AST Function. A function call value will contain information about the function (in the form of a value), and its arguments. - Add a ValueBase base class. This is needed for referencing a generic value from the arguments of a function. Changes to the semantic AST: - Refer to values::ValueBase and types::TypeBase instead of values::Node and types::Node. Changes to the values file: - Value is now a One<ValueBase>, not a One<Node> anymore. - Values is now an Any<ValueBase>, not an Any<Node> anymore. Changes to AnalyzeTreeGenAstVisitor: - visit_function registers a function using the name, the type of the parameters and a FunctionRef value. - Rename analyze_as to visit_as. Changes to the v3x/Analyzer: - We now have function implementations and functions. Function implementations are functions for which we have a C++ implementation. Functions are those defined in the cQASM file. - Rename call_function to resolve_function. Changes to the v3x/resolver: - We now have function implementations and functions. Changes to v3x/functions: - Register functions as function implementations.
- There can be zero or more statement separators after a local block. Changes to the syntactic AST: - A return statement is a block statement. - The parameters of a function are a local block. - Remove variable_list. Changes to BuildTreeGenAstVisitor: - A local block statement can be a variable declaration, an instruction, an assignment statement or a return statement. Changes to AnalyzeTreeGenAstVisitor: - Push and pop scopes manually when needed, not automatically at visit_local_block. - For example, when analyzing a function, push a scope, analyze the parameters, analyze the block, and pop the scope.
- Remove extra code from types_of. - Fix visit_assignment_statement. - Fix visit_function. - Fix visit_return_statement. Changes to the v3x/Analyzer: - Add some more const functions. Changes to the v3x/values file: - Update functions considering function_ref and function_call values.
Because of these changes to the syntactic AST: - Add annotations for Type nodes. - Add assignment statement. - Change statements/StatementList/items to block/GlobalBlock/statements. - Remove condition from nodes. And these changes to the semantic AST: - Add functions. - Change mapping to variable. - Change AssignmentInstruction to AssignmentStatement. - Remove condition from nodes.
- Add expressionStatement. In order to enable function calls as statements. Changes to the syntactic AST: - Change the type of the arguments of a function call expression to Maybe<expression_list>. Changes to the semantic AST: - Add expression statement. - A function call statement only holds a return value, if any. Changes to BuildTreeGenAstVisitor: - Add visitExpressionStatement. Expression statements use their expression's annotations. Changes to AnalyzeTreeGenAstVisitor: - Add visit_expression_statement. The analyzer checks that an expression statement can only be a function call. - A function call expression may not have arguments. Fix a couple of bugs in src/cqasm-annotations.cpp and src/v1x/cqasm-analyzer-helper.cpp. That I had previously introduced in this branch.
…xtended-functions # Conflicts: # test/v3x/python/test_parse_result.py
…xtended-functions
Update res/v1x/parsing files.
This file belongs to a folder that is unused at the moment. However, the change is legit.
Changes to the v3x/analyzer: - Make privat members protected, so that they can be used in testing. - Update instruction resolution exception error message. - Rename register_default_functions_into to register_default_function_impls_into. Update res/v3x/parsing files.
Changes to v3x::primitives::Axis: - Set default value to axis x. Changes to v3x::values, promote function: - Change asserts for checks. So that, if they fail, promote just returns an empty value.
pablolh
reviewed
Mar 1, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Roberto
First of all sorry for the delay.
It's quite difficult to review since I don't know what is new and what is moved around.
However, I didn't see any problem
I'm ready to approve if you deem those few comments irrelevant, please let me know then
…xtended-functions # Conflicts: # include/cqasm-annotations.hpp
pablolh
approved these changes
Mar 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add user-defined functions to the grammar.
Functions are defined as
def <name>(<parameters>) -> <return type> { <statements> }
.The return type is optional.
There is a
return
statement.Functions are called as
<name>(<arguments>)
.Arguments need to be promotable to the types of the parameters.
Function calls are both expressions and statements.
Changest to the grammar
Changes to the AST
Changes to the
v3x/analyzer
Changes to
v3x/resolver
Changes to
v3x/types
Changes to
v3x/values
Changes to
v1x
files