Skip to content

Commit 3cc9f84

Browse files
committed
add miette errors
1 parent c1414e6 commit 3cc9f84

Some content is hidden

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

48 files changed

+1623
-705
lines changed

Cargo.toml

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,28 @@
11
[package]
22
name = "descend"
3-
version = "0.1.0"
4-
authors = [
5-
"Luca Carlig <luca.carlig@huawei.com>",
6-
"Köpcke <bastian.koepcke@uni-muenster.de>",
7-
]
8-
edition = "2021"
9-
10-
# Allow specific lints globally
11-
[package.metadata.clippy]
12-
unused_variables = "allow"
13-
dead_code = "allow"
14-
unused_imports = "allow"
15-
unreachable_code = "allow"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
166

177
[dependencies]
18-
clap = { version = "4.5", features = ["derive"] }
19-
insta = "1.43.2"
20-
melior = { version = "0.25", features = ["ods-dialects"] }
21-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
22-
23-
[dependencies.peg]
24-
version = "0.8.0"
25-
26-
[dependencies.annotate-snippets]
27-
version = "0.9.0"
28-
features = ["color"]
29-
30-
[dependencies.descend_derive]
31-
path = "./descend_derive"
32-
33-
[build-dependencies]
8+
clap = { version = "4.5.50", features = ["derive"] }
349
melior = { version = "0.25", features = ["ods-dialects"] }
10+
miette = { version = "7.6.0", features = ["fancy", "syntect-highlighter"] }
11+
thiserror = "2.0.17"
12+
peg = "0.8.5"
13+
descend_derive = { path = "./descend_derive" }
3514

3615
[dev-dependencies]
3716
insta = { version = "1.43.2", features = ["glob"] }
3817

3918
[workspace]
4019
members = ["descend_derive"]
20+
resolver = "3"
21+
22+
[workspace.package]
23+
version = "0.1.0"
24+
authors = [
25+
"Luca Carlig <luca.carlig@huawei.com>",
26+
"Köpcke <bastian.koepcke@uni-muenster.de>",
27+
]
28+
edition = "2024"

descend_derive/Cargo.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
[package]
22
name = "descend_derive"
3-
version = "0.1.0"
4-
authors = ["Köpcke <bastian.koepcke@wwu.de>"]
5-
edition = "2018"
6-
7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
86

97
[lib]
108
proc-macro = true
119

1210
[build-dependencies]
1311

1412
[dependencies]
15-
syn = { version = "1.0", features = ["full"] }
16-
quote = "1.0"
17-
proc-macro2 = "1.0"
18-
include_dir = "0.7"
13+
syn = { version = "2.0.108", features = ["full"] }
14+
quote = "1.0.41"
15+
proc-macro2 = "1.0.103"
16+
include_dir = "0.7.4"

descend_derive/src/lib.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::collections::HashSet;
33
use proc_macro::TokenStream;
44
use quote::quote;
55
use syn::{
6+
Fields, FieldsNamed, Ident, ItemStruct, Token, Type, TypeReference,
67
parse::{Parse, ParseStream},
78
parse_macro_input,
89
punctuated::Punctuated,
9-
Fields, FieldsNamed, Ident, ItemStruct, Token, Type, TypeReference,
1010
};
1111

