From 79e0a5afb7799b63c0e94ae4e07783c6d12ca44a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 20:35:04 +0000 Subject: [PATCH 1/2] Initial plan From 76ded067419356bc6f7af9af771e3a5cbdb69ff3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 20:46:43 +0000 Subject: [PATCH 2/2] Remove bool const flag from qsc_openqasm_compiler Type enum Co-authored-by: minestarks <16928427+minestarks@users.noreply.github.com> --- .../qsc_openqasm_compiler/src/ast_builder.rs | 26 +++---- .../qsc_openqasm_compiler/src/compiler.rs | 42 +++++------ .../qsc_openqasm_compiler/src/types.rs | 74 +++++++------------ 3 files changed, 59 insertions(+), 83 deletions(-) diff --git a/source/compiler/qsc_openqasm_compiler/src/ast_builder.rs b/source/compiler/qsc_openqasm_compiler/src/ast_builder.rs index 9e0cb1e70b..d26dc633e2 100644 --- a/source/compiler/qsc_openqasm_compiler/src/ast_builder.rs +++ b/source/compiler/qsc_openqasm_compiler/src/ast_builder.rs @@ -1182,25 +1182,25 @@ pub(crate) fn build_unary_op_expr(op: ast::UnOp, expr: ast::Expr, prefix_span: S pub(crate) fn map_qsharp_type_to_ast_ty(output_ty: &crate::types::Type, span: Span) -> Ty { let mut ty = match output_ty { - crate::types::Type::Angle(_) => build_angle_ty_ident(), - crate::types::Type::Result(_) => build_path_ident_ty("Result"), + crate::types::Type::Angle => build_angle_ty_ident(), + crate::types::Type::Result => build_path_ident_ty("Result"), crate::types::Type::Qubit => build_path_ident_ty("Qubit"), - crate::types::Type::BigInt(_) => build_path_ident_ty("BigInt"), - crate::types::Type::Int(_) => build_path_ident_ty("Int"), - crate::types::Type::Double(_) => build_path_ident_ty("Double"), - crate::types::Type::Complex(_) => build_complex_ty_ident(), - crate::types::Type::Bool(_) => build_path_ident_ty("Bool"), - crate::types::Type::ResultArray(dims, _) => build_array_type_name("Result", *dims), + crate::types::Type::BigInt => build_path_ident_ty("BigInt"), + crate::types::Type::Int => build_path_ident_ty("Int"), + crate::types::Type::Double => build_path_ident_ty("Double"), + crate::types::Type::Complex => build_complex_ty_ident(), + crate::types::Type::Bool => build_path_ident_ty("Bool"), + crate::types::Type::ResultArray(dims) => build_array_type_name("Result", *dims), crate::types::Type::QubitArray(dims) => build_array_type_name("Qubit", *dims), - crate::types::Type::BigIntArray(dims, _) => build_array_type_name("BigInt", *dims), - crate::types::Type::IntArray(dims, _) => build_array_type_name("Int", *dims), + crate::types::Type::BigIntArray(dims) => build_array_type_name("BigInt", *dims), + crate::types::Type::IntArray(dims) => build_array_type_name("Int", *dims), crate::types::Type::DoubleArray(dims) => build_array_type_name("Double", *dims), - crate::types::Type::BoolArray(dims, _) => build_array_type_name("Bool", *dims), - crate::types::Type::ComplexArray(dims, _) => { + crate::types::Type::BoolArray(dims) => build_array_type_name("Bool", *dims), + crate::types::Type::ComplexArray(dims) => { let ty = build_complex_ty_ident(); wrap_array_ty_by_dims(*dims, ty) } - crate::types::Type::AngleArray(dims, _) => { + crate::types::Type::AngleArray(dims) => { let ty = build_angle_ty_ident(); wrap_array_ty_by_dims(*dims, ty) } diff --git a/source/compiler/qsc_openqasm_compiler/src/compiler.rs b/source/compiler/qsc_openqasm_compiler/src/compiler.rs index dbd7d5138e..2b0e571a50 100644 --- a/source/compiler/qsc_openqasm_compiler/src/compiler.rs +++ b/source/compiler/qsc_openqasm_compiler/src/compiler.rs @@ -329,7 +329,7 @@ impl QasmCompiler { if let Some(inputs) = &input { for input in inputs { let qsharp_ty = self.map_semantic_type_to_qsharp_type(&input.ty, input.ty_span); - if matches!(qsharp_ty, crate::types::Type::Angle(..)) { + if matches!(qsharp_ty, crate::types::Type::Angle) { let message = "use `float` types for passing input, using `angle` types".to_string(); let kind = CompilerErrorKind::NotSupported(message, input.span); @@ -504,8 +504,8 @@ impl QasmCompiler { .map(|symbol| { let qsharp_ty = self.map_semantic_type_to_qsharp_type(&symbol.ty, symbol.ty_span); - if matches!(qsharp_ty, crate::types::Type::Angle(..)) { - crate::types::Type::Double(symbol.ty.is_const()) + if matches!(qsharp_ty, crate::types::Type::Angle) { + crate::types::Type::Double } else { qsharp_ty } @@ -751,7 +751,7 @@ impl QasmCompiler { rhs_span, rhs_span, rhs_span, - &crate::types::Type::ResultArray(crate::types::ArrayDimensions::One, false), + &crate::types::Type::ResultArray(crate::types::ArrayDimensions::One), temp_var_stmt_init_expr, ); let temp_var_expr = build_path_ident_expr("bitarray", rhs_span, rhs_span); @@ -2516,9 +2516,8 @@ impl QasmCompiler { return crate::types::Type::Err; } - let is_const = ty.is_const(); match ty { - Type::Bit(_) => crate::types::Type::Result(is_const), + Type::Bit(_) => crate::types::Type::Result, Type::Qubit => crate::types::Type::Qubit, Type::HardwareQubit => { errs.push(unsupported_err("hardware qubits", span)); @@ -2530,18 +2529,18 @@ impl QasmCompiler { Type::Int(width, _) | Type::UInt(width, _) => { if let Some(width) = width { if *width > 64 { - crate::types::Type::BigInt(is_const) + crate::types::Type::BigInt } else { - crate::types::Type::Int(is_const) + crate::types::Type::Int } } else { - crate::types::Type::Int(is_const) + crate::types::Type::Int } } - Type::Float(_, _) => crate::types::Type::Double(is_const), - Type::Angle(_, _) => crate::types::Type::Angle(is_const), - Type::Complex(_, _) => crate::types::Type::Complex(is_const), - Type::Bool(_) => crate::types::Type::Bool(is_const), + Type::Float(_, _) => crate::types::Type::Double, + Type::Angle(_, _) => crate::types::Type::Angle, + Type::Complex(_, _) => crate::types::Type::Complex, + Type::Bool(_) => crate::types::Type::Bool, Type::Duration(_) => { errs.push(unsupported_err("duration type values", span)); crate::types::Type::Err @@ -2551,7 +2550,7 @@ impl QasmCompiler { crate::types::Type::Err } Type::BitArray(_, _) => { - crate::types::Type::ResultArray(crate::types::ArrayDimensions::One, is_const) + crate::types::Type::ResultArray(crate::types::ArrayDimensions::One) } Type::Array(array) if !matches!( @@ -2619,13 +2618,13 @@ impl QasmCompiler { match base_ty { qsc_openqasm_parser::semantic::types::ArrayBaseType::Duration => unreachable!(), qsc_openqasm_parser::semantic::types::ArrayBaseType::Bool => { - crate::types::Type::BoolArray(dims, false) + crate::types::Type::BoolArray(dims) } qsc_openqasm_parser::semantic::types::ArrayBaseType::Angle(_) => { - crate::types::Type::AngleArray(dims, false) + crate::types::Type::AngleArray(dims) } qsc_openqasm_parser::semantic::types::ArrayBaseType::Complex(_) => { - crate::types::Type::ComplexArray(dims, false) + crate::types::Type::ComplexArray(dims) } qsc_openqasm_parser::semantic::types::ArrayBaseType::Float(_) => { crate::types::Type::DoubleArray(dims) @@ -2634,19 +2633,18 @@ impl QasmCompiler { | qsc_openqasm_parser::semantic::types::ArrayBaseType::UInt(width) => { if let Some(width) = width { if *width > 64 { - crate::types::Type::BigIntArray(dims, false) + crate::types::Type::BigIntArray(dims) } else { - crate::types::Type::IntArray(dims, false) + crate::types::Type::IntArray(dims) } } else { - crate::types::Type::IntArray(dims, false) + crate::types::Type::IntArray(dims) } } } } /// Returns `true` if both `OpenQASM` types map to the same Q# type without errors. - /// Ignores const qualifiers, since constness does not affect the Q# representation. fn maps_to_same_qsharp_type( a: &qsc_openqasm_parser::semantic::types::Type, b: &qsc_openqasm_parser::semantic::types::Type, @@ -2654,7 +2652,7 @@ impl QasmCompiler { let mut errs = Vec::new(); let ty_a = Self::semantic_type_for_qsharp_type(a, Span::default(), &mut errs); let ty_b = Self::semantic_type_for_qsharp_type(b, Span::default(), &mut errs); - errs.is_empty() && ty_a.without_const() == ty_b.without_const() + errs.is_empty() && ty_a == ty_b } fn get_argument_validation_stmts( diff --git a/source/compiler/qsc_openqasm_compiler/src/types.rs b/source/compiler/qsc_openqasm_compiler/src/types.rs index 10bea73214..7411a75d9f 100644 --- a/source/compiler/qsc_openqasm_compiler/src/types.rs +++ b/source/compiler/qsc_openqasm_compiler/src/types.rs @@ -20,24 +20,24 @@ impl Complex { #[derive(Debug, Clone, Default, PartialEq, Eq)] pub enum Type { - Angle(bool), - Bool(bool), - BigInt(bool), - Complex(bool), - Int(bool), - Double(bool), + Angle, + Bool, + BigInt, + Complex, + Int, + Double, Qubit, - Result(bool), + Result, Tuple(Vec), Range, - BoolArray(ArrayDimensions, bool), - BigIntArray(ArrayDimensions, bool), - IntArray(ArrayDimensions, bool), + BoolArray(ArrayDimensions), + BigIntArray(ArrayDimensions), + IntArray(ArrayDimensions), DoubleArray(ArrayDimensions), - ComplexArray(ArrayDimensions, bool), - AngleArray(ArrayDimensions, bool), + ComplexArray(ArrayDimensions), + AngleArray(ArrayDimensions), QubitArray(ArrayDimensions), - ResultArray(ArrayDimensions, bool), + ResultArray(ArrayDimensions), /// # cargs, # qargs Gate(u32, u32), /// kind, args, return ty @@ -46,28 +46,6 @@ pub enum Type { Err, } -impl Type { - /// Returns the same type with the const qualifier set to `false`. - pub fn without_const(self) -> Self { - match self { - Self::Angle(_) => Self::Angle(false), - Self::Bool(_) => Self::Bool(false), - Self::BigInt(_) => Self::BigInt(false), - Self::Complex(_) => Self::Complex(false), - Self::Int(_) => Self::Int(false), - Self::Double(_) => Self::Double(false), - Self::Result(_) => Self::Result(false), - Self::BoolArray(d, _) => Self::BoolArray(d, false), - Self::BigIntArray(d, _) => Self::BigIntArray(d, false), - Self::IntArray(d, _) => Self::IntArray(d, false), - Self::ComplexArray(d, _) => Self::ComplexArray(d, false), - Self::AngleArray(d, _) => Self::AngleArray(d, false), - Self::ResultArray(d, _) => Self::ResultArray(d, false), - other => other, - } - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub enum CallableKind { /// A function. @@ -155,15 +133,15 @@ impl From for ArrayDimensions { impl Display for Type { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - Type::Angle(_) => write!(f, "Angle"), - Type::Bool(_) => write!(f, "bool"), - Type::BigInt(_) => write!(f, "BigInt"), - Type::Complex(_) => write!(f, "Complex"), - Type::Int(_) => write!(f, "Int"), - Type::Double(_) => write!(f, "Double"), + Type::Angle => write!(f, "Angle"), + Type::Bool => write!(f, "bool"), + Type::BigInt => write!(f, "BigInt"), + Type::Complex => write!(f, "Complex"), + Type::Int => write!(f, "Int"), + Type::Double => write!(f, "Double"), Type::Qubit => write!(f, "Qubit"), Type::Range => write!(f, "Range"), - Type::Result(_) => write!(f, "Result"), + Type::Result => write!(f, "Result"), Type::Tuple(types) => { write!(f, "(")?; for (i, ty) in types.iter().enumerate() { @@ -174,14 +152,14 @@ impl Display for Type { } write!(f, ")") } - Type::BoolArray(dim, _) => write!(f, "bool{dim}"), - Type::BigIntArray(dim, _) => write!(f, "BigInt{dim}"), - Type::IntArray(dim, _) => write!(f, "Int{dim}"), + Type::BoolArray(dim) => write!(f, "bool{dim}"), + Type::BigIntArray(dim) => write!(f, "BigInt{dim}"), + Type::IntArray(dim) => write!(f, "Int{dim}"), Type::DoubleArray(dim) => write!(f, "Double{dim}"), - Type::ComplexArray(dim, _) => write!(f, "Complex{dim}"), - Type::AngleArray(dim, _) => write!(f, "Angle{dim}"), + Type::ComplexArray(dim) => write!(f, "Complex{dim}"), + Type::AngleArray(dim) => write!(f, "Angle{dim}"), Type::QubitArray(dim) => write!(f, "Qubit{dim}"), - Type::ResultArray(dim, _) => write!(f, "Result{dim}"), + Type::ResultArray(dim) => write!(f, "Result{dim}"), Type::Callable(kind, args, return_type) => { write!(f, "Callable({kind}, {args:?}, {return_type})") }