Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use compiler base session in resolver and remove un-used code in the kclvm error crate. #442

Merged
merged 4 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions kclvm/ast_pretty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ indexmap = "1.0"
fancy-regex = "0.7.1"
pretty_assertions = "1.3.0"
compiler_base_session = {path = "../../compiler_base/session", version = "0.0.12"}
compiler_base_macros = "0.0.1"
2 changes: 1 addition & 1 deletion kclvm/ast_pretty/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::collections::HashSet;

use compiler_base_macros::bug;
use kclvm_ast::{
ast::{self, CallExpr},
token::{DelimToken, TokenKind},
walker::MutSelfTypedResultWalker,
};
use kclvm_error::bug;

use super::{Indentation, Printer};

Expand Down
4 changes: 2 additions & 2 deletions kclvm/capi/src/service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl KclvmService {
let kcl_paths_str = kcl_paths.iter().map(|s| s.as_str()).collect::<Vec<&str>>();
let mut result = ExecProgram_Result::default();
let sess = Arc::new(Session::default());
let mut program = load_program(sess, &kcl_paths_str.as_slice(), Some(opts))?;
let mut program = load_program(sess.clone(), &kcl_paths_str.as_slice(), Some(opts))?;

if let Err(err) = apply_overrides(
&mut program,
Expand All @@ -105,7 +105,7 @@ impl KclvmService {
}

let start_time = SystemTime::now();
let exec_result = kclvm_runner::execute(program, self.plugin_agent, &native_args);
let exec_result = kclvm_runner::execute(sess, program, self.plugin_agent, &native_args);
let escape_time = match SystemTime::now().duration_since(start_time) {
Ok(dur) => dur.as_secs_f32(),
Err(err) => return Err(err.to_string()),
Expand Down
2 changes: 1 addition & 1 deletion kclvm/cmd/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn lint_command(matches: &ArgMatches) -> Result<()> {
(err_handler.diagnostics, warning_handler.diagnostics) =
lint_files(&files, Some(args.get_load_program_options()));
if matches.occurrences_of("emit_warning") > 0 {
warning_handler.emit();
warning_handler.emit()?;
}
err_handler.abort_if_any_errors();
Ok(())
Expand Down
5 changes: 2 additions & 3 deletions kclvm/compiler/src/codegen/llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1750,10 +1750,9 @@ impl<'ctx> LLVMCodeGenContext<'ctx> {
column: None,
},
);
handler.abort_if_errors()
} else {
result
handler.abort_if_any_errors()
}
result
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions kclvm/error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ edition = "2021"
compiler_base_span = {path = "../../compiler_base/span", version = "0.0.2"}
compiler_base_session = {path = "../../compiler_base/session", version = "0.0.12"}
compiler_base_error = "0.0.8"
compiler_base_macros = "0.0.1"
kclvm-span = {path = "../span", version = "0.4.5"}
kclvm-runtime = {path = "../runtime", version = "0.4.5"}

anyhow = "1.0"
tracing = "0.1"
atty = "0.2"
termcolor = "1.0"
annotate-snippets = "0.8.0"
annotate-snippets = { version = "0.9.0", default-features = false, features = ["color"] }
termize = "0.1.1"
indexmap = "1.0"
48 changes: 0 additions & 48 deletions kclvm/error/src/bug.rs

This file was deleted.

42 changes: 3 additions & 39 deletions kclvm/error/src/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use kclvm_span::Loc;
use std::fmt;
use std::hash::Hash;

use indexmap::IndexSet;
use kclvm_span::Loc;
use termcolor::{Color, ColorSpec};

use crate::{ErrorKind, WarningKind};

/// Diagnostic structure.
Expand All @@ -19,7 +16,7 @@ pub struct Diagnostic {
/// line, and column location.
///
/// A Position is valid if the line number is > 0.
/// The line and column are both 1 based.
/// The line is 1-based and the column is 0-based.
#[derive(PartialEq, Clone, Eq, Hash, Debug, Default)]
pub struct Position {
pub filename: String,
Expand Down Expand Up @@ -89,7 +86,7 @@ impl From<Loc> for Position {
line: loc.line as u64,
column: if loc.col_display > 0 {
// Loc col is the (0-based) column offset.
Some(loc.col.0 as u64 + 1)
Some(loc.col.0 as u64)
} else {
None
},
Expand Down Expand Up @@ -156,22 +153,6 @@ impl Level {
Level::Note => "note",
}
}

pub fn color(&self) -> ColorSpec {
let mut spec = ColorSpec::new();
match self {
Level::Error => {
spec.set_fg(Some(Color::Red)).set_intense(true);
}
Level::Warning => {
spec.set_fg(Some(Color::Yellow)).set_intense(cfg!(windows));
}
Level::Note => {
spec.set_fg(Some(Color::Green)).set_intense(true);
}
}
spec
}
}

impl fmt::Display for Level {
Expand All @@ -189,20 +170,3 @@ pub enum Style {
LineAndColumn,
Line,
}

/// Classify diagnostics into errors and warnings.
pub fn classification(
diagnostics: &IndexSet<Diagnostic>,
) -> (IndexSet<Diagnostic>, IndexSet<Diagnostic>) {
let (mut errs, mut warnings) = (IndexSet::new(), IndexSet::new());
for diag in diagnostics {
if diag.level == Level::Error {
errs.insert(diag.clone());
} else if diag.level == Level::Warning {
warnings.insert(diag.clone());
} else {
continue;
}
}
(errs, warnings)
}