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 and clean the code #109

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c49defb
chore: setting up the base ideas of the refactor and the clean-up
TheRustifyer May 31, 2024
82cef53
feat: Moving towards the owned data processing model
TheRustifyer Jun 1, 2024
3c41152
feat(wip): reworking how the cache store the generated commands, and …
TheRustifyer Jun 6, 2024
6d44a4f
feat(wip): time for the renormalization of the module implementations
TheRustifyer Jun 6, 2024
226099c
feat(wip): saving the job so far
TheRustifyer Jun 7, 2024
aac336b
feat(wip)!: Creational Flyweights to reduce the memory usage footprin…
TheRustifyer Jun 21, 2024
32fcb75
test(wip)!: saving the attributes &str to Cow refactor
TheRustifyer Jun 22, 2024
79e9e37
test: saving the refactor of the cfg and model data structures being …
TheRustifyer Jun 23, 2024
87305b7
Merge branch 'refactor-cfg-and-model-cow-based' into refactor-and-cle…
TheRustifyer Jun 23, 2024
ffd6648
feat(wip): Finished the refactor step of the project model using Cow …
TheRustifyer Jun 23, 2024
f7c928c
feat(system_headers): Avoiding check the fs for system headers to see…
TheRustifyer Jun 24, 2024
48a95ee
fix: missed .with_extension methods on the implementations of Transla…
TheRustifyer Jun 24, 2024
7535b3a
fix: removed unused borrows of the project configuration since its ow…
TheRustifyer Jun 24, 2024
dbadd89
fix: removed unused borrows of the project configuration since its ow…
TheRustifyer Jun 24, 2024
13d36b9
feat(wip): Renormalizing the types of the data that will be sent to t…
TheRustifyer Jun 26, 2024
985c334
feat(wip): Flexible inputs on the commands executor
TheRustifyer Jun 26, 2024
4815b9f
feat(wip): Flexible inputs on the commands executor
TheRustifyer Jun 26, 2024
fb3c748
feat(wip): Working with the interior mutability pattern to see if it'…
TheRustifyer Jun 29, 2024
62ebe6a
chore(wip): Towards the unique generation and generification of the p…
TheRustifyer Jun 29, 2024
118633a
feat: No ReferenceCounted or Interior Mutability patterns are require…
TheRustifyer Jun 30, 2024
8ce930f
feat: Making Clang the first compiler that correctly uses the Flyweig…
TheRustifyer Jun 30, 2024
54f8b56
feat: Applying the latest changes to all the kind of translation unit…
TheRustifyer Jul 1, 2024
5421500
feat: The generated obj files that are added to the linker are append…
TheRustifyer Jul 2, 2024
cacfa51
fix: removing the duplicated std byproducts (obj files) on the linker…
TheRustifyer Jul 3, 2024
ec8bdd3
feat: Introducing the transient crate to allow downcasting the implem…
TheRustifyer Jul 4, 2024
56257d3
feat: Generification of the commands generator for any kind of Transl…
TheRustifyer Jul 5, 2024
215cea7
feat: Avoiding duplicating the linker arguments with an early guard w…
TheRustifyer Jul 8, 2024
6ae32ac
feat: refactor of the core of the procedure for that takes care about…
TheRustifyer Jul 9, 2024
919d1f5
fix: missed function invocations on the benchmarks module
TheRustifyer Jul 10, 2024
683444d
fix: changed the arguments passed to the bencher function on the meas…
TheRustifyer Jul 10, 2024
9994f25
chore: cargo fmt
TheRustifyer Jul 10, 2024
4134274
feat: refactor of the C++ modular std lib procedure
TheRustifyer Jul 12, 2024
27a99bb
feat: Argument has now Cow<str> as the inner type
TheRustifyer Jul 12, 2024
01a73a3
fix: changed again the 'generate_commands' signature without reflecti…
TheRustifyer Jul 12, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
cargo fmt --all -- --check

unit-and-doc-tests:
name: Verify code formatting
name: Run unit and doc tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
89 changes: 89 additions & 0 deletions zork++/Cargo.lock

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

