Skip to content

Commit 740acea

Browse files
committed
Use ErasedReportedError pervasively
1 parent 1e18f14 commit 740acea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+649
-856
lines changed

Cargo.lock

+10-46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/ast/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ publish = false
88
[dependencies]
99
colored = "2.0.0"
1010
diagnostics = { path = "../diagnostics" }
11-
error = { path = "../error" }
1211
index_map = { path = "../../project/library/index_map" }
13-
item = { path = "../item" }
14-
joinery = "2.1.0"
12+
joinery = "3.1.0"
1513
smallvec = { version = "1.8.0", features = ["const_generics"] }
1614
span = { path = "../span" }
1715
token = { path = "../token" }

compiler/ast/src/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl Format for super::BareExpression {
366366
Self::CaseAnalysis(analysis) => analysis.format(f, indentation),
367367
Self::DoBlock(do_) => do_.format(f, indentation),
368368
Self::SequenceLiteral(sequence) => sequence.format(f, indentation),
369-
Self::Error => write!(f, "{}", "invalid".color(color_palette::INVALID)),
369+
Self::Error(_) => write!(f, "{}", "invalid".color(color_palette::INVALID)),
370370
}
371371
}
372372
}

compiler/ast/src/lib.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! The abstract syntax tree (AST).
22
//!
33
//! The most important definitions are [`Declaration`], [`Expression`] and [`Pattern`].
4-
#![feature(default_free_fn)]
4+
#![feature(default_free_fn, let_chains)]
55

6-
use diagnostics::{Diagnostic, ErrorCode};
7-
use error::PossiblyErroneous;
6+
use diagnostics::{error::PossiblyErroneous, reporter::ErasedReportedError};
87
pub use format::{Debug, Format};
98
use smallvec::smallvec;
109
use span::{PossiblySpanning, SourceFileIndex, Span, Spanned, Spanning};
@@ -14,7 +13,7 @@ use utilities::{obtain, Atom, SmallVec};
1413

1514
mod format;
1615

17-
pub type Item<Bare> = item::Item<Bare, Attributes>;
16+
pub type Item<Bare> = span::item::Item<Bare, Attributes>;
1817

1918
pub type Declaration = Item<BareDeclaration>;
2019

@@ -194,12 +193,12 @@ pub enum BareExpression {
194193
CaseAnalysis(Box<CaseAnalysis>),
195194
DoBlock(Box<DoBlock>),
196195
SequenceLiteral(Box<SequenceLiteral<Expression>>),
197-
Error,
196+
Error(ErasedReportedError),
198197
}
199198

200199
impl PossiblyErroneous for BareExpression {
201-
fn error() -> Self {
202-
Self::Error
200+
fn error(error: ErasedReportedError) -> Self {
201+
Self::Error(error)
203202
}
204203
}
205204

@@ -481,16 +480,9 @@ impl Path {
481480
}
482481
}
483482

484-
// @Task make this Option<Self> and move diagnostic construction into lowerer
485-
pub fn join(mut self, other: Self) -> Result<Self, Diagnostic> {
486-
if let Some(hanger) = other.hanger {
487-
if !matches!(hanger.bare, BareHanger::Self_) {
488-
return Err(Diagnostic::error()
489-
.code(ErrorCode::E026)
490-
.message(format!("path ‘{hanger}’ not allowed in this position"))
491-
.primary_span(hanger)
492-
.help("consider moving this path to a separate use-declaration"));
493-
}
483+
pub fn join(mut self, other: Self) -> Result<Self, Hanger> {
484+
if let Some(hanger) = other.hanger && !matches!(hanger.bare, BareHanger::Self_) {
485+
return Err(hanger);
494486
}
495487
self.segments.extend(other.segments);
496488
Ok(self)

compiler/codegen_cranelift/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ cranelift-module = "0.85.1"
1111
cranelift-native = "0.85.1"
1212
cranelift-object = "0.85.1"
1313
diagnostics = { path = "../diagnostics" }
14-
error = { path = "../error" }
1514
hir = { path = "../hir" }
1615
session = { path = "../session" }

compiler/codegen_cranelift/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use cranelift::{
99
};
1010
use cranelift_module::{Linkage, Module};
1111
use cranelift_object::{ObjectBuilder, ObjectModule};
12-
use diagnostics::Diagnostic;
13-
use error::Result;
12+
use diagnostics::{error::Result, Diagnostic};
1413
use session::{BuildSession, Component};
1514
use std::{
1615
path::{Path, PathBuf},

compiler/codegen_llvm/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ publish = false
77

88
[dependencies]
99
diagnostics = { path = "../diagnostics" }
10-
error = { path = "../error" }
1110
hir = { path = "../hir" }
1211
hir_format = { path = "../hir_format" }
1312
resolver = { path = "../resolver" }

compiler/codegen_llvm/src/lib.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#![feature(default_free_fn, let_chains, io_error_other)]
33
#![allow(clippy::match_same_arms)] // @Temporary
44

5-
use diagnostics::Diagnostic;
6-
use error::Result;
5+
use diagnostics::{error::Result, Diagnostic};
76
use hir::DeclarationIndex;
87
use hir_format::ComponentExt;
98
use inkwell::{
@@ -326,7 +325,7 @@ impl<'a, 'ctx> Generator<'a, 'ctx> {
326325
}
327326
Use(_) => {}
328327
// @Question how should we handle that?
329-
Error => todo!(),
328+
Error(_) => todo!(),
330329
};
331330
}
332331

@@ -383,7 +382,7 @@ impl<'a, 'ctx> Generator<'a, 'ctx> {
383382
}
384383
Use(_) => {}
385384
// @Question how should we handle that?
386-
Error => todo!(),
385+
Error(_) => todo!(),
387386
};
388387
}
389388

@@ -413,7 +412,7 @@ impl<'a, 'ctx> Generator<'a, 'ctx> {
413412
}
414413
Substituted(_) => todo!(),
415414
IO(_) => todo!(),
416-
Error => todo!(),
415+
Error(_) => todo!(),
417416
}
418417
}
419418

@@ -490,7 +489,7 @@ impl<'a, 'ctx> Generator<'a, 'ctx> {
490489
IntrinsicApplication(_) => todo!("compiling intrinsic applications"),
491490
Projection(_) => todo!("compiling record projections"),
492491
IO(_) => todo!("compiling IO actions"),
493-
Substituted(_) | Error => unreachable!(),
492+
Substituted(_) | Error(_) => unreachable!(),
494493
}
495494
}
496495

@@ -551,7 +550,7 @@ impl<'a, 'ctx> Generator<'a, 'ctx> {
551550
Substituted(_) => todo!(),
552551
IntrinsicApplication(_) => todo!(),
553552
Projection(_) => todo!(),
554-
Error => todo!(),
553+
Error(_) => todo!(),
555554
Number(_) | Text(_) | IO(_) => unreachable!(),
556555
}
557556
}
@@ -576,7 +575,7 @@ impl<'a, 'ctx> Generator<'a, 'ctx> {
576575
IntrinsicApplication(_) => todo!(),
577576
Projection(_) => todo!(),
578577
IO(_) => todo!(),
579-
Error => todo!(),
578+
Error(_) => todo!(),
580579
}
581580
}
582581

@@ -620,7 +619,7 @@ impl ExpressionExt for hir::Expression {
620619
Substituted(_) => todo!(),
621620
Projection(_) => todo!(),
622621
IO(_) => todo!(),
623-
Error => todo!(),
622+
Error(_) => todo!(),
624623
}
625624
}
626625
}

0 commit comments

Comments
 (0)