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

Reimplement Parser #2149

Draft
wants to merge 69 commits into
base: main
Choose a base branch
from
Draft

Reimplement Parser #2149

wants to merge 69 commits into from

Conversation

idavis
Copy link
Collaborator

@idavis idavis commented Feb 4, 2025

Lexing

  • Basic raw tokens
  • Basic cooked tokens
  • Cook pragma and annotation

Parsing

Lowering

Compiling

Fit and Finish

  • Move Q# related semantic errors from Lowerer to Compiler
  • Review compiler error messages
  • Review parser error messages
  • Review lexer error messages
  • Benchmark parser
  • Review language spec for any inconsistencies with implementation

@idavis idavis requested a review from orpuente-MS February 4, 2025 02:11
@idavis idavis self-assigned this Feb 4, 2025
Index,
}

// TODO: This seems to be an unnecessary wrapper.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
Keyword(Keyword),
}

// TODO: This seems to be an unnecessary wrapper.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
rc::Rc,
};

// TODO: Profile this with iai-callgrind in a large OpenQASM3

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment

let expr = if matches!(ty, Type::Complex(..)) {
if is_complex_binop_supported(op) {
// TODO: How do we handle complex binary expressions?

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
@idavis idavis force-pushed the feature/qasm3 branch 2 times, most recently from eb82b24 to b803573 Compare March 18, 2025 21:48

let ast_ty = map_qsharp_type_to_ast_ty(&output_ty);
signature.output = format!("{output_ty}");
// TODO: This can create a collision on multiple compiles when interactive

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment

// input decls should have been pushed to symbol table,
// but should not be the stmts list.
// TODO: This may be an issue for tooling as there isn't a way to have a forward

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
)
}

// TODO: which these are parsed as different types, they are effectively the same

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
}
Type::Float(..) | Type::Angle(..) => {
rewrap_lit!((lhs, rhs), (Float(lhs), Float(rhs)), {
// TODO: we need to issue the same lint in Q#.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
}
Type::Float(..) | Type::Angle(..) => {
rewrap_lit!((lhs, rhs), (Float(lhs), Float(rhs)), {
// TODO: we need to issue the same lint in Q#.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
Type::BitArray(..) => {
rewrap_lit!(lit, Bitstring(val, _), Int(i64::try_from(val).ok()?))
}
// TODO: UInt Overflowing behavior.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
// already is a i64. Therefore, there is nothing to do?
Type::Int(..) | Type::UInt(..) => Some(lit),
Type::Float(..) => rewrap_lit!(lit, Float(val), {
// TODO: we need to issue the same lint in Q#.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
Type::BitArray(..) => {
rewrap_lit!(lit, Bitstring(val, _), Int(i64::try_from(val).ok()?))
}
// TODO: Int Overflowing behavior.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
// same result anyways. Need to think through this.
Type::Int(..) | Type::UInt(..) => Some(lit),
Type::Float(..) => rewrap_lit!(lit, Float(val), {
// TODO: we need to issue the same lint in Q#.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
match ty {
Type::Bool(..) => rewrap_lit!(lit, Bool(val), Float(if val { 1.0 } else { 0.0 })),
Type::Int(..) | Type::UInt(..) => rewrap_lit!(lit, Int(val), {
// TODO: we need to issue the same lint in Q#.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
orpuente-MS and others added 27 commits March 27, 2025 09:28
This PR doesn't change any behavior. It just touches the Display
functions in the QASM3 parser to make unit tests easier to read.
Previously assignments and binary assignments were valid in any part of
the expression tree. This PR makes Assign and AssignOp valid only in
expression statements.
This PR turns assignment into a StmtKind (it was a ExprKind before).
This PR:
 1. Fixes a bug with block statements
 2. Adds grammar docstrings to the QASM3 parser.
3. Adds the invalid tests in the reference parser to make sure they are
invalid for our parser as well.
…es. (#2226)

If/else blocks, while, and for loops in QASM introduce new scopes only
when their body enclosed by curly braces. To make lowering easier, this
PR changes their bodies from `List<Stmt>` to `Stmt`. In the body
enclosed in curly braces case, the Stmt will be of kind Block.
- Adding span offsetter for parsed files
- Clean up error spans
- Move box validation
- Add a mutable visitor for AST nodes.
This PR:
 1. Aliases super::ast to semantic.
2. Fixes The bodies of if, for, and while to be `Stmt` instead of
`List<Stmt>`.
 3. Lowers the if, for, while, and switch stmts.
4. Refactors the pattern used to handle lowering of optional items by
introducing the `short_circuit_opt_item!` macro.
…ler (#2246)

This PR adds gate calls and the AST items it depends on to the new QASM3
compiler:
 - [x] Constant evaluation (needed for array sizes and type widths).
   - [x] Unit tests.
 - [x] QuantumDeclStmt
 - [x] IndexedAssignStmt.
 - [x] Bitarrays.
 - [x] MeasureExpr / MeasureStmt.
- [x] Compilation to Result type (introduces `LiteralKind::Bit(bool)`)
variant.
 - [x] GatecallStmt
 - [x] barrier
 - [x] reset
This PR completes the lowering and compilation for:
 - [x] gate definitions
 - [x] gphase
 - [x] for stmt
 - [x] if stmt
 - [x] switch stmt
 - [x] return stmt
 - [x] classical function calls
 - [x] classical function decls

It also does some partial work to make the compiler infallible, by
returning `ExprKind::Err` instead of None when compiling expressions.
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.

2 participants