From 74a393013c77177f6613347e227d28ee2f3f8d22 Mon Sep 17 00:00:00 2001 From: Mine Starks <16928427+minestarks@users.noreply.github.com> Date: Fri, 4 Oct 2024 20:49:46 +0000 Subject: [PATCH] rename to PathKind --- compiler/qsc/src/interpret/tests.rs | 4 +-- compiler/qsc_ast/src/ast.rs | 28 ++++++++-------- compiler/qsc_ast/src/mut_visit.rs | 24 +++++++------- compiler/qsc_ast/src/visit.rs | 24 +++++++------- compiler/qsc_codegen/src/qsharp.rs | 20 ++++++------ compiler/qsc_doc_gen/src/display.rs | 10 +++--- .../qsc_frontend/src/compile/preprocess.rs | 6 ++-- .../src/compile/preprocess/tests.rs | 4 +-- compiler/qsc_frontend/src/lower.rs | 19 ++++++----- compiler/qsc_frontend/src/resolve.rs | 28 ++++++++-------- compiler/qsc_frontend/src/resolve/tests.rs | 6 ++-- compiler/qsc_frontend/src/typeck/convert.rs | 6 ++-- compiler/qsc_frontend/src/typeck/rules.rs | 17 +++++----- compiler/qsc_linter/src/linter/ast.rs | 14 ++++---- compiler/qsc_parse/src/expr.rs | 6 ++-- compiler/qsc_parse/src/item.rs | 12 +++---- compiler/qsc_parse/src/prim.rs | 10 +++--- compiler/qsc_parse/src/prim/tests.rs | 4 +-- compiler/qsc_qasm3/src/ast_builder.rs | 32 +++++++++---------- .../src/completion/global_items.rs | 6 ++-- .../src/completion/path_context.rs | 24 +++++++------- language_service/src/name_locator.rs | 4 +-- language_service/src/references.rs | 6 ++-- language_service/src/signature_help.rs | 4 +-- language_service/src/tests.rs | 2 +- 25 files changed, 159 insertions(+), 161 deletions(-) diff --git a/compiler/qsc/src/interpret/tests.rs b/compiler/qsc/src/interpret/tests.rs index 8a9572285e..688a54dc05 100644 --- a/compiler/qsc/src/interpret/tests.rs +++ b/compiler/qsc/src/interpret/tests.rs @@ -1347,7 +1347,7 @@ mod given_interpreter { use indoc::indoc; use qsc_ast::ast::{ - Expr, ExprKind, NodeId, Package, Path, PathResult, Stmt, StmtKind, TopLevelNode, + Expr, ExprKind, NodeId, Package, Path, PathKind, Stmt, StmtKind, TopLevelNode, }; use qsc_data_structures::span::Span; use qsc_frontend::compile::SourceMap; @@ -1867,7 +1867,7 @@ mod given_interpreter { let path_expr = Expr { id: NodeId::default(), span: Span::default(), - kind: Box::new(ExprKind::Path(PathResult::Ok(Box::new(path)))), + kind: Box::new(ExprKind::Path(PathKind::Ok(Box::new(path)))), }; let expr = Expr { id: NodeId::default(), diff --git a/compiler/qsc_ast/src/ast.rs b/compiler/qsc_ast/src/ast.rs index 6da927fc83..737429810b 100644 --- a/compiler/qsc_ast/src/ast.rs +++ b/compiler/qsc_ast/src/ast.rs @@ -273,7 +273,7 @@ pub enum ItemKind { #[default] Err, /// An `open` item for a namespace with an optional alias. - Open(PathResult, Option>), + Open(PathKind, Option>), /// A `newtype` declaration. Ty(Box, Box), /// A `struct` declaration. @@ -672,7 +672,7 @@ pub enum TyKind { /// A type wrapped in parentheses. Paren(Box), /// A named type. - Path(PathResult), + Path(PathKind), /// A type parameter. Param(Box), /// A tuple type. @@ -884,7 +884,7 @@ pub enum ExprKind { /// Parentheses: `(a)`. Paren(Box), /// A path: `a` or `a.b`. - Path(PathResult), + Path(PathKind), /// A range: `start..step..end`, `start..end`, `start...`, `...end`, or `...`. Range(Option>, Option>, Option>), /// A repeat-until loop with an optional fixup: `repeat { ... } until a fixup { ... }`. @@ -892,7 +892,7 @@ pub enum ExprKind { /// A return: `return a`. Return(Box), /// A struct constructor. - Struct(PathResult, Option>, Box<[Box]>), + Struct(PathKind, Option>, Box<[Box]>), /// A ternary operator. TernOp(TernOp, Box, Box, Box), /// A tuple: `(a, b, c)`. @@ -1147,7 +1147,7 @@ fn display_repeat( fn display_struct( mut indent: Indented, - name: &PathResult, + name: &PathKind, copy: &Option>, fields: &[Box], ) -> fmt::Result { @@ -1404,7 +1404,7 @@ impl Display for QubitInitKind { /// A path that may or may not have been successfully parsed. #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub enum PathResult { +pub enum PathKind { /// A successfully parsed path. Ok(Box), @@ -1412,9 +1412,9 @@ pub enum PathResult { Err(Option>), } -impl Default for PathResult { +impl Default for PathKind { fn default() -> Self { - PathResult::Err(None) + PathKind::Err(None) } } @@ -1429,11 +1429,11 @@ pub struct IncompletePath { pub segments: Box<[Ident]>, } -impl Display for PathResult { +impl Display for PathKind { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - PathResult::Ok(path) => write!(f, "{path}")?, - PathResult::Err(Some(incomplete_path)) => { + PathKind::Ok(path) => write!(f, "{path}")?, + PathKind::Err(Some(incomplete_path)) => { let mut indent = set_indentation(indented(f), 0); write!(indent, "Err IncompletePath {}:", incomplete_path.span)?; indent = set_indentation(indent, 1); @@ -1441,7 +1441,7 @@ impl Display for PathResult { write!(indent, "\n{part}")?; } } - PathResult::Err(None) => write!(f, "Err",)?, + PathKind::Err(None) => write!(f, "Err",)?, } Ok(()) } @@ -1905,7 +1905,7 @@ pub struct ImportOrExportItem { /// The span of the import path including the glob and alias, if any. pub span: Span, /// The path to the item being exported. - pub path: PathResult, + pub path: PathKind, /// An optional alias for the item being exported. pub alias: Option, /// Whether this is a glob import/export. @@ -1942,7 +1942,7 @@ impl ImportOrExportItem { match &self.alias { Some(_) => self.alias.as_ref(), None => { - if let PathResult::Ok(path) = &self.path { + if let PathKind::Ok(path) = &self.path { Some(&path.name) } else { None diff --git a/compiler/qsc_ast/src/mut_visit.rs b/compiler/qsc_ast/src/mut_visit.rs index 1e2fc315e4..15664a6a95 100644 --- a/compiler/qsc_ast/src/mut_visit.rs +++ b/compiler/qsc_ast/src/mut_visit.rs @@ -3,7 +3,7 @@ use crate::ast::{ Attr, Block, CallableBody, CallableDecl, Expr, ExprKind, FieldAssign, FieldDef, FunctorExpr, - FunctorExprKind, Ident, Item, ItemKind, Namespace, Package, Pat, PatKind, Path, PathResult, + FunctorExprKind, Ident, Item, ItemKind, Namespace, Package, Pat, PatKind, Path, PathKind, QubitInit, QubitInitKind, SpecBody, SpecDecl, Stmt, StmtKind, StringComponent, StructDecl, TopLevelNode, Ty, TyDef, TyDefKind, TyKind, }; @@ -82,8 +82,8 @@ pub trait MutVisitor: Sized { walk_path(self, path); } - fn visit_path_result(&mut self, path: &mut PathResult) { - walk_path_result(self, path); + fn visit_path_kind(&mut self, path: &mut PathKind) { + walk_path_kind(self, path); } fn visit_ident(&mut self, ident: &mut Ident) { @@ -120,7 +120,7 @@ pub fn walk_item(vis: &mut impl MutVisitor, item: &mut Item) { ItemKind::Callable(decl) => vis.visit_callable_decl(decl), ItemKind::Err => {} ItemKind::Open(ns, alias) => { - vis.visit_path_result(ns); + vis.visit_path_kind(ns); alias.iter_mut().for_each(|a| vis.visit_ident(a)); } ItemKind::Ty(ident, def) => { @@ -132,7 +132,7 @@ pub fn walk_item(vis: &mut impl MutVisitor, item: &mut Item) { vis.visit_span(&mut export.span); for item in &mut *export.items { vis.visit_span(&mut item.span); - vis.visit_path_result(&mut item.path); + vis.visit_path_kind(&mut item.path); if let Some(ref mut alias) = item.alias { vis.visit_ident(alias); } @@ -227,7 +227,7 @@ pub fn walk_ty(vis: &mut impl MutVisitor, ty: &mut Ty) { TyKind::Hole | TyKind::Err => {} TyKind::Paren(ty) => vis.visit_ty(ty), TyKind::Param(name) => vis.visit_ident(name), - TyKind::Path(path) => vis.visit_path_result(path), + TyKind::Path(path) => vis.visit_path_kind(path), TyKind::Tuple(tys) => tys.iter_mut().for_each(|t| vis.visit_ty(t)), } } @@ -319,7 +319,7 @@ pub fn walk_expr(vis: &mut impl MutVisitor, expr: &mut Expr) { ExprKind::Paren(expr) | ExprKind::Return(expr) | ExprKind::UnOp(_, expr) => { vis.visit_expr(expr); } - ExprKind::Path(path) => vis.visit_path_result(path), + ExprKind::Path(path) => vis.visit_path_kind(path), ExprKind::Range(start, step, end) => { start.iter_mut().for_each(|s| vis.visit_expr(s)); step.iter_mut().for_each(|s| vis.visit_expr(s)); @@ -331,7 +331,7 @@ pub fn walk_expr(vis: &mut impl MutVisitor, expr: &mut Expr) { fixup.iter_mut().for_each(|f| vis.visit_block(f)); } ExprKind::Struct(name, copy, fields) => { - vis.visit_path_result(name); + vis.visit_path_kind(name); copy.iter_mut().for_each(|c| vis.visit_expr(c)); fields.iter_mut().for_each(|f| vis.visit_field_assign(f)); } @@ -389,17 +389,17 @@ pub fn walk_path(vis: &mut impl MutVisitor, path: &mut Path) { vis.visit_ident(&mut path.name); } -pub fn walk_path_result(vis: &mut impl MutVisitor, path: &mut PathResult) { +pub fn walk_path_kind(vis: &mut impl MutVisitor, path: &mut PathKind) { match path { - PathResult::Ok(path) => vis.visit_path(path), - PathResult::Err(Some(incomplete_path)) => { + PathKind::Ok(path) => vis.visit_path(path), + PathKind::Err(Some(incomplete_path)) => { vis.visit_span(&mut incomplete_path.span); for ref mut ident in &mut incomplete_path.segments { vis.visit_ident(ident); } } - PathResult::Err(None) => {} + PathKind::Err(None) => {} } } diff --git a/compiler/qsc_ast/src/visit.rs b/compiler/qsc_ast/src/visit.rs index a44188d675..09d3066774 100644 --- a/compiler/qsc_ast/src/visit.rs +++ b/compiler/qsc_ast/src/visit.rs @@ -3,7 +3,7 @@ use crate::ast::{ Attr, Block, CallableBody, CallableDecl, Expr, ExprKind, FieldAssign, FieldDef, FunctorExpr, - FunctorExprKind, Ident, Item, ItemKind, Namespace, Package, Pat, PatKind, Path, PathResult, + FunctorExprKind, Ident, Item, ItemKind, Namespace, Package, Pat, PatKind, Path, PathKind, QubitInit, QubitInitKind, SpecBody, SpecDecl, Stmt, StmtKind, StringComponent, StructDecl, TopLevelNode, Ty, TyDef, TyDefKind, TyKind, }; @@ -81,8 +81,8 @@ pub trait Visitor<'a>: Sized { walk_path(self, path); } - fn visit_path_result(&mut self, path: &'a PathResult) { - walk_path_result(self, path); + fn visit_path_kind(&mut self, path: &'a PathKind) { + walk_path_kind(self, path); } fn visit_ident(&mut self, _: &'a Ident) {} @@ -111,7 +111,7 @@ pub fn walk_item<'a>(vis: &mut impl Visitor<'a>, item: &'a Item) { ItemKind::Err => {} ItemKind::Callable(decl) => vis.visit_callable_decl(decl), ItemKind::Open(ns, alias) => { - vis.visit_path_result(ns); + vis.visit_path_kind(ns); alias.iter().for_each(|a| vis.visit_ident(a)); } ItemKind::Ty(ident, def) => { @@ -121,7 +121,7 @@ pub fn walk_item<'a>(vis: &mut impl Visitor<'a>, item: &'a Item) { ItemKind::Struct(decl) => vis.visit_struct_decl(decl), ItemKind::ImportOrExport(decl) => { for item in &decl.items { - vis.visit_path_result(&item.path); + vis.visit_path_kind(&item.path); if let Some(ref alias) = item.alias { vis.visit_ident(alias); } @@ -200,7 +200,7 @@ pub fn walk_ty<'a>(vis: &mut impl Visitor<'a>, ty: &'a Ty) { } TyKind::Hole | TyKind::Err => {} TyKind::Paren(ty) => vis.visit_ty(ty), - TyKind::Path(path) => vis.visit_path_result(path), + TyKind::Path(path) => vis.visit_path_kind(path), TyKind::Param(name) => vis.visit_ident(name), TyKind::Tuple(tys) => tys.iter().for_each(|t| vis.visit_ty(t)), } @@ -288,7 +288,7 @@ pub fn walk_expr<'a>(vis: &mut impl Visitor<'a>, expr: &'a Expr) { ExprKind::Paren(expr) | ExprKind::Return(expr) | ExprKind::UnOp(_, expr) => { vis.visit_expr(expr); } - ExprKind::Path(path) => vis.visit_path_result(path), + ExprKind::Path(path) => vis.visit_path_kind(path), ExprKind::Range(start, step, end) => { start.iter().for_each(|s| vis.visit_expr(s)); step.iter().for_each(|s| vis.visit_expr(s)); @@ -300,7 +300,7 @@ pub fn walk_expr<'a>(vis: &mut impl Visitor<'a>, expr: &'a Expr) { fixup.iter().for_each(|f| vis.visit_block(f)); } ExprKind::Struct(name, copy, fields) => { - vis.visit_path_result(name); + vis.visit_path_kind(name); copy.iter().for_each(|c| vis.visit_expr(c)); fields.iter().for_each(|f| vis.visit_field_assign(f)); } @@ -352,13 +352,13 @@ pub fn walk_path<'a>(vis: &mut impl Visitor<'a>, path: &'a Path) { vis.visit_ident(&path.name); } -pub fn walk_path_result<'a>(vis: &mut impl Visitor<'a>, path: &'a PathResult) { +pub fn walk_path_kind<'a>(vis: &mut impl Visitor<'a>, path: &'a PathKind) { match path { - PathResult::Ok(path) => vis.visit_path(path), - PathResult::Err(Some(incomplete_path)) => { + PathKind::Ok(path) => vis.visit_path(path), + PathKind::Err(Some(incomplete_path)) => { vis.visit_idents(&incomplete_path.segments); } - PathResult::Err(None) => {} + PathKind::Err(None) => {} } } diff --git a/compiler/qsc_codegen/src/qsharp.rs b/compiler/qsc_codegen/src/qsharp.rs index 373a579e6a..ffc212768d 100644 --- a/compiler/qsc_codegen/src/qsharp.rs +++ b/compiler/qsc_codegen/src/qsharp.rs @@ -16,9 +16,9 @@ use std::vec; use qsc_ast::ast::{ self, Attr, BinOp, Block, CallableBody, CallableDecl, CallableKind, Expr, ExprKind, Functor, FunctorExpr, FunctorExprKind, Ident, Idents, ImportOrExportItem, Item, ItemKind, Lit, - Mutability, Pat, PatKind, Path, PathResult, Pauli, QubitInit, QubitInitKind, QubitSource, - SetOp, SpecBody, SpecDecl, SpecGen, Stmt, StmtKind, StringComponent, TernOp, TopLevelNode, Ty, - TyDef, TyDefKind, TyKind, UnOp, + Mutability, Pat, PatKind, Path, PathKind, Pauli, QubitInit, QubitInitKind, QubitSource, SetOp, + SpecBody, SpecDecl, SpecGen, Stmt, StmtKind, StringComponent, TernOp, TopLevelNode, Ty, TyDef, + TyDefKind, TyKind, UnOp, }; use qsc_ast::ast::{Namespace, Package}; use qsc_ast::visit::Visitor; @@ -135,7 +135,7 @@ impl Visitor<'_> for QSharpGen { ItemKind::Callable(decl) => self.visit_callable_decl(decl), ItemKind::Open(ns, alias) => { self.write("open "); - self.visit_path_result(ns); + self.visit_path_kind(ns); if let Some(alias) = alias { self.write(" as "); self.visit_ident(alias); @@ -168,7 +168,7 @@ impl Visitor<'_> for QSharpGen { ) in decl.items.iter().enumerate() { let is_last = ix == decl.items.len() - 1; - self.visit_path_result(path); + self.visit_path_kind(path); if *is_glob { self.write(".*"); @@ -348,7 +348,7 @@ impl Visitor<'_> for QSharpGen { self.visit_ty(ty); self.write(")"); } - TyKind::Path(path) => self.visit_path_result(path), + TyKind::Path(path) => self.visit_path_kind(path), TyKind::Param(name) => self.visit_ident(name), TyKind::Tuple(tys) => { if tys.is_empty() { @@ -550,7 +550,7 @@ impl Visitor<'_> for QSharpGen { self.write("return "); self.visit_expr(expr); } - ExprKind::Struct(PathResult::Ok(path), copy, assigns) => { + ExprKind::Struct(PathKind::Ok(path), copy, assigns) => { self.write("new "); self.visit_path(path); self.writeln(" {"); @@ -581,7 +581,7 @@ impl Visitor<'_> for QSharpGen { self.visit_expr(expr); } } - ExprKind::Path(PathResult::Ok(path)) => self.visit_path(path), + ExprKind::Path(PathKind::Ok(path)) => self.visit_path(path), ExprKind::Range(start, step, end) => { // A range: `start..step..end`, `start..end`, `start...`, `...end`, or `...`. match (start, step, end) { @@ -715,8 +715,8 @@ impl Visitor<'_> for QSharpGen { self.write("_"); } ExprKind::Err - | ExprKind::Path(PathResult::Err(_)) - | ExprKind::Struct(PathResult::Err(_), ..) => { + | ExprKind::Path(PathKind::Err(_)) + | ExprKind::Struct(PathKind::Err(_), ..) => { unreachable!(); } } diff --git a/compiler/qsc_doc_gen/src/display.rs b/compiler/qsc_doc_gen/src/display.rs index 7c1a590da3..f579b40d3d 100644 --- a/compiler/qsc_doc_gen/src/display.rs +++ b/compiler/qsc_doc_gen/src/display.rs @@ -516,7 +516,7 @@ impl<'a> Display for AstTy<'a> { } ast::TyKind::Hole => write!(f, "_"), ast::TyKind::Paren(ty) => write!(f, "{}", AstTy { ty }), - ast::TyKind::Path(path) => write!(f, "{}", AstPathResult { path }), + ast::TyKind::Path(path) => write!(f, "{}", AstPathKind { path }), ast::TyKind::Param(id) => write!(f, "{}", id.name), ast::TyKind::Tuple(tys) => fmt_tuple(f, tys, |ty| AstTy { ty }), ast::TyKind::Err => write!(f, "?"), @@ -540,13 +540,13 @@ impl<'a> Display for FunctorExpr<'a> { } } -struct AstPathResult<'a> { - path: &'a ast::PathResult, +struct AstPathKind<'a> { + path: &'a ast::PathKind, } -impl<'a> Display for AstPathResult<'a> { +impl<'a> Display for AstPathKind<'a> { fn fmt(&self, f: &mut Formatter<'_>) -> Result { - if let ast::PathResult::Ok(path) = self.path { + if let ast::PathKind::Ok(path) = self.path { write!(f, "{}", path.full_name()) } else { write!(f, "?") diff --git a/compiler/qsc_frontend/src/compile/preprocess.rs b/compiler/qsc_frontend/src/compile/preprocess.rs index 545bef2cdb..f79ba7d7a9 100644 --- a/compiler/qsc_frontend/src/compile/preprocess.rs +++ b/compiler/qsc_frontend/src/compile/preprocess.rs @@ -3,7 +3,7 @@ use core::str::FromStr; use qsc_ast::{ - ast::{Attr, ExprKind, Idents, ItemKind, Namespace, PathResult, Stmt, StmtKind, UnOp}, + ast::{Attr, ExprKind, Idents, ItemKind, Namespace, PathKind, Stmt, StmtKind, UnOp}, mut_visit::MutVisitor, }; use qsc_hir::hir; @@ -141,7 +141,7 @@ fn matches_config(attrs: &[Box], capabilities: TargetCapabilityFlags) -> b for attr in attrs { if let ExprKind::Paren(inner) = attr.arg.kind.as_ref() { match inner.kind.as_ref() { - ExprKind::Path(PathResult::Ok(path)) => { + ExprKind::Path(PathKind::Ok(path)) => { if let Ok(capability) = TargetCapabilityFlags::from_str(path.name.name.as_ref()) { if capability.is_empty() { @@ -153,7 +153,7 @@ fn matches_config(attrs: &[Box], capabilities: TargetCapabilityFlags) -> b } } ExprKind::UnOp(UnOp::NotL, inner) => { - if let ExprKind::Path(PathResult::Ok(path)) = inner.kind.as_ref() { + if let ExprKind::Path(PathKind::Ok(path)) = inner.kind.as_ref() { if let Ok(capability) = TargetCapabilityFlags::from_str(path.name.name.as_ref()) { diff --git a/compiler/qsc_frontend/src/compile/preprocess/tests.rs b/compiler/qsc_frontend/src/compile/preprocess/tests.rs index 77e6eb8ebb..5991416482 100644 --- a/compiler/qsc_frontend/src/compile/preprocess/tests.rs +++ b/compiler/qsc_frontend/src/compile/preprocess/tests.rs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use qsc_ast::ast::{Attr, Expr, ExprKind, Ident, NodeId, Path, PathResult}; +use qsc_ast::ast::{Attr, Expr, ExprKind, Ident, NodeId, Path, PathKind}; use qsc_data_structures::span::Span; use crate::compile::{preprocess::matches_config, TargetCapabilityFlags}; @@ -36,7 +36,7 @@ fn name_value_attr(name: &str, value: &str) -> Attr { kind: Box::new(ExprKind::Paren(Box::new(Expr { id: NodeId::default(), span: Span::default(), - kind: Box::new(ExprKind::Path(PathResult::Ok(Box::new(Path { + kind: Box::new(ExprKind::Path(PathKind::Ok(Box::new(Path { id: NodeId::default(), span: Span::default(), segments: None, diff --git a/compiler/qsc_frontend/src/lower.rs b/compiler/qsc_frontend/src/lower.rs index 22170a3d9f..360c1e856b 100644 --- a/compiler/qsc_frontend/src/lower.rs +++ b/compiler/qsc_frontend/src/lower.rs @@ -10,7 +10,7 @@ use crate::{ typeck::{self, convert}, }; use miette::Diagnostic; -use qsc_ast::ast::{self, Ident, Idents, PathResult}; +use qsc_ast::ast::{self, Ident, Idents, PathKind}; use qsc_data_structures::{index_map::IndexMap, span::Span, target::TargetCapabilityFlags}; use qsc_hir::{ assigner::Assigner, @@ -135,7 +135,7 @@ impl With<'_> { let exports: Vec<(_, Option)> = namespace .exports() .filter_map(|item| { - let PathResult::Ok(path) = &item.path else { + let PathKind::Ok(path) = &item.path else { return None; }; self.names.get(path.id).map(|x| (x, item.alias.clone())) @@ -324,13 +324,13 @@ impl With<'_> { match &*attr.arg.kind { // @Config(Capability) ast::ExprKind::Paren(inner) - if matches!(inner.kind.as_ref(), ast::ExprKind::Path(PathResult::Ok(path)) + if matches!(inner.kind.as_ref(), ast::ExprKind::Path(PathKind::Ok(path)) if TargetCapabilityFlags::from_str(path.name.name.as_ref()).is_ok()) => {} // @Config(not Capability) ast::ExprKind::Paren(inner) if matches!(inner.kind.as_ref(), ast::ExprKind::UnOp(ast::UnOp::NotL, inner) - if matches!(inner.kind.as_ref(), ast::ExprKind::Path(PathResult::Ok(path)) + if matches!(inner.kind.as_ref(), ast::ExprKind::Path(PathKind::Ok(path)) if TargetCapabilityFlags::from_str(path.as_ref().name.name.as_ref()).is_ok())) => {} @@ -619,7 +619,7 @@ impl With<'_> { } ast::ExprKind::Lit(lit) => lower_lit(lit), ast::ExprKind::Paren(_) => unreachable!("parentheses should be removed earlier"), - ast::ExprKind::Path(PathResult::Ok(path)) => { + ast::ExprKind::Path(PathKind::Ok(path)) => { let args = self .tys .generics @@ -638,7 +638,7 @@ impl With<'_> { fixup.as_ref().map(|f| self.lower_block(f)), ), ast::ExprKind::Return(expr) => hir::ExprKind::Return(Box::new(self.lower_expr(expr))), - ast::ExprKind::Struct(PathResult::Ok(path), copy, fields) => hir::ExprKind::Struct( + ast::ExprKind::Struct(PathKind::Ok(path), copy, fields) => hir::ExprKind::Struct( self.node_id_to_res(path.id), copy.as_ref().map(|c| Box::new(self.lower_expr(c))), fields @@ -680,10 +680,9 @@ impl With<'_> { ast::ExprKind::While(cond, body) => { hir::ExprKind::While(Box::new(self.lower_expr(cond)), self.lower_block(body)) } - ast::ExprKind::Err | &ast::ExprKind::Path(ast::PathResult::Err(_)) => { - hir::ExprKind::Err - } - ast::ExprKind::Struct(ast::PathResult::Err(_), ..) => hir::ExprKind::Err, + ast::ExprKind::Err + | &ast::ExprKind::Path(ast::PathKind::Err(_)) + | ast::ExprKind::Struct(ast::PathKind::Err(_), ..) => hir::ExprKind::Err, }; hir::Expr { diff --git a/compiler/qsc_frontend/src/resolve.rs b/compiler/qsc_frontend/src/resolve.rs index 83117d75c6..3d12aac36c 100644 --- a/compiler/qsc_frontend/src/resolve.rs +++ b/compiler/qsc_frontend/src/resolve.rs @@ -7,7 +7,7 @@ mod tests; use miette::Diagnostic; use qsc_ast::{ ast::{ - self, CallableBody, CallableDecl, Ident, Idents, NodeId, PathResult, SpecBody, SpecGen, + self, CallableBody, CallableDecl, Ident, Idents, NodeId, PathKind, SpecBody, SpecGen, TopLevelNode, }, visit::{self as ast_visit, walk_attr, Visitor as AstVisitor}, @@ -510,7 +510,7 @@ impl AstVisitor<'_> for ExportImportVisitor<'_> { .resolver .bind_import_or_export(decl, Some((ns, &namespace.name))); } - ItemKind::Open(PathResult::Ok(path), alias) => { + ItemKind::Open(PathKind::Ok(path), alias) => { // we only need to bind opens that are in top-level namespaces, outside of callables. // this is because this is for the intermediate export-binding pass // and in the export-binding pass, we only need to know what symbols are available @@ -802,7 +802,7 @@ impl Resolver { ) { match &*item.kind { ast::ItemKind::Open(name, alias) => { - if let PathResult::Ok(path) = name { + if let PathKind::Ok(path) = name { self.bind_open( path.as_ref(), alias, @@ -892,7 +892,7 @@ impl Resolver { // problem without upleveling the preprocessor into the resolver, so it can do resolution-aware // dropped_names population. .filter(|item| { - if let (Some(ref current_namespace_name), PathResult::Ok(path)) = + if let (Some(ref current_namespace_name), PathKind::Ok(path)) = (¤t_namespace_name, &item.path) { let item_as_tracked_name = path_as_tracked_name(path, current_namespace_name); @@ -903,7 +903,7 @@ impl Resolver { }) .collect::>() { - let PathResult::Ok(path) = &decl_item.path else { + let PathKind::Ok(path) = &decl_item.path else { continue; }; let Some(decl_item_name) = decl_item.name() else { @@ -1102,7 +1102,7 @@ impl Resolver { /// Globs can only be attached to namespaces, and /// they import all items from the namespace into the current scope. fn bind_glob_import_or_export(&mut self, item: &ImportOrExportItem, is_export: bool) { - let PathResult::Ok(path) = &item.path else { + let PathKind::Ok(path) = &item.path else { return; }; @@ -1171,7 +1171,7 @@ impl Resolver { current_namespace: Option, err: &Error, ) -> Result<(), ClobberedNamespace> { - let PathResult::Ok(path) = &item.path else { + let PathKind::Ok(path) = &item.path else { return Ok(()); }; @@ -1295,7 +1295,7 @@ impl AstVisitor<'_> for With<'_> { // Only locally scoped imports and exports are handled here. self.resolver.bind_import_or_export(decl, None); } - ItemKind::Open(PathResult::Ok(path), alias) => { + ItemKind::Open(PathKind::Ok(path), alias) => { let scopes = self.resolver.curr_scope_chain.iter().rev(); let namespace = scopes .into_iter() @@ -1361,7 +1361,7 @@ impl AstVisitor<'_> for With<'_> { fn visit_ty(&mut self, ty: &ast::Ty) { match &*ty.kind { - ast::TyKind::Path(PathResult::Ok(path)) => { + ast::TyKind::Path(PathKind::Ok(path)) => { if let Err(e) = self.resolver.resolve_path(NameKind::Ty, path) { self.resolver.errors.push(e); } @@ -1428,7 +1428,7 @@ impl AstVisitor<'_> for With<'_> { visitor.visit_expr(output); }); } - ast::ExprKind::Path(PathResult::Ok(path)) => { + ast::ExprKind::Path(PathKind::Ok(path)) => { if let Err(e) = self.resolver.resolve_path(NameKind::Term, path) { self.resolver.errors.push(e); }; @@ -1447,7 +1447,7 @@ impl AstVisitor<'_> for With<'_> { } self.visit_expr(replace); } - ast::ExprKind::Struct(PathResult::Ok(path), copy, fields) => { + ast::ExprKind::Struct(PathKind::Ok(path), copy, fields) => { if let Err(e) = self.resolver.resolve_path(NameKind::Ty, path) { self.resolver.errors.push(e); }; @@ -1694,7 +1694,7 @@ fn bind_global_items( pub(super) fn extract_field_name<'a>(names: &Names, expr: &'a ast::Expr) -> Option<&'a Rc> { // Follow the same reasoning as `is_field_update`. match &*expr.kind { - ast::ExprKind::Path(PathResult::Ok(path)) + ast::ExprKind::Path(PathKind::Ok(path)) if path.segments.is_none() && !matches!(names.get(path.id), Some(Res::Local(_))) => { Some(&path.name.name) @@ -1711,7 +1711,7 @@ fn is_field_update<'a>( // Disambiguate the update operator by looking at the index expression. If it's an // unqualified path that doesn't resolve to a local, assume that it's meant to be a field name. match &*index.kind { - ast::ExprKind::Path(PathResult::Ok(path)) if path.segments.is_none() => !matches!( + ast::ExprKind::Path(PathKind::Ok(path)) if path.segments.is_none() => !matches!( { let name = &path.name; let namespace = &path.segments; @@ -1748,7 +1748,7 @@ fn bind_global_item( Ok(()) } else { for decl_item in &decl.items { - let PathResult::Ok(path) = &decl_item.path else { + let PathKind::Ok(path) = &decl_item.path else { continue; }; let Some(decl_item_name) = decl_item.name() else { diff --git a/compiler/qsc_frontend/src/resolve/tests.rs b/compiler/qsc_frontend/src/resolve/tests.rs index 2f3c3ca959..2851b059ef 100644 --- a/compiler/qsc_frontend/src/resolve/tests.rs +++ b/compiler/qsc_frontend/src/resolve/tests.rs @@ -10,7 +10,7 @@ use crate::{ }; use expect_test::{expect, Expect}; use indoc::indoc; -use qsc_ast::ast::{Idents, Item, ItemKind, PathResult}; +use qsc_ast::ast::{Idents, Item, ItemKind, PathKind}; use qsc_ast::{ assigner::Assigner as AstAssigner, ast::{Ident, NodeId, Package, Path, TopLevelNode}, @@ -137,7 +137,7 @@ impl Visitor<'_> for Renamer<'_> { fn visit_item(&mut self, item: &'_ Item) { match &*item.kind { - ItemKind::Open(PathResult::Ok(namespace), Some(alias)) => { + ItemKind::Open(PathKind::Ok(namespace), Some(alias)) => { if let Some(ns_id) = self.namespaces.get_namespace_id(namespace.str_iter()) { // self.changes.push((item.span, ns_id.into())); self.aliases.insert(vec![alias.name.clone()], ns_id); @@ -147,7 +147,7 @@ impl Visitor<'_> for Renamer<'_> { } ItemKind::ImportOrExport(export) => { for item in export.items() { - let PathResult::Ok(path) = &item.path else { + let PathKind::Ok(path) = &item.path else { continue; }; if let Some(res) = self.names.get(path.id) { diff --git a/compiler/qsc_frontend/src/typeck/convert.rs b/compiler/qsc_frontend/src/typeck/convert.rs index 615dd80ff0..dc97f6493e 100644 --- a/compiler/qsc_frontend/src/typeck/convert.rs +++ b/compiler/qsc_frontend/src/typeck/convert.rs @@ -6,7 +6,7 @@ use std::rc::Rc; use crate::resolve::{self, Names}; use qsc_ast::ast::{ self, CallableBody, CallableDecl, CallableKind, FunctorExpr, FunctorExprKind, Ident, Pat, - PatKind, Path, PathResult, SetOp, Spec, StructDecl, TyDef, TyDefKind, TyKind, + PatKind, Path, PathKind, SetOp, Spec, StructDecl, TyDef, TyDefKind, TyKind, }; use qsc_data_structures::span::Span; use qsc_hir::{ @@ -42,7 +42,7 @@ pub(crate) fn ty_from_ast(names: &Names, ty: &ast::Ty) -> (Ty, Vec (Ty::Err, vec![MissingTyError(ty.span)]), TyKind::Paren(inner) => ty_from_ast(names, inner), - TyKind::Path(PathResult::Ok(path)) => (ty_from_path(names, path), Vec::new()), + TyKind::Path(PathKind::Ok(path)) => (ty_from_path(names, path), Vec::new()), TyKind::Param(name) => match names.get(name.id) { Some(resolve::Res::Param(id)) => (Ty::Param(name.name.clone(), *id), Vec::new()), Some(_) => unreachable!( @@ -61,7 +61,7 @@ pub(crate) fn ty_from_ast(names: &Names, ty: &ast::Ty) -> (Ty, Vec (Ty::Err, Vec::new()), + TyKind::Err | TyKind::Path(PathKind::Err { .. }) => (Ty::Err, Vec::new()), } } diff --git a/compiler/qsc_frontend/src/typeck/rules.rs b/compiler/qsc_frontend/src/typeck/rules.rs index 509add956a..59eac78b09 100644 --- a/compiler/qsc_frontend/src/typeck/rules.rs +++ b/compiler/qsc_frontend/src/typeck/rules.rs @@ -8,9 +8,8 @@ use super::{ }; use crate::resolve::{self, Names, Res}; use qsc_ast::ast::{ - self, BinOp, Block, Expr, ExprKind, Functor, Ident, Lit, NodeId, Pat, PatKind, Path, - PathResult, QubitInit, QubitInitKind, Spec, Stmt, StmtKind, StringComponent, TernOp, TyKind, - UnOp, + self, BinOp, Block, Expr, ExprKind, Functor, Ident, Lit, NodeId, Pat, PatKind, Path, PathKind, + QubitInit, QubitInitKind, Spec, Stmt, StmtKind, StringComponent, TernOp, TyKind, UnOp, }; use qsc_data_structures::span::Span; use qsc_hir::{ @@ -106,7 +105,7 @@ impl<'a> Context<'a> { })), TyKind::Hole => self.inferrer.fresh_ty(TySource::not_divergent(ty.span)), TyKind::Paren(inner) => self.infer_ty(inner), - TyKind::Path(PathResult::Ok(path)) => match self.names.get(path.id) { + TyKind::Path(PathKind::Ok(path)) => match self.names.get(path.id) { Some(&Res::Item(item, _)) => Ty::Udt(path.name.name.clone(), hir::Res::Item(item)), Some(&Res::PrimTy(prim)) => Ty::Prim(prim), Some(Res::UnitTy) => Ty::Tuple(Vec::new()), @@ -137,7 +136,7 @@ impl<'a> Context<'a> { TyKind::Tuple(items) => { Ty::Tuple(items.iter().map(|item| self.infer_ty(item)).collect()) } - TyKind::Err | TyKind::Path(PathResult::Err { .. }) => Ty::Err, + TyKind::Err | TyKind::Path(PathKind::Err { .. }) => Ty::Err, } } @@ -395,7 +394,7 @@ impl<'a> Context<'a> { Lit::String(_) => converge(Ty::Prim(Prim::String)), }, ExprKind::Paren(expr) => self.infer_expr(expr), - ExprKind::Path(PathResult::Ok(path)) => self.infer_path(expr, path), + ExprKind::Path(PathKind::Ok(path)) => self.infer_path(expr, path), ExprKind::Range(start, step, end) => { let mut diverges = false; for expr in start.iter().chain(step).chain(end) { @@ -445,7 +444,7 @@ impl<'a> Context<'a> { } self.diverge() } - ExprKind::Struct(PathResult::Ok(name), copy, fields) => { + ExprKind::Struct(PathKind::Ok(name), copy, fields) => { let container = convert::ty_from_path(self.names, name); self.inferrer @@ -534,8 +533,8 @@ impl<'a> Context<'a> { converge(self.inferrer.fresh_ty(TySource::not_divergent(expr.span))) } ExprKind::Err - | ast::ExprKind::Path(ast::PathResult::Err(_)) - | ast::ExprKind::Struct(ast::PathResult::Err(_), ..) => converge(Ty::Err), + | ast::ExprKind::Path(ast::PathKind::Err(_)) + | ast::ExprKind::Struct(ast::PathKind::Err(_), ..) => converge(Ty::Err), }; self.record(expr.id, ty.ty.clone()); diff --git a/compiler/qsc_linter/src/linter/ast.rs b/compiler/qsc_linter/src/linter/ast.rs index 9f6813d000..697998ad4c 100644 --- a/compiler/qsc_linter/src/linter/ast.rs +++ b/compiler/qsc_linter/src/linter/ast.rs @@ -8,7 +8,7 @@ use crate::{ use qsc_ast::{ ast::{ Attr, Block, CallableDecl, Expr, FunctorExpr, Ident, Item, Namespace, Package, Pat, Path, - PathResult, QubitInit, SpecDecl, Stmt, TopLevelNode, Ty, TyDef, + PathKind, QubitInit, SpecDecl, Stmt, TopLevelNode, Ty, TyDef, }, visit::Visitor, }; @@ -57,7 +57,7 @@ pub(crate) trait AstLintPass { fn check_package(&self, _package: &Package, _buffer: &mut Vec) {} fn check_pat(&self, _pat: &Pat, _buffer: &mut Vec) {} fn check_path(&self, _path: &Path, _buffer: &mut Vec) {} - fn check_path_result(&self, _path: &PathResult, _buffer: &mut Vec) {} + fn check_path_kind(&self, _path: &PathKind, _buffer: &mut Vec) {} fn check_qubit_init(&self, _qubit_init: &QubitInit, _buffer: &mut Vec) {} fn check_spec_decl(&self, _spec_decl: &SpecDecl, _buffer: &mut Vec) {} fn check_stmt(&self, _stmt: &Stmt, _buffer: &mut Vec) {} @@ -85,7 +85,7 @@ macro_rules! declare_ast_lints { use crate::{linter::ast::{declare_ast_lints, AstLintPass}, Lint, LintLevel}; use qsc_ast::{ ast::{ - Attr, Block, CallableDecl, Expr, FunctorExpr, Ident, Item, Namespace, Package, Pat, Path, PathResult, + Attr, Block, CallableDecl, Expr, FunctorExpr, Ident, Item, Namespace, Package, Pat, Path, PathKind, QubitInit, SpecDecl, Stmt, Ty, TyDef, }, visit::{self, Visitor}, @@ -205,7 +205,7 @@ macro_rules! declare_ast_lints { fn check_pat(&mut self, pat: &Pat) { $(self.$lint_name.check_pat(pat, &mut self.buffer));*; } fn check_qubit_init(&mut self, init: &QubitInit) { $(self.$lint_name.check_qubit_init(init, &mut self.buffer));*; } fn check_path(&mut self, path: &Path) { $(self.$lint_name.check_path(path, &mut self.buffer));*; } - fn check_path_result(&mut self, path: &PathResult) { $(self.$lint_name.check_path_result(path, &mut self.buffer));*; } + fn check_path_kind(&mut self, path: &PathKind) { $(self.$lint_name.check_path_kind(path, &mut self.buffer));*; } fn check_ident(&mut self, ident: &Ident) { $(self.$lint_name.check_ident(ident, &mut self.buffer));*; } } @@ -285,9 +285,9 @@ macro_rules! declare_ast_lints { visit::walk_path(self, path); } - fn visit_path_result(&mut self, path: &'a PathResult) { - self.check_path_result(path); - visit::walk_path_result(self, path); + fn visit_path_kind(&mut self, path: &'a PathKind) { + self.check_path_kind(path); + visit::walk_path_kind(self, path); } fn visit_ident(&mut self, ident: &'a Ident) { diff --git a/compiler/qsc_parse/src/expr.rs b/compiler/qsc_parse/src/expr.rs index 902bb25fa9..c419a36425 100644 --- a/compiler/qsc_parse/src/expr.rs +++ b/compiler/qsc_parse/src/expr.rs @@ -22,7 +22,7 @@ use num_bigint::BigInt; use num_traits::Num; use qsc_ast::ast::{ self, BinOp, CallableKind, Expr, ExprKind, FieldAssign, Functor, Lit, NodeId, Pat, PatKind, - PathResult, Pauli, StringComponent, TernOp, UnOp, + PathKind, Pauli, StringComponent, TernOp, UnOp, }; use qsc_data_structures::span::Span; use std::{result, str::FromStr}; @@ -360,7 +360,7 @@ fn expr_array_core(s: &mut ParserContext) -> Result> { } fn is_ident(name: &str, kind: &ExprKind) -> bool { - matches!(kind, ExprKind::Path(PathResult::Ok(path)) if path.segments.is_none() && path.name.name.as_ref() == name) + matches!(kind, ExprKind::Path(PathKind::Ok(path)) if path.segments.is_none() && path.name.name.as_ref() == name) } fn expr_range_prefix(s: &mut ParserContext) -> Result> { @@ -757,7 +757,7 @@ fn next_precedence(precedence: u8, assoc: Assoc) -> u8 { fn expr_as_pat(expr: Expr) -> Result> { let kind = Box::new(match *expr.kind { - ExprKind::Path(PathResult::Ok(path)) if path.segments.is_none() => { + ExprKind::Path(PathKind::Ok(path)) if path.segments.is_none() => { Ok(PatKind::Bind(path.name, None)) } ExprKind::Hole => Ok(PatKind::Discard(None)), diff --git a/compiler/qsc_parse/src/item.rs b/compiler/qsc_parse/src/item.rs index d803f903ea..5875666cea 100644 --- a/compiler/qsc_parse/src/item.rs +++ b/compiler/qsc_parse/src/item.rs @@ -32,7 +32,7 @@ use crate::{ use qsc_ast::ast::{ Attr, Block, CallableBody, CallableDecl, CallableKind, FieldDef, Ident, Idents, ImportOrExportDecl, ImportOrExportItem, Item, ItemKind, Namespace, NodeId, Pat, PatKind, Path, - PathResult, Spec, SpecBody, SpecDecl, SpecGen, StmtKind, StructDecl, TopLevelNode, Ty, TyDef, + PathKind, Spec, SpecBody, SpecDecl, SpecGen, StmtKind, StructDecl, TopLevelNode, Ty, TyDef, TyDefKind, TyKind, }; use qsc_data_structures::language_features::LanguageFeatures; @@ -474,7 +474,7 @@ fn parse_ty_def(s: &mut ParserContext) -> Result> { } fn ty_as_ident(ty: Ty) -> Result> { - let TyKind::Path(PathResult::Ok(path)) = *ty.kind else { + let TyKind::Path(PathKind::Ok(path)) = *ty.kind else { return Err(Error::new(ErrorKind::Convert( "identifier", "type", @@ -671,9 +671,9 @@ fn parse_import_or_export(s: &mut ParserContext) -> Result { } /// A path with an optional glob indicator at the end, e.g. `Foo.Bar.*` -fn path_import(s: &mut ParserContext) -> Result<(PathResult, bool)> { +fn path_import(s: &mut ParserContext) -> Result<(PathKind, bool)> { match path(s, WordKinds::PathImport) { - Ok(path) => Ok((PathResult::Ok(path), false)), + Ok(path) => Ok((PathKind::Ok(path), false)), Err((error, Some(incomplete_path))) => { if token(s, TokenKind::ClosedBinOp(ClosedBinOp::Star)).is_ok() { let (name, namespace) = incomplete_path @@ -682,7 +682,7 @@ fn path_import(s: &mut ParserContext) -> Result<(PathResult, bool)> { .expect("path should have at least one part"); Ok(( - PathResult::Ok(Box::new(Path { + PathKind::Ok(Box::new(Path { id: NodeId::default(), span: incomplete_path.segments.full_span(), segments: if namespace.is_empty() { @@ -696,7 +696,7 @@ fn path_import(s: &mut ParserContext) -> Result<(PathResult, bool)> { )) } else { s.push_error(error); - Ok((PathResult::Err(Some(incomplete_path)), false)) + Ok((PathKind::Err(Some(incomplete_path)), false)) } } Err((error, None)) => Err(error), diff --git a/compiler/qsc_parse/src/prim.rs b/compiler/qsc_parse/src/prim.rs index e66338189c..d684a6ed1d 100644 --- a/compiler/qsc_parse/src/prim.rs +++ b/compiler/qsc_parse/src/prim.rs @@ -11,7 +11,7 @@ use crate::{ lex::{Delim, TokenKind}, ErrorKind, }; -use qsc_ast::ast::{Ident, IncompletePath, NodeId, Pat, PatKind, Path, PathResult}; +use qsc_ast::ast::{Ident, IncompletePath, NodeId, Pat, PatKind, Path, PathKind}; use qsc_data_structures::span::{Span, WithSpan}; #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -143,14 +143,14 @@ pub(super) fn path( /// Recovering [`Path`] parser. Parsing only fails if no segments /// were successfully parsed. If any segments were successfully parsed, -/// returns a [`PathResult::Err`] containing the segments that were +/// returns a [`PathKind::Err`] containing the segments that were /// successfully parsed up to the final `.` token. -pub(super) fn recovering_path(s: &mut ParserContext, kind: WordKinds) -> Result { +pub(super) fn recovering_path(s: &mut ParserContext, kind: WordKinds) -> Result { match path(s, kind) { - Ok(path) => Ok(PathResult::Ok(path)), + Ok(path) => Ok(PathKind::Ok(path)), Err((error, Some(incomplete_path))) => { s.push_error(error); - Ok(PathResult::Err(Some(incomplete_path))) + Ok(PathKind::Err(Some(incomplete_path))) } Err((error, None)) => Err(error), } diff --git a/compiler/qsc_parse/src/prim/tests.rs b/compiler/qsc_parse/src/prim/tests.rs index 7f2d0f17f4..daea66020f 100644 --- a/compiler/qsc_parse/src/prim/tests.rs +++ b/compiler/qsc_parse/src/prim/tests.rs @@ -12,10 +12,10 @@ use crate::{ Error, ErrorKind, }; use expect_test::expect; -use qsc_ast::ast::PathResult; +use qsc_ast::ast::PathKind; use qsc_data_structures::{language_features::LanguageFeatures, span::Span}; -fn path(s: &mut ParserContext) -> Result { +fn path(s: &mut ParserContext) -> Result { super::recovering_path(s, WordKinds::empty()) } diff --git a/compiler/qsc_qasm3/src/ast_builder.rs b/compiler/qsc_qasm3/src/ast_builder.rs index 53cd6ee292..3eaa5e958e 100644 --- a/compiler/qsc_qasm3/src/ast_builder.rs +++ b/compiler/qsc_qasm3/src/ast_builder.rs @@ -8,7 +8,7 @@ use num_bigint::BigInt; use qsc::{ ast::{ self, Attr, Block, CallableBody, CallableDecl, CallableKind, Expr, ExprKind, Ident, Item, - Lit, Mutability, NodeId, Pat, PatKind, Path, PathResult, QubitInit, QubitInitKind, + Lit, Mutability, NodeId, Pat, PatKind, Path, PathKind, QubitInit, QubitInitKind, QubitSource, Stmt, StmtKind, TopLevelNode, Ty, TyKind, }, Span, @@ -28,7 +28,7 @@ where ..Default::default() }; let path_expr = Expr { - kind: Box::new(ExprKind::Path(PathResult::Ok(Box::new(Path { + kind: Box::new(ExprKind::Path(PathKind::Ok(Box::new(Path { segments: build_idents(&["QIR", "Runtime"]), name: Box::new(alloc_ident), id: NodeId::default(), @@ -83,7 +83,7 @@ where }; let path_expr = Expr { - kind: Box::new(ExprKind::Path(PathResult::Ok(Box::new(Path { + kind: Box::new(ExprKind::Path(PathKind::Ok(Box::new(Path { segments: build_idents(&["QIR", "Runtime"]), name: Box::new(alloc_ident), id: NodeId::default(), @@ -349,7 +349,7 @@ pub(crate) fn build_math_call_from_exprs(name: &str, exprs: Vec, span: Spa ..Default::default() }; let path_expr = Expr { - kind: Box::new(ExprKind::Path(PathResult::Ok(Box::new(Path { + kind: Box::new(ExprKind::Path(PathKind::Ok(Box::new(Path { segments: build_idents(&["Microsoft", "Quantum", "Math"]), name: Box::new(alloc_ident), id: NodeId::default(), @@ -395,7 +395,7 @@ pub(crate) fn build_path_ident_expr>( segments: None, name: Box::new(ident), }; - let path_kind = ast::ExprKind::Path(PathResult::Ok(Box::new(path))); + let path_kind = ast::ExprKind::Path(PathKind::Ok(Box::new(path))); ast::Expr { id: NodeId::default(), span: expr_span, @@ -419,7 +419,7 @@ pub(crate) fn build_indexed_assignment_statement>( let lhs = ast::Expr { id: NodeId::default(), span: name_span, - kind: Box::new(ast::ExprKind::Path(PathResult::Ok(Box::new(ast::Path { + kind: Box::new(ast::ExprKind::Path(PathKind::Ok(Box::new(ast::Path { id: NodeId::default(), span: name_span, segments: None, @@ -463,7 +463,7 @@ pub(crate) fn build_assignment_statement>( let lhs = ast::Expr { id: NodeId::default(), span: name_span, - kind: Box::new(ast::ExprKind::Path(PathResult::Ok(Box::new(path)))), + kind: Box::new(ast::ExprKind::Path(PathKind::Ok(Box::new(path)))), }; let expr_kind = ast::ExprKind::Assign(Box::new(lhs), Box::new(rhs)); let expr = ast::Expr { @@ -486,7 +486,7 @@ pub(crate) fn build_convert_call_expr(expr: Expr, name: &str) -> Expr { ..Default::default() }; let path_expr = Expr { - kind: Box::new(ExprKind::Path(PathResult::Ok(Box::new(Path { + kind: Box::new(ExprKind::Path(PathKind::Ok(Box::new(Path { segments: build_idents(&["Microsoft", "Quantum", "Convert"]), name: Box::new(cast_ident), id: NodeId::default(), @@ -516,7 +516,7 @@ pub(crate) fn build_array_reverse_expr(expr: Expr) -> Expr { ..Default::default() }; let path_expr = Expr { - kind: Box::new(ExprKind::Path(PathResult::Ok(Box::new(Path { + kind: Box::new(ExprKind::Path(PathKind::Ok(Box::new(Path { segments: build_idents(&["Microsoft", "Quantum", "Arrays"]), name: Box::new(cast_ident), id: NodeId::default(), @@ -687,7 +687,7 @@ pub(crate) fn build_global_call_with_one_param>( let callee_expr = ast::Expr { id: NodeId::default(), span: name_span, - kind: Box::new(ast::ExprKind::Path(PathResult::Ok(Box::new(ast::Path { + kind: Box::new(ast::ExprKind::Path(PathKind::Ok(Box::new(ast::Path { id: NodeId::default(), span: Span::default(), segments: None, @@ -724,7 +724,7 @@ pub(crate) fn build_global_call_with_two_params>( let callee_expr = ast::Expr { id: NodeId::default(), span: name_span, - kind: Box::new(ast::ExprKind::Path(PathResult::Ok(Box::new(ast::Path { + kind: Box::new(ast::ExprKind::Path(PathKind::Ok(Box::new(ast::Path { id: NodeId::default(), span: Span::default(), segments: None, @@ -786,7 +786,7 @@ pub(crate) fn build_call_no_params(name: &str, idents: &[&str], span: Span) -> E ..Default::default() }; let path_expr = Expr { - kind: Box::new(ExprKind::Path(PathResult::Ok(Box::new(Path { + kind: Box::new(ExprKind::Path(PathKind::Ok(Box::new(Path { segments, name: Box::new(fn_name), id: NodeId::default(), @@ -821,7 +821,7 @@ pub(crate) fn build_call_with_param( ..Default::default() }; let path_expr = Expr { - kind: Box::new(ExprKind::Path(PathResult::Ok(Box::new(Path { + kind: Box::new(ExprKind::Path(PathKind::Ok(Box::new(Path { segments, name: Box::new(fn_name), id: NodeId::default(), @@ -913,7 +913,7 @@ where name: ty.to_string().into(), ..Default::default() }; - let result_ty_path = ast::PathResult::Ok(Box::new(ast::Path { + let result_ty_path = ast::PathKind::Ok(Box::new(ast::Path { name: Box::new(result_ty_ident), segments: None, id: NodeId::default(), @@ -969,7 +969,7 @@ pub(crate) fn build_path_ident_ty>(name: S) -> Ty { name: Rc::from(name.as_ref()), ..Default::default() }; - let path = ast::PathResult::Ok(Box::new(ast::Path { + let path = ast::PathKind::Ok(Box::new(ast::Path { name: Box::new(ident), segments: Option::default(), id: NodeId::default(), @@ -987,7 +987,7 @@ pub(crate) fn build_complex_ty_ident() -> Ty { name: Rc::from("Complex"), ..Default::default() }; - let path = ast::PathResult::Ok(Box::new(ast::Path { + let path = ast::PathKind::Ok(Box::new(ast::Path { name: Box::new(ident), segments: build_idents(&["Microsoft", "Quantum", "Math"]), id: NodeId::default(), diff --git a/language_service/src/completion/global_items.rs b/language_service/src/completion/global_items.rs index 73fda18ade..5956556ba0 100644 --- a/language_service/src/completion/global_items.rs +++ b/language_service/src/completion/global_items.rs @@ -9,7 +9,7 @@ use crate::{ use qsc::{ ast::{ visit::{walk_block, walk_callable_decl, walk_item, walk_namespace, Visitor}, - Idents as _, Package as AstPackage, PathResult, + Idents as _, Package as AstPackage, PathKind, }, display::CodeDisplay, hir::{ty::Udt, CallableDecl, Idents, ItemKind, Package, PackageId, Visibility}, @@ -742,7 +742,7 @@ impl<'a> Visitor<'a> for ImportFinder { fn visit_item(&mut self, item: &'a qsc::ast::Item) { match &*item.kind { - qsc::ast::ItemKind::Open(PathResult::Ok(name), alias) => { + qsc::ast::ItemKind::Open(PathKind::Ok(name), alias) => { let open_as_import = ImportItem { path: name.rc_str_iter().cloned().collect(), alias: alias.as_ref().map(|x| x.name.clone()), @@ -796,7 +796,7 @@ impl ImportItem { }; let mut buf = Vec::with_capacity(decl.items.len()); for item in &decl.items { - let PathResult::Ok(path) = &item.path else { + let PathKind::Ok(path) = &item.path else { continue; }; let alias = item.alias.as_ref().map(|x| x.name.clone()); diff --git a/language_service/src/completion/path_context.rs b/language_service/src/completion/path_context.rs index e0fcc78760..a7f3bfc26a 100644 --- a/language_service/src/completion/path_context.rs +++ b/language_service/src/completion/path_context.rs @@ -5,8 +5,8 @@ use qsc::{ ast::{ visit::{self, Visitor}, Attr, Block, CallableDecl, Expr, ExprKind, FieldAssign, FieldDef, FunctorExpr, Ident, Item, - ItemKind, Namespace, Package, Pat, Path, PathResult, QubitInit, SpecDecl, Stmt, StructDecl, - Ty, TyDef, TyKind, + ItemKind, Namespace, Package, Pat, Path, QubitInit, SpecDecl, Stmt, StructDecl, Ty, TyDef, + TyKind, }, parse::completion::PathKind, }; @@ -63,11 +63,11 @@ impl<'a> Visitor<'a> for IncompletePath<'a> { } } - fn visit_path_result(&mut self, path: &'a PathResult) { + fn visit_path_kind(&mut self, path: &'a qsc::ast::PathKind) { self.qualifier = match path { - PathResult::Ok(path) => path.segments.as_ref().map(AsRef::as_ref), - PathResult::Err(Some(incomplete_path)) => Some(&incomplete_path.segments), - PathResult::Err(None) => None, + qsc::ast::PathKind::Ok(path) => path.segments.as_ref().map(AsRef::as_ref), + qsc::ast::PathKind::Err(Some(incomplete_path)) => Some(&incomplete_path.segments), + qsc::ast::PathKind::Err(None) => None, }; } } @@ -230,16 +230,16 @@ where } } - fn visit_path_result(&mut self, path: &'a PathResult) { + fn visit_path_kind(&mut self, path: &'a qsc::ast::PathKind) { let span = match path { - PathResult::Ok(path) => &path.span, - PathResult::Err(Some(incomplete_path)) => &incomplete_path.span, - PathResult::Err(None) => return, + qsc::ast::PathKind::Ok(path) => &path.span, + qsc::ast::PathKind::Err(Some(incomplete_path)) => &incomplete_path.span, + qsc::ast::PathKind::Err(None) => return, }; if span.touches(self.offset) { - self.visitor.visit_path_result(path); - visit::walk_path_result(self, path); + self.visitor.visit_path_kind(path); + visit::walk_path_kind(self, path); } } diff --git a/language_service/src/name_locator.rs b/language_service/src/name_locator.rs index 7afe956036..371cafc9c2 100644 --- a/language_service/src/name_locator.rs +++ b/language_service/src/name_locator.rs @@ -6,7 +6,7 @@ use std::rc::Rc; use crate::compilation::Compilation; use qsc::ast::visit::{walk_expr, walk_namespace, walk_pat, walk_ty, walk_ty_def, Visitor}; -use qsc::ast::{Idents, PathResult}; +use qsc::ast::{Idents, PathKind}; use qsc::display::Lookup; use qsc::{ast, hir, resolve}; @@ -349,7 +349,7 @@ impl<'inner, 'package, T: Handler<'package>> Visitor<'package> for Locator<'inne } } } - ast::ExprKind::Struct(PathResult::Ok(ty_name), copy, fields) => { + ast::ExprKind::Struct(PathKind::Ok(ty_name), copy, fields) => { if ty_name.span.touches(self.offset) { self.visit_path(ty_name); return; diff --git a/language_service/src/references.rs b/language_service/src/references.rs index f6d044b0dc..23c3dfe822 100644 --- a/language_service/src/references.rs +++ b/language_service/src/references.rs @@ -10,7 +10,7 @@ use crate::compilation::Compilation; use crate::name_locator::{Handler, Locator, LocatorContext}; use crate::qsc_utils::into_location; use qsc::ast::visit::{walk_callable_decl, walk_expr, walk_ty, Visitor}; -use qsc::ast::PathResult; +use qsc::ast::PathKind; use qsc::display::Lookup; use qsc::hir::ty::Ty; use qsc::hir::{PackageId, Res}; @@ -347,7 +347,7 @@ impl<'a> Visitor<'_> for FindItemRefs<'a> { } fn visit_ty(&mut self, ty: &ast::Ty) { - if let ast::TyKind::Path(PathResult::Ok(ty_path)) = &*ty.kind { + if let ast::TyKind::Path(PathKind::Ok(ty_path)) = &*ty.kind { let res = self.compilation.get_res(ty_path.id); if let Some(resolve::Res::Item(item_id, _)) = res { if self.eq(item_id) { @@ -410,7 +410,7 @@ impl<'a> Visitor<'_> for FindFieldRefs<'a> { } } } - ast::ExprKind::Struct(PathResult::Ok(struct_name), copy, fields) => { + ast::ExprKind::Struct(PathKind::Ok(struct_name), copy, fields) => { self.visit_path(struct_name); if let Some(copy) = copy { self.visit_expr(copy); diff --git a/language_service/src/signature_help.rs b/language_service/src/signature_help.rs index 44bb391bd2..2eb39ecf33 100644 --- a/language_service/src/signature_help.rs +++ b/language_service/src/signature_help.rs @@ -13,7 +13,7 @@ use qsc::{ ast::{ self, visit::{walk_expr, walk_item, Visitor}, - PathResult, + PathKind, }, display::{parse_doc_for_param, parse_doc_for_summary, CodeDisplay, Lookup}, hir, @@ -322,7 +322,7 @@ fn try_get_direct_callee<'a>( compilation: &'a Compilation, callee: &ast::Expr, ) -> Option<(hir::PackageId, &'a hir::CallableDecl, &'a str)> { - if let ast::ExprKind::Path(PathResult::Ok(path)) = &*callee.kind { + if let ast::ExprKind::Path(PathKind::Ok(path)) = &*callee.kind { if let Some(resolve::Res::Item(item_id, _)) = compilation.get_res(path.id) { let (item, _, resolved_item_id) = compilation.resolve_item_relative_to_user_package(item_id); diff --git a/language_service/src/tests.rs b/language_service/src/tests.rs index c745133a43..0d7baea437 100644 --- a/language_service/src/tests.rs +++ b/language_service/src/tests.rs @@ -211,7 +211,7 @@ async fn completions_requested_after_document_load() { worker.apply_pending().await; expect![[r#" - 333 + 334 "#]] .assert_debug_eq( &ls.get_completions(