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

Fix parsing bug after refactor: Don't borrow parse state #106

Merged
merged 3 commits into from
Apr 16, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 65 additions & 77 deletions src/build/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn generate_asts(
SourceType::SourceFile(source_file) => {
let root_package = build_state.get_package(&build_state.root_config_name).unwrap();

let (ast_path, iast_path, dirty) = if source_file.implementation.parse_dirty
let (ast_result, iast_result, dirty) = if source_file.implementation.parse_dirty
|| source_file
.interface
.as_ref()
Expand Down Expand Up @@ -80,18 +80,18 @@ pub fn generate_asts(
)
};

(module_name.to_owned(), ast_path, iast_path, dirty)
(module_name.to_owned(), ast_result, iast_result, dirty)
}
}
})
.collect::<Vec<(
String,
Result<(String, Option<String>), String>,
Result<Option<(String, Option<String>)>, String>,
Result<(String, Option<helpers::StdErr>), String>,
Result<Option<(String, Option<helpers::StdErr>)>, String>,
bool,
)>>()
.into_iter()
.for_each(|(module_name, ast_path, iast_path, is_dirty)| {
.for_each(|(module_name, ast_result, iast_result, is_dirty)| {
if let Some(module) = build_state.modules.get_mut(&module_name) {
// if the module is dirty, mark it also compile_dirty
// do NOT set to false if the module is not parse_dirty, it needs to keep
Expand All @@ -103,89 +103,77 @@ pub fn generate_asts(
.packages
.get(&module.package_name)
.expect("Package not found");
if is_dirty {
rolandpeelen marked this conversation as resolved.
Show resolved Hide resolved
module.compile_dirty = true
}
match ast_path {
Ok((_path, err)) => {
match module.source_type {
SourceType::SourceFile(ref mut source_file) => {
source_file.implementation.parse_dirty = false;
source_file
.interface
.as_mut()
.map(|interface| interface.parse_dirty = false);
if let SourceType::SourceFile(ref mut source_file) = module.source_type {
// We get Err(x) when there is a parse error. When it's Ok(_, Some(
// stderr_warnings )), the outputs are warnings
match ast_result {
// In case of a pinned (internal) dependency, we want to keep on
// propagating the warning with every compile. So we mark it as dirty for
// the next round
Ok((_path, Some(stderr_warnings))) if package.is_pinned_dep => {
source_file.implementation.parse_state = ParseState::Warning;
source_file.implementation.parse_dirty = true;
if let Some(interface) = source_file.interface.as_mut() {
interface.parse_dirty = false;
}
_ => (),
logs::append(package, &stderr_warnings);
stderr.push_str(&stderr_warnings);
}
// supress warnings in non-pinned deps
match module.source_type {
SourceType::SourceFile(ref mut source_file) => {
source_file.implementation.parse_state = ParseState::Success;
Ok((_path, Some(_))) | Ok((_path, None)) => {
// If we do have stderr_warnings here, the file is not a pinned
// dependency (so some external dep). We can ignore those
source_file.implementation.parse_state = ParseState::Success;
source_file.implementation.parse_dirty = false;
if let Some(interface) = source_file.interface.as_mut() {
interface.parse_dirty = false;
}
_ => (),
}
Err(err) => {
// Some compilation error
source_file.implementation.parse_state = ParseState::ParseError;
source_file.implementation.parse_dirty = true;
logs::append(package, &err);
has_failure = true;
stderr.push_str(&err);
}
};

if package.is_pinned_dep {
if let Some(err) = err {
match module.source_type {
SourceType::SourceFile(ref mut source_file) => {
source_file.implementation.parse_state = ParseState::Warning;
source_file.implementation.parse_dirty = true;
}
_ => (),
}
logs::append(package, &err);
stderr.push_str(&err);
// We get Err(x) when there is a parse error. When it's Ok(_, Some(( _path,
// stderr_warnings ))), the outputs are warnings
match iast_result {
// In case of a pinned (internal) dependency, we want to keep on
// propagating the warning with every compile. So we mark it as dirty for
// the next round
Ok(Some((_path, Some(stderr_warnings)))) if package.is_pinned_dep => {
if let Some(interface) = source_file.interface.as_mut() {
interface.parse_state = ParseState::Warning;
interface.parse_dirty = true;
}
logs::append(package, &stderr_warnings);
stderr.push_str(&stderr_warnings);
}
}
Err(err) => {
match module.source_type {
SourceType::SourceFile(ref mut source_file) => {
source_file.implementation.parse_state = ParseState::ParseError;
source_file.implementation.parse_dirty = true;
Ok(Some((_, None))) | Ok(Some((_, Some(_)))) => {
// If we do have stderr_warnings here, the file is not a pinned
// dependency (so some external dep). We can ignore those
if let Some(interface) = source_file.interface.as_mut() {
interface.parse_state = ParseState::Success;
interface.parse_dirty = false;
}
_ => (),
}
logs::append(package, &err);
has_failure = true;
stderr.push_str(&err);
}
};
match iast_path {
Ok(Some((_path, err))) => {
// supress warnings in non-pinned deps
if package.is_pinned_dep {
if let Some(err) = err {
match module.source_type {
SourceType::SourceFile(ref mut source_file) => {
source_file.interface.as_mut().map(|interface| {
interface.parse_state = ParseState::ParseError;
interface.parse_dirty = true;
});
}
_ => (),
}
logs::append(package, &err);
stderr.push_str(&err);
Err(err) => {
// Some compilation error
if let Some(interface) = source_file.interface.as_mut() {
interface.parse_state = ParseState::ParseError;
interface.parse_dirty = true;
}
logs::append(package, &err);
has_failure = true;
stderr.push_str(&err);
}
}
Ok(None) => (),
Err(err) => {
match module.source_type {
SourceType::SourceFile(ref mut source_file) => {
source_file.interface.as_mut().map(|interface| {
interface.parse_state = ParseState::ParseError;
interface.parse_dirty = true;
});
}
_ => (),
Ok(None) => {
// The file had no interface file associated
()
}
logs::append(package, &err);
has_failure = true;
stderr.push_str(&err);
}
};
}
Expand Down Expand Up @@ -295,7 +283,7 @@ fn generate_ast(
version: &str,
bsc_path: &str,
workspace_root: &Option<String>,
) -> Result<(String, Option<String>), String> {
) -> Result<(String, Option<helpers::StdErr>), String> {
let file_path = PathBuf::from(&package.path).join(filename);
let contents = helpers::read_file(&file_path).expect("Error reading file");

Expand Down
2 changes: 2 additions & 0 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::path::{Component, Path, PathBuf};
use std::process::Command;
use std::time::{SystemTime, UNIX_EPOCH};

pub type StdErr = String;

pub mod emojis {
use console::Emoji;
pub static COMMAND: Emoji<'_, '_> = Emoji("🏃 ", "");
Expand Down
Loading