Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
951897a
Let quoted tokens carry a span
asterite Feb 6, 2025
8f2ca2e
Let Lexer and Parser take a `FileId`
asterite Feb 6, 2025
81f4ee0
Merge branch 'master' into ab/macro-error-location
asterite Feb 7, 2025
83df011
Use `with_dummy_file` functions
asterite Feb 7, 2025
54492e4
Let the Lexer return LocatedTokens
asterite Feb 7, 2025
ceeba2a
Let the Parser use located tokens
asterite Feb 7, 2025
049afc7
Let Parser keep track of token locations
asterite Feb 7, 2025
ed74b4a
Use locations throughout most of Parser
asterite Feb 7, 2025
51a4f4c
A bit more Span -> Location
asterite Feb 7, 2025
5441a9e
A bit more...
asterite Feb 7, 2025
84265c3
Let Ident wrap Located<String>
asterite Feb 7, 2025
77086ee
Let Expression hold a Location
asterite Feb 7, 2025
ba48eee
Let Parser::push_error take a Location
asterite Feb 7, 2025
6a035cd
Let UnresolvedType hold a location
asterite Feb 7, 2025
958e079
Let Path hold a Location
asterite Feb 7, 2025
b179ca7
Let Pattern always hold a Location
asterite Feb 7, 2025
93c4555
Let NoirEnumeration hold a location
asterite Feb 7, 2025
470fc5b
Let FunctionDefinition hold a Location
asterite Feb 7, 2025
0e48cc5
Let Param hold a Location
asterite Feb 7, 2025
0b9ae18
Let ConstrainExpression hold a location
asterite Feb 7, 2025
4a92796
Let Statement hold a Location
asterite Feb 7, 2025
9da19b4
Let UseTree hold a Location
asterite Feb 7, 2025
4443fd1
Let PathSegment hold a Location
asterite Feb 7, 2025
dc186e9
Let ForLoopStatement hold a Location
asterite Feb 7, 2025
29e167a
Let NoirStructDef hold a Location
asterite Feb 7, 2025
58bc638
Let LValue hold a Location
asterite Feb 7, 2025
779f5b5
Let NoirTrait hold a Location
asterite Feb 7, 2025
6900ed6
Let TypeImpl hold a Location
asterite Feb 7, 2025
20c3fe0
Let TraitImplItem hold a Location
asterite Feb 7, 2025
78ed3c9
Let TypeAlias hold a Location
asterite Feb 7, 2025
b03b105
Let Comptime and Unsafe hold a Location
asterite Feb 7, 2025
48f38f3
Let Default return type hold a Location
asterite Feb 7, 2025
5027ba2
Let UnresolvedTypeExpression hold a Location
asterite Feb 7, 2025
8f17613
Let Loop hold a Location
asterite Feb 7, 2025
5d7e795
Let TypeImpl methods hold a Location
asterite Feb 7, 2025
b9102ef
Let Expression::new take a Location
asterite Feb 7, 2025
2ba8bb5
with_span -> with_location
asterite Feb 7, 2025
a33dd71
Let BinaryOp be Located
asterite Feb 7, 2025
f79c40c
Let ResolvedGeneric hold a Location
asterite Feb 7, 2025
715a111
Let Ident::new take a Location
asterite Feb 7, 2025
cebd379
Handle a TODO
asterite Feb 7, 2025
28cdd21
Handle a couple of TODOs
asterite Feb 7, 2025
f7ab1da
One more TODO
asterite Feb 7, 2025
4dc9bbe
Let MetaAttribute hold a Location
asterite Feb 7, 2025
ac333bc
Handle more TODOs
asterite Feb 7, 2025
015a21e
One final TODO
asterite Feb 7, 2025
5b83df0
Let Location::dummy() use Span::default()
asterite Feb 7, 2025
fc9300f
Merge branch 'master' into ab/macro-error-location
asterite Feb 7, 2025
01cd5c2
Require `push_err` to take a file
asterite Feb 8, 2025
2fa6f8a
No need to pass file in collect_struct
asterite Feb 8, 2025
1a19623
Fix unused item location
asterite Feb 8, 2025
0a828c3
Don't need FileId in collect_function
asterite Feb 8, 2025
1e8e80f
Let unify take a file
asterite Feb 8, 2025
fc8f820
One more case
asterite Feb 8, 2025
7c4a329
Avoid using Elaborator's file
asterite Feb 8, 2025
2e2833a
Fix a TODO
asterite Feb 8, 2025
9970614
Avoid Elaborator's file in a few more places
asterite Feb 8, 2025
2dabfee
Let interpolation fragment hold a FileId
asterite Feb 8, 2025
38098e2
Require file in run_lint
asterite Feb 8, 2025
129707e
Fix a TODO
asterite Feb 8, 2025
cab1fa2
It's okay to use the location of a macro call
asterite Feb 8, 2025
e4063f8
Disable cache parsing for now
asterite Feb 8, 2025
356cfee
Reduce a bit the number of lines
asterite Feb 10, 2025
061c35a
Merge branch 'master' into ab/macro-error-location
asterite Feb 10, 2025
e6e728a
Merge branch 'master' into ab/macro-error-location
asterite Feb 11, 2025
3d40294
Replace FileIDs in cached parsed code
asterite Feb 11, 2025
1747510
Show macro parse errors where they happen
asterite Feb 11, 2025
d2d7cb4
Show failure to parse macro where it happens, with a secondary locati…
asterite Feb 11, 2025
464a79f
Fix secondary file in LSP errors
asterite Feb 11, 2025
65e0af7
Let Item also hold a Location
asterite Feb 11, 2025
b85e506
Wrap errors when collecting items after macro runs
asterite Feb 11, 2025
f3573ac
Use `push_err` more
asterite Feb 11, 2025
5739cd9
Wrap pushing multiple errors into an Elaborator
asterite Feb 11, 2025
247c757
Keep track of elaborate reasons
asterite Feb 11, 2025
30657d3
Fix tests
asterite Feb 11, 2025
c693a65
Don't say "error" because it could be a warning
asterite Feb 11, 2025
571d9e6
Simpler code so it's clearer when we are wrapping errors in MacroError
asterite Feb 12, 2025
a99bc95
MacroError -> ComptimeError
asterite Feb 12, 2025
1651ff3
Merge branch 'master' into ab/macro-error-location
asterite Feb 18, 2025
2c4f63f
Merge branch 'master' into ab/macro-error-location
asterite Feb 19, 2025
358bc1f
Merge branch 'master' into ab/macro-error-location
asterite Feb 19, 2025
0693c71
Merge branch 'master' into ab/macro-error-location
asterite Feb 20, 2025
e27c612
Fix typo
asterite Feb 20, 2025
a0133b8
Clarify comment
asterite Feb 20, 2025
9815430
Fix TODO
asterite Feb 20, 2025
e35797e
Rename method
asterite Feb 20, 2025
1fef217
Let FmtStrFragment::Interpolation carry a Location
asterite Feb 20, 2025
a0cdfa2
clippy
asterite Feb 20, 2025
6159701
to_span/to_location -> span/location
asterite Feb 20, 2025
26e1784
Update compiler/noirc_errors/src/position.rs
asterite Feb 20, 2025
236b173
Remove unneeded `const` from `fn`
asterite Feb 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 96 additions & 124 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiler/noirc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
pub mod debug_info;
mod position;
pub mod reporter;
pub use position::{Location, Position, Span, Spanned};
pub use position::{Located, Location, Position, Span, Spanned};
pub use reporter::{CustomDiagnostic, DiagnosticKind};

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
85 changes: 79 additions & 6 deletions compiler/noirc_errors/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,68 @@ use codespan::Span as ByteSpan;
use fm::FileId;
use serde::{Deserialize, Serialize};
use std::{
cmp::Ordering,
hash::{Hash, Hasher},
ops::Range,
};