2 changes: 2 additions & 0 deletions zork++/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ path = "src/bin/main.rs"
toml = "0.5.11"
glob = "0.3.1"
serde = { version = "1.0.202", features = ["derive"] }
typetag = "0.2"
transient = "0.4.0"
clap = { version = "4.0.32", features = ["derive"] }
log = "0.4.17"
env_logger = "0.11.3"
Expand Down
16 changes: 11 additions & 5 deletions zork++/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use clap::Parser;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use zork::compiler::generate_commands;
use zork::{
cache::{self, ZorkCache},
cli::input::CliArgs,
compiler::build_project,
config_file::{self, ZorkConfigFile},
utils::{self, reader::build_model},
};
Expand All @@ -15,12 +15,18 @@
pub fn build_project_benchmark(c: &mut Criterion) {
let config: ZorkConfigFile =
config_file::zork_cfg_from_file(utils::constants::CONFIG_FILE_MOCK).unwrap();
let cli_args = CliArgs::parse();

Check failure on line 18 in zork++/benches/benchmarks.rs

View workflow job for this annotation

GitHub Actions / Verify code formatting

Diff in /home/runner/work/Zork/Zork/zork++/benches/benchmarks.rs
let program_data = build_model(&config, &cli_args, Path::new(".")).unwrap();
let program_data = build_model(config, &cli_args, Path::new(".")).unwrap();
let mut cache = ZorkCache::default();

c.bench_function("Build project", |b| {
b.iter(|| build_project(black_box(&program_data), black_box(&mut cache), false))

c.bench_function("Generate commands", |b| {
b.iter(|| {
generate_commands(
black_box(&program_data),
black_box(&mut cache),
&cli_args,
)
})
});

c.bench_function("Cache loading time", |b| {
Expand Down
40 changes: 0 additions & 40 deletions zork++/src/lib/bounds/mod.rs

This file was deleted.

44 changes: 26 additions & 18 deletions zork++/src/lib/cache/compile_commands.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,59 @@
use crate::cache::ZorkCache;
use crate::cli::output::arguments::Arguments;
use crate::cli::output::commands::SourceCommandLine;
use crate::utils;
use crate::utils::constants::COMPILATION_DATABASE;
use color_eyre::eyre::{Context, Result};
use serde::Serialize;
use std::fs::File;
use std::path::{Path, PathBuf};

pub type CompileCommands<'a> = Vec<CompileCommand<'a>>;

/// Generates the `compile_commands.json` file, that acts as a compilation database
/// for some static analysis external tools, like `clang-tidy`, and populates it with
/// the generated commands for the translation units
pub(crate) fn map_generated_commands_to_compilation_db(cache: &ZorkCache) -> Result<()> {
pub(crate) fn map_generated_commands_to_compilation_db<'a>(
cache: &'a ZorkCache<'a>,
) -> Result<CompileCommands<'a>> {
log::trace!("Generating the compilation database...");
let mut compilation_db_entries = Vec::with_capacity(cache.last_generated_commands.len());

for command in cache.last_generated_commands.iter() {
compilation_db_entries.push(CompileCommands::from(command));
let generated_commands = cache.get_all_commands_iter();
let mut compilation_db_entries: Vec<CompileCommand> =
Vec::with_capacity(cache.count_total_generated_commands()); // Without the linker one

for command in generated_commands {
compilation_db_entries.push(CompileCommand::from(command));
}

let compile_commands_path = Path::new(COMPILATION_DATABASE);
if !Path::new(&compile_commands_path).exists() {
File::create(compile_commands_path)
.with_context(|| "Error creating the compilation database")?;
}

utils::fs::serialize_object_to_file(Path::new(compile_commands_path), &compilation_db_entries)
.with_context(move || "Error saving the compilation database")
.with_context(move || "Error saving the compilation database")?;

Ok(compilation_db_entries)
}

/// Data model for serialize the data that will be outputted
/// to the `compile_commands.json` compilation database file
#[derive(Serialize, Debug, Default, Clone)]
pub struct CompileCommands {
pub directory: String,
pub struct CompileCommand<'a> {
pub directory: PathBuf,
pub file: String,
pub arguments: Vec<String>,
pub arguments: Arguments<'a>,
}

impl From<(&'_ PathBuf, &'_ Vec<String>)> for CompileCommands {
fn from(value: (&PathBuf, &Vec<String>)) -> Self {
let dir = value.0.parent().unwrap_or(Path::new("."));
let mut file = value.0.file_stem().unwrap_or_default().to_os_string();
file.push(".");
file.push(value.0.extension().unwrap_or_default());

impl<'a> From<&SourceCommandLine<'a>> for CompileCommand<'a> {
fn from(value: &SourceCommandLine<'a>) -> Self {
let value = value.clone();
Self {
directory: dir.to_str().unwrap_or_default().to_string(),
file: file.to_str().unwrap_or_default().to_string(),
arguments: value.1.clone(),
directory: value.directory,
file: value.filename,
arguments: value.args,
}
}
}
Loading
Loading