Skip to content

Commit 3d45d67

Browse files
authored
Merge pull request #1084 from hash-org/parsing-ty-args
2 parents bcf736e + 68b5514 commit 3d45d67

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

compiler/hash-ast/src/ast.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,15 @@ static SPAN_MAP: Lazy<RwLock<Vec<Span>>> = Lazy::new(|| {
8080
/// added to the global [`SPAN_MAP`] later.
8181
///
8282
/// ##Note: This is only used by the parser in order to reduce contention for [`SPAN_MAP`].
83+
#[derive(Default)]
8384
pub struct LocalSpanMap {
8485
map: Vec<(AstNodeId, ByteRange)>,
85-
source: SourceId,
8686
}
8787

8888
impl LocalSpanMap {
89-
/// Create a new [LocalSpanMap].
90-
pub fn new(source: SourceId) -> Self {
91-
Self { map: vec![], source }
92-
}
93-
9489
/// Create a new [LocalSpanMap] with a given capacity.
95-
pub fn with_capacity(source: SourceId, capacity: usize) -> Self {
96-
Self { map: Vec::with_capacity(capacity), source }
90+
pub fn with_capacity(capacity: usize) -> Self {
91+
Self { map: Vec::with_capacity(capacity) }
9792
}
9893

9994
/// Add a new node to the map.
@@ -156,7 +151,7 @@ impl SpanMap {
156151
}
157152

158153
/// Merge a [LocalSpanMap] into the [`SPAN_MAP`].
159-
pub fn add_local_map(local: LocalSpanMap) {
154+
pub fn add_local_map(source: SourceId, local: LocalSpanMap) {
160155
// If no nodes were added, don't do anything!
161156
if local.map.is_empty() {
162157
return;
@@ -173,7 +168,7 @@ impl SpanMap {
173168

174169
// Now we write all of the items into the map.
175170
for (id, range) in local.map {
176-
writer[id.to_usize()] = Span::new(range, local.source);
171+
writer[id.to_usize()] = Span::new(range, source);
177172
}
178173
}
179174
}

compiler/hash-parser/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ impl<Ctx: ParserCtxQuery> CompilerStage<Ctx> for Parser {
111111
let path = SourceMapUtils::map(id, |source| source.path().to_path_buf());
112112
node_map.add_module(id, ModuleEntry::new(path, node));
113113
}
114-
ParserAction::MergeSpans { spans } => scope.spawn(move |_| {
115-
SpanMap::add_local_map(spans);
114+
ParserAction::MergeSpans { source, spans } => scope.spawn(move |_| {
115+
SpanMap::add_local_map(source, spans);
116116
}),
117117
ParserAction::ParseImport { source, sender } => {
118118
// ##Note: import de-duplication is already ensured by the
@@ -172,7 +172,7 @@ pub enum ParserAction {
172172
Error { diagnostics: Vec<Report>, timings: StageMetrics },
173173

174174
/// Update the global `SPAN_MAP` with the specified local span map.
175-
MergeSpans { spans: LocalSpanMap },
175+
MergeSpans { source: SourceId, spans: LocalSpanMap },
176176

177177
/// A worker has completed processing an interactive block and now provides
178178
/// the generated AST.
@@ -266,7 +266,7 @@ fn parse_source(source: ParseSource, sender: Sender<ParserAction>) {
266266
// are encountered whilst parsing this module.
267267
let resolver = ImportResolver::new(id, source.parent(), sender);
268268
let mut diagnostics = ParserDiagnostics::new();
269-
let mut spans = LocalSpanMap::with_capacity(id, tokens.len() * 2);
269+
let mut spans = LocalSpanMap::with_capacity(tokens.len() * 2);
270270
let mut gen = AstGen::new(spanned, &tokens, &resolver, &mut diagnostics, &mut spans);
271271

272272
// Perform the parsing operation now... and send the result through the
@@ -299,6 +299,6 @@ fn parse_source(source: ParseSource, sender: Sender<ParserAction>) {
299299

300300
// Send both the generated module, and the `LocalSpanMap` for updating
301301
// the global `SPAN_MAP`.
302-
sender.send(ParserAction::MergeSpans { spans }).unwrap();
302+
sender.send(ParserAction::MergeSpans { source: id, spans }).unwrap();
303303
sender.send(action).unwrap();
304304
}

compiler/hash-parser/src/parser/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ impl<'s> AstGenFrame<'s> {
108108
let pos = self.previous_pos().end() + 1;
109109
ByteRange::new(pos, pos)
110110
}
111-
112-
/// Check whether the frame has encountered an error.
113-
#[inline(always)]
114-
pub(crate) fn has_error(&self) -> bool {
115-
self.error.get()
116-
}
117111
}
118112

119113
/// The [AstGen] struct it the primary parser for the Hash compiler. It

compiler/hash-parser/src/parser/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Hash Compiler AST generation sources. This file contains the sources to the
22
//! logic that transforms tokens into an AST.
33
use hash_ast::ast::*;
4-
use hash_reporting::diagnostic::HasDiagnosticsMut;
4+
use hash_reporting::diagnostic::{DiagnosticsMut, HasDiagnosticsMut};
55
use hash_source::identifier::IDENTS;
66
use hash_token::{delimiter::Delimiter, keyword::Keyword, Token, TokenKind};
77
use hash_utils::thin_vec::thin_vec;
@@ -331,7 +331,7 @@ impl AstGen<'_> {
331331
// Abort early if we encountered some kind of error along the way,
332332
// although I would think when the `gen` is consumed then we can
333333
// send up all of the errors to the parent generator?
334-
if gen.has_error() {
334+
if gen.diagnostics.has_errors() {
335335
let err = gen.diagnostics.errors.pop().unwrap();
336336
return Err(err);
337337
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run=pass, stage=parse
2+
3+
set := (data: char) -> Result<void, IoError> => {
4+
match (intrinsic_char_set(data) as Result<void, (i32, str)>) {
5+
Err(e) => Err(_conv_ioerr_prim(e)),
6+
Ok(r) => Ok(r)
7+
}
8+
};

0 commit comments

Comments
 (0)