1212
// Copy paste from syn example
@@ -46,7 +46,7 @@ pub fn span_derive(attr: TokenStream, input: TokenStream) -> TokenStream {
4646
std::mem::swap(&mut tmp, &mut field.attrs);
4747
tmp = tmp
4848
.into_iter()
49-
.filter(|attr| !attr.path.is_ident(IGNORE_ATTR_NAME))
49+
.filter(|attr| !attr.path().is_ident(IGNORE_ATTR_NAME))
5050
.collect::<Vec<_>>();
5151
std::mem::swap(&mut tmp, &mut field.attrs);
5252
}
@@ -64,7 +64,7 @@ pub fn span_derive(attr: TokenStream, input: TokenStream) -> TokenStream {
6464
for mut field in original_fields.named.clone().into_iter() {
6565
let mut ignored = false;
6666
for attr in field.attrs.iter() {
67-
if attr.path.is_ident(IGNORE_ATTR_NAME) {
67+
if attr.path().is_ident(IGNORE_ATTR_NAME) {
6868
ignored = true;
6969
break;
7070
}
@@ -170,8 +170,13 @@ pub fn generate_desc_tests(input: TokenStream) -> TokenStream {
170170
// Since include_dir! doesn't support dynamic paths, we need to handle specific folders
171171
let dir = match folder_path {
172172
"examples/core" => include_dir::include_dir!("$CARGO_MANIFEST_DIR/../examples/core"),
173-
"examples/error-examples" => include_dir::include_dir!("$CARGO_MANIFEST_DIR/../examples/error-examples"),
174-
_ => panic!("Unsupported folder path: {}. Currently supported: examples/core, examples/error-examples", folder_path),
173+
"examples/error-examples" => {
174+
include_dir::include_dir!("$CARGO_MANIFEST_DIR/../examples/error-examples")
175+
}
176+
_ => panic!(
177+
"Unsupported folder path: {}. Currently supported: examples/core, examples/error-examples",
178+
folder_path
179+
),
175180
};
176181

177182
let mut test_functions = Vec::new();
@@ -236,7 +241,7 @@ pub fn generate_desc_tests(input: TokenStream) -> TokenStream {
236241
} else {
237242
test_functions.push(quote! {
238243
#[test]
239-
fn #test_name_ident() -> Result<(), descend::error::ErrorReported> {
244+
fn #test_name_ident() -> Result<(), descend::error::CompileError> {
240245
let output = descend::compile(#file_path_lit)?.0;
241246
insta::assert_snapshot!(output);
242247
Ok(())
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file intentionally contains invalid syntax to trigger a FileIOError
2+
// when the compiler tries to read it. This demonstrates how FileIOError
3+
// is used when files cannot be read due to I/O issues.
4+
5+
fn main() -[t: cpu.thread]-> () <'a> {
6+
// This is intentionally malformed syntax
7+
let x =
8+
// Missing semicolon and incomplete expression
9+
return 42
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn missing_main() -[t: cpu.thread]-> () <'a> {
2+
()
3+
}

src/ast/span.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@ impl Span {
1919
}
2020
}
2121
}
22+
23+
impl From<Span> for miette::SourceSpan {
24+
fn from(span: Span) -> Self {
25+
miette::SourceSpan::new(
26+
miette::SourceOffset::from(span.begin as usize),
27+
(span.end - span.begin) as usize
28+
)
29+
}
30+
}

src/codegen/mlir/builder/mod.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
//! MLIR Builder Module
2-
//!
3-
//! This module provides the core MLIR code generation functionality, including
4-
//! the main `MlirBuilder` struct and methods for building MLIR modules, functions,
5-
//! and expressions from Descend AST nodes.
6-
//!
7-
//! # Architecture
8-
//!
9-
//! The builder uses a two-pass compilation strategy:
10-
//! 1. **Pass 1**: Declare all functions and record their result types
11-
//! 2. **Pass 2**: Build function bodies with access to callee result types
12-
//!
13-
//! This approach ensures that function calls can reference the correct result types
14-
//! of their callees, enabling proper MLIR generation.
15-
//!
16-
//! # Key Components
17-
//!
18-
//! - `MlirBuilder`: Main builder struct that manages MLIR module construction
19-
//! - `MlirContext`: Context for managing variables and current block during codegen
20-
//! - Function building: Converts Descend function definitions to MLIR functions
21-
//! - Expression building: Handles various expression types (literals, operations, control flow)
22-
//!
23-
//! # Usage
24-
//!
25-
//! ```rust,no_run
26-
//! use descend::codegen::mlir::builder::MlirBuilder;
27-
//! use melior::{Context, ir::{Module, Location}};
28-
//!
29-
//! let context = Context::new();
30-
//! let module = Module::new(Location::unknown(&context));
31-
//! let mut builder = MlirBuilder::new(&context, module);
32-
//!
33-
//! // Build compilation unit (requires proper comp_unit)
34-
//! // builder.build_items_two_pass(&comp_unit);
35-
//! ```
36-
371
pub mod context;
382
pub mod control_flow;
393
pub mod expr;
@@ -44,9 +8,9 @@ pub mod ops;
448
pub mod place;
459

4610
use melior::{
47-
dialect::func,
48-
ir::{operation::OperationLike, Block, BlockLike, Location, Module, RegionLike},
4911
Context,
12+
dialect::func,
13+
ir::{Block, BlockLike, Location, Module, RegionLike, operation::OperationLike},
5014
};
5115

5216
use super::to_mlir::ToMlir;

src/codegen/mlir/error.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
//! MLIR Codegen Error Handling
2-
//!
3-
//! This module provides comprehensive error handling for the MLIR codegen backend.
4-
//! It defines custom error types that capture different failure modes during
5-
//! MLIR code generation, providing detailed error information for debugging.
6-
//!
7-
//! # Error Types
8-
//!
9-
//! - `General`: For general MLIR codegen errors with custom messages
10-
//! - `TypeParseError`: For MLIR type parsing failures
11-
//! - `OperationBuildError`: For MLIR operation construction failures
12-
//! - `MissingResult`: For operations that fail to produce expected results
13-
//! - `InvalidOperation`: For operations that are malformed or invalid
14-
//! - `ContextError`: For context-related errors during codegen
15-
//!
16-
//! # Usage
17-
//!
18-
//! ```rust
19-
//! use descend::codegen::mlir::error::{MlirError, type_parse_error};
20-
//!
21-
//! // Create specific error types
22-
//! let err = type_parse_error("invalid_type");
23-
//!
24-
//! // Convert to string for display
25-
//! println!("Error: {}", err);
26-
//! ```
27-
281
use std::fmt;
292

303
/// Errors that can occur during MLIR code generation

0 commit comments

Comments
 (0)