diff --git a/compiler/qsc_qasm3/src/angle.rs b/compiler/qsc_qasm3/src/angle.rs index 026084b640..cabcec9337 100644 --- a/compiler/qsc_qasm3/src/angle.rs +++ b/compiler/qsc_qasm3/src/angle.rs @@ -16,6 +16,7 @@ struct Angle { size: u32, } +#[allow(dead_code)] impl Angle { fn new(value: u64, size: u32) -> Self { Angle { value, size } diff --git a/compiler/qsc_qasm3/src/ast_builder.rs b/compiler/qsc_qasm3/src/ast_builder.rs index 2b270cb2b9..938b80e383 100644 --- a/compiler/qsc_qasm3/src/ast_builder.rs +++ b/compiler/qsc_qasm3/src/ast_builder.rs @@ -746,38 +746,6 @@ pub(crate) fn build_gate_call_with_params_and_callee( } } -pub(crate) fn build_gate_call_expr( - args: Vec, - name_span: Span, - gate_name: &str, - call_span: Span, - expr_span: Span, -) -> ast::Expr { - let param_expr = build_gate_call_param_expr(args, 0); - - let ident = ast::Ident { - id: NodeId::default(), - span: name_span, - name: Rc::from(gate_name), - }; - let callee_expr = ast::Expr { - id: NodeId::default(), - span: call_span, - kind: Box::new(ast::ExprKind::Path(Box::new(ast::Path { - id: NodeId::default(), - span: Span::default(), - segments: None, - name: Box::new(ident), - }))), - }; - let call_kind = ast::ExprKind::Call(Box::new(callee_expr), Box::new(param_expr)); - ast::Expr { - kind: Box::new(call_kind), - span: expr_span, - ..Default::default() - } -} - pub fn build_gate_call_param_expr(args: Vec, remaining: usize) -> Expr { if args.len() == 1 && remaining > 0 { return args[0].clone(); @@ -832,14 +800,6 @@ pub(crate) fn build_lit_double_expr(value: f64, span: Span) -> Expr { } } -pub(crate) fn build_lit_string_expr(value: f64, span: Span) -> Expr { - Expr { - id: NodeId::default(), - span, - kind: Box::new(ExprKind::Lit(Box::new(Lit::Double(value)))), - } -} - pub(crate) fn build_stmt_semi_from_expr(expr: Expr) -> Stmt { Stmt { id: NodeId::default(), @@ -848,15 +808,6 @@ pub(crate) fn build_stmt_semi_from_expr(expr: Expr) -> Stmt { } } -pub(crate) fn build_stmt_semi_from_block(block: Block) -> Stmt { - let expr = build_wrapped_block_expr(block); - Stmt { - id: NodeId::default(), - span: expr.span, - kind: Box::new(StmtKind::Semi(Box::new(expr))), - } -} - pub(crate) fn build_wrapped_block_expr(block: Block) -> Expr { Expr { id: NodeId::default(), @@ -864,6 +815,7 @@ pub(crate) fn build_wrapped_block_expr(block: Block) -> Expr { kind: Box::new(ast::ExprKind::Block(Box::new(block))), } } + pub(crate) fn build_stmt_wrapped_block_expr(stmt: Stmt) -> Block { Block { id: NodeId::default(), @@ -957,19 +909,6 @@ pub(crate) fn build_implicit_return_stmt(output_expr: Expr) -> Stmt { } } -pub(crate) fn build_explicit_return_stmt(output_expr: Expr) -> Stmt { - let span = output_expr.span; - Stmt { - kind: Box::new(StmtKind::Semi(Box::new(Expr { - kind: Box::new(ExprKind::Return(Box::new(output_expr))), - span, - ..Default::default() - }))), - span, - ..Default::default() - } -} - pub(crate) fn build_path_ident_ty>(name: S) -> Ty { let ident = ast::Ident { name: Rc::from(name.as_ref()), diff --git a/compiler/qsc_qasm3/src/compile.rs b/compiler/qsc_qasm3/src/compile.rs index 154f8cdef6..193c7bfdbf 100644 --- a/compiler/qsc_qasm3/src/compile.rs +++ b/compiler/qsc_qasm3/src/compile.rs @@ -1673,6 +1673,7 @@ impl QasmCompiler { } } + #[allow(dead_code)] fn compile_gphase_call_expr( &mut self, gphase_call_expr: &oq3_syntax::ast::GPhaseCallExpr, @@ -1904,28 +1905,6 @@ impl QasmCompiler { } } - fn compile_int_literal_to_complex( - &mut self, - value: &oq3_syntax::ast::IntNumber, - span: Span, - ) -> Option { - let value = value.value().expect("FloatNumber must have a value"); - if let Some(value) = safe_u128_to_f64(value) { - Some(build_lit_complex_expr( - crate::types::Complex::new(value, 0.0), - span, - )) - } else { - let kind = SemanticErrorKind::InvalidCastValueRange( - "Integer".to_string(), - "Complex real".to_string(), - span, - ); - self.push_semantic_error(kind); - None - } - } - fn compile_float_literal(value: &oq3_syntax::ast::FloatNumber, span: Span) -> ast::Expr { build_lit_double_expr(value.value().expect("FloatNumber must have a value"), span) } @@ -3983,15 +3962,6 @@ impl QasmCompiler { self.errors.push(error); } - /// Pushes an error for a pulse control not being supported. - pub fn push_pulse_control_error(&mut self, node: &SyntaxNode) { - let span = span_for_syntax_node(node); - let text = node.text().to_string(); - let kind = crate::ErrorKind::PulseControlNotSupported(text, span); - let error = self.create_err(kind); - self.errors.push(error); - } - /// Creates an error from the given kind with the current source mapping. fn create_err(&self, kind: crate::ErrorKind) -> WithSource { let error = crate::Error(kind); @@ -4087,18 +4057,6 @@ fn binop_requires_int_conversion_for_type(op: BinaryOp, ty_1: &Type, ty_2: &Type } } -fn binop_requires_int_magic(op: BinaryOp, ty_1: &Type, ty_2: &Type) -> bool { - match op { - BinaryOp::CmpOp(_) => match (ty_1, ty_2) { - (Type::BitArray(ArrayDims::D1(d1), _), Type::BitArray(ArrayDims::D1(d2), _)) => { - d1 == d2 - } - _ => false, - }, - _ => false, - } -} - fn binop_requires_bool_conversion_for_type(op: BinaryOp) -> bool { matches!(op, BinaryOp::LogicOp(..)) } diff --git a/compiler/qsc_qasm3/src/lib.rs b/compiler/qsc_qasm3/src/lib.rs index 5881acd061..dfeb89229d 100644 --- a/compiler/qsc_qasm3/src/lib.rs +++ b/compiler/qsc_qasm3/src/lib.rs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -#![allow(dead_code)] - mod angle; mod ast_builder; mod compile; @@ -57,8 +55,6 @@ impl Error { pub enum ErrorKind { #[error("this statement is not yet handled during OpenQASM 3 import: {0}")] Unimplemented(String, #[label] Span), - #[error("pulse control statements are not supported: {0}")] - PulseControlNotSupported(String, #[label] Span), #[error("calibration statements are not supported: {0}")] CalibrationsNotSupported(String, #[label] Span), #[error("{0} are not supported.")] @@ -78,9 +74,6 @@ impl ErrorKind { fn with_offset(self, offset: u32) -> Self { match self { ErrorKind::Unimplemented(error, span) => Self::Unimplemented(error, span + offset), - ErrorKind::PulseControlNotSupported(error, span) => { - Self::PulseControlNotSupported(error, span + offset) - } ErrorKind::CalibrationsNotSupported(error, span) => { Self::CalibrationsNotSupported(error, span + offset) } diff --git a/compiler/qsc_qasm3/src/symbols.rs b/compiler/qsc_qasm3/src/symbols.rs index 5d03ad4d2f..f3573f8c4c 100644 --- a/compiler/qsc_qasm3/src/symbols.rs +++ b/compiler/qsc_qasm3/src/symbols.rs @@ -112,8 +112,6 @@ impl Default for Symbol { #[derive(Debug, Clone, PartialEq, Eq)] pub enum SymbolError { - /// The symbol was not found in the symbol table. - NotFound, /// The symbol already exists in the symbol table, at the current scope. AlreadyExists, } @@ -182,10 +180,6 @@ impl Scope { .and_then(|id| self.id_to_symbol.get(id)) } - pub fn get_symbol_by_id(&self, id: SymbolId) -> Option<&Symbol> { - self.id_to_symbol.get(&id) - } - fn get_ordered_symbols(&self) -> Vec { self.order .iter() @@ -307,15 +301,6 @@ impl SymbolTable { None } - pub fn get_symbol_by_id(&self, id: SymbolId) -> Option<&Symbol> { - for scope in self.scopes.iter().rev() { - if let Some(symbol) = scope.get_symbol_by_id(id) { - return Some(symbol); - } - } - None - } - pub fn is_current_scope_global(&self) -> bool { matches!(self.scopes.last(), Some(scope) if scope.kind == ScopeKind::Global) } @@ -327,13 +312,6 @@ impl SymbolTable { .any(|scope| scope.kind == ScopeKind::Function) } - pub fn is_scope_rooted_in_gate(&self) -> bool { - self.scopes - .iter() - .rev() - .any(|scope| scope.kind == ScopeKind::Gate) - } - pub fn is_scope_rooted_in_global(&self) -> bool { for scope in self.scopes.iter().rev() { if scope.kind == ScopeKind::Function { diff --git a/compiler/qsc_qasm3/src/tests.rs b/compiler/qsc_qasm3/src/tests.rs index fbf05b17ea..8248902f8a 100644 --- a/compiler/qsc_qasm3/src/tests.rs +++ b/compiler/qsc_qasm3/src/tests.rs @@ -99,6 +99,7 @@ pub(crate) fn gen_qsharp_stmt(stmt: &Stmt) -> String { qsc::codegen::qsharp::write_stmt_string(stmt) } +#[allow(dead_code)] pub(crate) fn compare_compilation_to_qsharp(unit: &QasmCompileUnit, expected: &str) { let package = unit.package.as_ref().expect("package must exist"); let despanned_ast = AstDespanner.despan(package); @@ -280,6 +281,7 @@ fn get_first_statement_as_qsharp(package: &Package) -> String { pub struct AstDespanner; impl AstDespanner { + #[allow(dead_code)] // false positive lint pub fn despan(&mut self, package: &Package) -> Package { let mut p = package.clone(); self.visit_package(&mut p); @@ -294,8 +296,10 @@ impl MutVisitor for AstDespanner { } } +#[allow(dead_code)] struct HirDespanner; impl HirDespanner { + #[allow(dead_code)] fn despan(&mut self, package: &qsc::hir::Package) -> qsc::hir::Package { let mut p = package.clone(); qsc::hir::mut_visit::MutVisitor::visit_package(self, &mut p); diff --git a/compiler/qsc_qasm3/src/types.rs b/compiler/qsc_qasm3/src/types.rs index 1f25090902..02ad9b36ea 100644 --- a/compiler/qsc_qasm3/src/types.rs +++ b/compiler/qsc_qasm3/src/types.rs @@ -85,12 +85,6 @@ pub enum GateModifier { NegCtrl(Option, Span), } -impl QasmTypedExpr { - pub fn new(ty: oq3_semantics::types::Type, expr: qsc::ast::Expr) -> Self { - Self { ty, expr } - } -} - #[derive(Debug, Copy, Clone, PartialEq)] pub struct Complex { pub real: f64, @@ -103,6 +97,7 @@ impl Complex { } } +#[allow(dead_code)] #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) enum Type { Bool(bool), @@ -128,6 +123,7 @@ pub(crate) enum Type { #[derive(Debug, Clone, PartialEq, Eq)] pub enum CallableKind { /// A function. + #[allow(dead_code)] Function, /// An operation. Operation, @@ -214,51 +210,6 @@ impl Display for ArrayDimensions { } } -fn can_cast_type_in_assignment(lhs: &Type, rhs: &Type) -> bool { - if types_equal_ignore_const(lhs, rhs) { - return true; - } - matches!( - (lhs, rhs), - (Type::Double(_) | Type::Complex(_), Type::Int(_)) | (Type::Complex(_), Type::Double(_)) - ) -} - -fn types_equal_ignore_const(lhs: &Type, rhs: &Type) -> bool { - match (lhs, rhs) { - (Type::Bool(_), Type::Bool(_)) - | (Type::Int(_), Type::Int(_)) - | (Type::Double(_), Type::Double(_)) - | (Type::Complex(_), Type::Complex(_)) - | (Type::Result(_), Type::Result(_)) - | (Type::BigInt(_), Type::BigInt(_)) - | (Type::Qubit, Type::Qubit) => true, - (Type::Tuple(lhs), Type::Tuple(rhs)) => { - if lhs.len() != rhs.len() { - return false; - } - lhs.iter() - .zip(rhs.iter()) - .all(|(lhs, rhs)| types_equal_ignore_const(lhs, rhs)) - } - (Type::ResultArray(lhs_dims, _), Type::ResultArray(rhs_dims, _)) - | (Type::BigIntArray(lhs_dims, _), Type::BigIntArray(rhs_dims, _)) - | (Type::BoolArray(lhs_dims, _), Type::BoolArray(rhs_dims, _)) - | (Type::IntArray(lhs_dims, _), Type::IntArray(rhs_dims, _)) - | (Type::DoubleArray(lhs_dims), Type::DoubleArray(rhs_dims)) - | (Type::QubitArray(lhs_dims), Type::QubitArray(rhs_dims)) => lhs_dims == rhs_dims, - (Type::TupleArray(lhs_dims, lhs), Type::TupleArray(rhs_dims, rhs)) => { - lhs_dims == rhs_dims - && lhs.len() == rhs.len() - && lhs - .iter() - .zip(rhs.iter()) - .all(|(lhs, rhs)| types_equal_ignore_const(lhs, rhs)) - } - _ => false, - } -} - /// Get the indexed type of a given type. /// For example, if the type is `Int[2][3]`, the indexed type is `Int[2]`. /// If the type is `Int[2]`, the indexed type is `Int`.