pub type Position = u32;

#[derive(Eq, Debug, Clone)]
pub struct Located<T> {
pub contents: T,
location: Location,
}

/// This is important for tests. Two Located objects are equal if their content is equal
/// They may not have the same location. Use `.location()` to test for Location being equal specifically
impl<T: PartialEq> PartialEq<Located<T>> for Located<T> {
fn eq(&self, other: &Located<T>) -> bool {
self.contents == other.contents
}
}

impl<T: PartialOrd> PartialOrd<Located<T>> for Located<T> {
fn partial_cmp(&self, other: &Located<T>) -> Option<Ordering> {
self.contents.partial_cmp(&other.contents)
}
}

impl<T: Ord> Ord for Located<T> {
fn cmp(&self, other: &Located<T>) -> Ordering {
self.contents.cmp(&other.contents)
}
}

impl<T: Default> Default for Located<T> {
fn default() -> Self {
Self { contents: Default::default(), location: Location::dummy() }
}
}

/// Hash-based data structures (HashMap, HashSet) rely on the inverse of Hash
/// being injective, i.e. x.eq(y) => hash(x, H) == hash(y, H), we hence align
/// this with the above
impl<T: Hash> Hash for Located<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.contents.hash(state);
}
}

impl<T> Located<T> {
pub fn from(location: Location, contents: T) -> Located<T> {
Located { location, contents }
}

pub fn span(&self) -> Span {
self.location.span
}

pub fn location(&self) -> Location {
self.location
}
}

