Skip to content

Commit

Permalink
Merge branch 'main' into more-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelGarus committed Feb 22, 2023
2 parents b1db8da + 0b21361 commit a8082a4
Show file tree
Hide file tree
Showing 60 changed files with 4,397 additions and 2,602 deletions.
624 changes: 278 additions & 346 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions compiler/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ candy_frontend = { path = "../frontend" }
candy_fuzzer = { path = "../fuzzer" }
candy_language_server = { path = "../language_server" }
candy_vm = { path = "../vm" }
clap = { version = "4.1.4", features = ["derive"] }
itertools = { version = "0.10.0" }
notify = "4.0.17"
notify = "5.1.0"
notify-debouncer-mini = { version = "0.2.1", default-features = false }
rustc-hash = "1.1.0"
salsa = "0.16.1"
structopt = "0.3.25"
tokio = { version = "1.23.1", features = ["full"] }
tokio = { version = "1.24.2", features = ["full"] }
tower-lsp = "0.18.0"
tracing = { version = "0.1", features = ["release_max_level_debug"] }
tracing-subscriber = { version = "0.3.16", features = ["registry"] }
7 changes: 0 additions & 7 deletions compiler/cli/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,20 @@ use candy_frontend::{
rcst_to_cst::RcstToCstStorage,
string_to_rcst::StringToRcstStorage,
};
use candy_language_server::{
folding_range::FoldingRangeDbStorage, references::ReferencesDbStorage,
semantic_tokens::SemanticTokenDbStorage,
};
use candy_vm::mir_to_lir::MirToLirStorage;

#[salsa::database(
AstDbStorage,
AstToHirStorage,
CstDbStorage,
CstToAstStorage,
FoldingRangeDbStorage,
HirDbStorage,
HirToMirStorage,
MirToLirStorage,
ModuleDbStorage,
OptimizeMirStorage,
PositionConversionStorage,
RcstToCstStorage,
ReferencesDbStorage,
SemanticTokenDbStorage,
StringToRcstStorage
)]
pub struct Database {
Expand Down
108 changes: 58 additions & 50 deletions compiler/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use candy_frontend::{
module::{Module, ModuleKind},
position::PositionConversionDb,
rcst_to_cst::RcstToCst,
rich_ir::ToRichIr,
string_to_rcst::StringToRcst,
TracingConfig, TracingMode,
};
use candy_language_server::CandyLanguageServer;
use candy_language_server::server::Server;
use candy_vm::{
channel::{ChannelId, Packet},
context::{DbUseProvider, RunForever},
Expand All @@ -24,9 +25,11 @@ use candy_vm::{
tracer::{full::FullTracer, DummyTracer, Tracer},
vm::{CompletedOperation, OperationId, Status, Vm},
};
use clap::{Parser, ValueHint};
use database::Database;
use itertools::Itertools;
use notify::{watcher, RecursiveMode, Watcher};
use notify::RecursiveMode;
use notify_debouncer_mini::new_debouncer;
use rustc_hash::FxHashMap;
use std::{
convert::TryInto,
Expand All @@ -36,63 +39,61 @@ use std::{
sync::{mpsc::channel, Arc},
time::Duration,
};
use structopt::StructOpt;
use tower_lsp::{LspService, Server};
use tracing::{debug, error, info, warn, Level, Metadata};
use tracing_subscriber::{
filter,
fmt::{format::FmtSpan, writer::BoxMakeWriter},
prelude::*,
};

#[derive(StructOpt, Debug)]
#[structopt(name = "candy", about = "The 🍭 Candy CLI.")]
#[derive(Parser, Debug)]
#[command(name = "candy", about = "The 🍭 Candy CLI.")]
enum CandyOptions {
Build(CandyBuildOptions),
Run(CandyRunOptions),
Fuzz(CandyFuzzOptions),
Lsp,
}

#[derive(StructOpt, Debug)]
#[derive(Parser, Debug)]
struct CandyBuildOptions {
#[structopt(long)]
#[arg(long)]
debug: bool,

#[structopt(long)]
#[arg(long)]
watch: bool,

#[structopt(long)]
#[arg(long)]
tracing: bool,

#[structopt(parse(from_os_str))]
#[arg(value_hint = ValueHint::FilePath)]
file: PathBuf,
}

#[derive(StructOpt, Debug)]
#[derive(Parser, Debug)]
struct CandyRunOptions {
#[structopt(long)]
#[arg(long)]
debug: bool,

#[structopt(long)]
#[arg(long)]
tracing: bool,

#[structopt(parse(from_os_str))]
#[arg(value_hint = ValueHint::FilePath)]
file: PathBuf,
}

#[derive(StructOpt, Debug)]
#[derive(Parser, Debug)]
struct CandyFuzzOptions {
#[structopt(long)]
#[arg(long)]
debug: bool,

#[structopt(parse(from_os_str))]
#[arg(value_hint = ValueHint::FilePath)]
file: PathBuf,
}

#[tokio::main]
async fn main() -> ProgramResult {
match CandyOptions::from_args() {
match CandyOptions::parse() {
CandyOptions::Build(options) => build(options),
CandyOptions::Run(options) => run(options),
CandyOptions::Fuzz(options) => fuzz(options),
Expand Down Expand Up @@ -127,8 +128,9 @@ fn build(options: CandyBuildOptions) -> ProgramResult {
result.ok_or(Exit::FileNotFound).map(|_| ())
} else {
let (tx, rx) = channel();
let mut watcher = watcher(tx, Duration::from_secs(1)).unwrap();
watcher
let mut debouncer = new_debouncer(Duration::from_secs(1), None, tx).unwrap();
debouncer
.watcher()
.watch(&options.file, RecursiveMode::Recursive)
.unwrap();
loop {
Expand All @@ -147,11 +149,15 @@ fn raw_build(
tracing: &TracingConfig,
debug: bool,
) -> Option<Arc<Lir>> {
let rcst = db
.rcst(module.clone())
.unwrap_or_else(|err| panic!("Error parsing file `{}`: {:?}", module, err));
let rcst = db.rcst(module.clone()).unwrap_or_else(|err| {
panic!(
"Error parsing file `{}`: {:?}",
<Module as ToRichIr<Module>>::to_rich_ir(&module),
err,
)
});
if debug {
module.dump_associated_debug_file("rcst", &format!("{:#?}\n", rcst));
module.dump_associated_debug_file("rcst", &format!("{}\n", rcst.to_rich_ir()));
}

let cst = db.cst(module.clone()).unwrap();
Expand All @@ -161,10 +167,7 @@ fn raw_build(

let (asts, ast_cst_id_map) = db.ast(module.clone()).unwrap();
if debug {
module.dump_associated_debug_file(
"ast",
&format!("{}\n", asts.iter().map(|ast| format!("{}", ast)).join("\n")),
);
module.dump_associated_debug_file("ast", &format!("{}\n", asts.to_rich_ir()));
module.dump_associated_debug_file(
"ast_to_cst_ids",
&ast_cst_id_map
Expand All @@ -183,7 +186,7 @@ fn raw_build(

let (hir, hir_ast_id_map) = db.hir(module.clone()).unwrap();
if debug {
module.dump_associated_debug_file("hir", &format!("{}", hir));
module.dump_associated_debug_file("hir", &format!("{}\n", hir.to_rich_ir()));
module.dump_associated_debug_file(
"hir_to_ast_ids",
&hir_ast_id_map
Expand All @@ -209,21 +212,28 @@ fn raw_build(
{
let range = db.range_to_positions(module.clone(), span);
warn!(
"{module}:{}:{} – {}:{}: {payload}",
range.start.line, range.start.character, range.end.line, range.end.character,
"{}:{}:{} – {}:{}: {payload}",
<Module as ToRichIr<Module>>::to_rich_ir(&module),
range.start.line,
range.start.character,
range.end.line,
range.end.character,
);
}

let mir = db.mir(module.clone(), tracing.clone()).unwrap();
if debug {
module.dump_associated_debug_file("mir", &format!("{mir}"));
module.dump_associated_debug_file("mir", &format!("{}\n", mir.to_rich_ir()));
}

let optimized_mir = db
.mir_with_obvious_optimized(module.clone(), tracing.clone())
.unwrap();
if debug {
module.dump_associated_debug_file("optimized_mir", &format!("{optimized_mir}"));
module.dump_associated_debug_file(
"optimized_mir",
&format!("{}\n", optimized_mir.to_rich_ir()),
);
}

let lir = db.lir(module.clone(), tracing.clone()).unwrap();
Expand Down Expand Up @@ -474,7 +484,10 @@ fn fuzz(options: CandyFuzzOptions) -> ProgramResult {
return Err(Exit::FileNotFound);
}

debug!("Fuzzing `{module}`.");
debug!(
"Fuzzing `{}`.",
<Module as ToRichIr<Module>>::to_rich_ir(&module),
);
let failing_cases = candy_fuzzer::fuzz(&db, module);

if failing_cases.is_empty() {
Expand All @@ -495,8 +508,8 @@ fn fuzz(options: CandyFuzzOptions) -> ProgramResult {
async fn lsp() -> ProgramResult {
init_logger(false);
info!("Starting language server…");
let (service, socket) = LspService::new(CandyLanguageServer::from_client);
Server::new(tokio::io::stdin(), tokio::io::stdout(), socket)
let (service, socket) = Server::create();
tower_lsp::Server::new(tokio::io::stdin(), tokio::io::stdout(), socket)
.serve(service)
.await;
Ok(())
Expand All @@ -521,26 +534,21 @@ fn init_logger(use_stdout: bool) {
.starts_with("candy")
}))
.with_filter(filter::filter_fn(level_for(
"candy::compiler::optimize",
Level::DEBUG,
"candy_frontend::mir_optimize",
Level::INFO,
)))
.with_filter(filter::filter_fn(level_for(
"candy::compiler::string_to_rcst",
"candy_frontend::string_to_rcst",
Level::WARN,
)))
.with_filter(filter::filter_fn(level_for("candy_frontend", Level::DEBUG)))
.with_filter(filter::filter_fn(level_for("candy_fuzzer", Level::DEBUG)))
.with_filter(filter::filter_fn(level_for(
"candy::compiler",
Level::DEBUG,
)))
.with_filter(filter::filter_fn(level_for(
"candy::language_server",
"candy_language_server",
Level::TRACE,
)))
.with_filter(filter::filter_fn(level_for("candy::vm", Level::DEBUG)))
.with_filter(filter::filter_fn(level_for(
"candy::vm::heap",
Level::DEBUG,
)));
.with_filter(filter::filter_fn(level_for("candy_vm", Level::DEBUG)))
.with_filter(filter::filter_fn(level_for("candy_vm::heap", Level::DEBUG)));
tracing_subscriber::registry().with(console_log).init();
}
fn level_for(module: &'static str, level: Level) -> impl Fn(&Metadata) -> bool {
Expand Down
3 changes: 3 additions & 0 deletions compiler/frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ rust-version = "1.56"
[lib]

[dependencies]
derive_more = "0.99.17"
enumset = "1.0.12"
im = "15.1.0"
itertools = { version = "0.10.0" }
lazy_static = "1.4.0"
Expand All @@ -15,6 +17,7 @@ num-bigint = { version = "0.4.3", features = ["rand"] }
num-traits = { version = "0.2.15", features = ["i128"] }
rustc-hash = "1.1.0"
salsa = "0.16.1"
serde = { version = "1.0.152", features = ["derive"] }
strum = "0.24.0"
strum_macros = "0.24"
tracing = { version = "0.1", features = ["release_max_level_debug"] }
Expand Down
Loading

1 comment on commit a8082a4

@jwbot
Copy link
Collaborator

@jwbot jwbot commented on a8082a4 Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiler

Benchmark suite Current: a8082a4 Previous: 0b21361 Ratio
Time: Compiler/hello_world 29116369 ns/iter (± 455985) 20562023 ns/iter (± 298456) 1.42
Time: Compiler/fibonacci 790489170 ns/iter (± 10672896) 533562236 ns/iter (± 2671183) 1.48
Time: VM Runtime/hello_world 21488680 ns/iter (± 512182) 15985931 ns/iter (± 430465) 1.34
Time: VM Runtime/fibonacci/15 207686591 ns/iter (± 917871) 189734044 ns/iter (± 896423) 1.09

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.