#[derive(PartialOrd, Eq, Ord, Debug, Clone, Default)]
pub struct Spanned<T> {
pub contents: T,
Expand Down Expand Up @@ -36,17 +92,13 @@ impl<T> Spanned<T> {
Spanned { span: Span::inclusive(start, end), contents }
}

pub const fn from(t_span: Span, contents: T) -> Spanned<T> {
pub fn from(t_span: Span, contents: T) -> Spanned<T> {
Spanned { span: t_span, contents }
}

pub fn span(&self) -> Span {
self.span
}

pub fn set_span(&mut self, span: Span) {
self.span = span;
}
}

impl<T> std::borrow::Borrow<T> for Spanned<T> {
Expand Down Expand Up @@ -135,12 +187,33 @@ impl Location {
}

pub fn dummy() -> Self {
Self { span: Span::single_char(0), file: FileId::dummy() }
Self { span: Span::default(), file: FileId::dummy() }
}

pub fn contains(&self, other: &Location) -> bool {
self.file == other.file && self.span.contains(&other.span)
}

#[must_use]
pub fn merge(self, other: Location) -> Location {
if self.file == other.file {
Location::new(self.span.merge(other.span), self.file)
} else {
self
}
}
}

impl Ord for Location {
fn cmp(&self, other: &Self) -> Ordering {
(self.file, self.span).cmp(&(other.file, other.span))
}
}

impl PartialOrd for Location {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[cfg(test)]
Expand Down
25 changes: 11 additions & 14 deletions compiler/noirc_evaluator/src/ssa/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ impl<'a> Parser<'a> {
}

fn eat_identifier(&mut self) -> ParseResult<Option<Identifier>> {
let span = self.token.to_span();
let span = self.token.span();
if let Some(name) = self.eat_ident()? {
Ok(Some(Identifier::new(name, span)))
} else {
Expand Down Expand Up @@ -960,72 +960,69 @@ impl<'a> Parser<'a> {
fn expected_instruction_or_terminator<T>(&mut self) -> ParseResult<T> {
Err(ParserError::ExpectedInstructionOrTerminator {
found: self.token.token().clone(),
span: self.token.to_span(),
span: self.token.span(),
})
}

fn expected_string_or_data<T>(&mut self) -> ParseResult<T> {
Err(ParserError::ExpectedStringOrData {
found: self.token.token().clone(),
span: self.token.to_span(),
span: self.token.span(),
})
}

fn expected_byte_string<T>(&mut self) -> ParseResult<T> {
Err(ParserError::ExpectedByteString {
found: self.token.token().clone(),
span: self.token.to_span(),
span: self.token.span(),
})
}

fn expected_identifier<T>(&mut self) -> ParseResult<T> {
Err(ParserError::ExpectedIdentifier {
found: self.token.token().clone(),
span: self.token.to_span(),
span: self.token.span(),
})
}

fn expected_int<T>(&mut self) -> ParseResult<T> {
Err(ParserError::ExpectedInt {
found: self.token.token().clone(),
span: self.token.to_span(),
})
Err(ParserError::ExpectedInt { found: self.token.token().clone(), span: self.token.span() })
}

fn expected_type<T>(&mut self) -> ParseResult<T> {
Err(ParserError::ExpectedType {
found: self.token.token().clone(),
span: self.token.to_span(),
span: self.token.span(),
})
}

fn expected_value<T>(&mut self) -> ParseResult<T> {
Err(ParserError::ExpectedValue {
found: self.token.token().clone(),
span: self.token.to_span(),
span: self.token.span(),
})
}

fn expected_global_value<T>(&mut self) -> ParseResult<T> {
Err(ParserError::ExpectedGlobalValue {
found: self.token.token().clone(),
span: self.token.to_span(),
span: self.token.span(),
})
}

fn expected_token<T>(&mut self, token: Token) -> ParseResult<T> {
Err(ParserError::ExpectedToken {
token,
found: self.token.token().clone(),
span: self.token.to_span(),
span: self.token.span(),
})
}

fn expected_one_of_tokens<T>(&mut self, tokens: &[Token]) -> ParseResult<T> {
Err(ParserError::ExpectedOneOfTokens {
tokens: tokens.to_vec(),
found: self.token.token().clone(),
span: self.token.to_span(),
span: self.token.span(),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/parser/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl SpannedToken {
SpannedToken(Spanned::from(span, token))
}

pub(crate) fn to_span(&self) -> Span {
pub(crate) fn span(&self) -> Span {
self.0.span()
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<'a> FunctionContext<'a> {
let value = value.replace('{', "{{").replace('}', "}}");
string.push_str(&value);
}
FmtStrFragment::Interpolation(value, _span) => {
FmtStrFragment::Interpolation(value, _) => {
string.push('{');
string.push_str(value);
string.push('}');
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/ast/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::ast::{Ident, UnresolvedGenerics, UnresolvedType};
use crate::token::SecondaryAttribute;

use iter_extended::vecmap;
use noirc_errors::Span;
use noirc_errors::Location;

use super::{Documented, ItemVisibility};

Expand All @@ -16,7 +16,7 @@ pub struct NoirEnumeration {
pub visibility: ItemVisibility,
pub generics: UnresolvedGenerics,
pub variants: Vec<Documented<EnumVariant>>,
pub span: Span,
pub location: Location,
}

impl NoirEnumeration {
Expand Down
Loading
Loading