-
Notifications
You must be signed in to change notification settings - Fork 326
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
Provide syntax warnings to Java #10645
Changes from all commits
fdce181
50149bd
dd81f5d
32e0df5
fb2ef2f
3dc45ff
9d7de7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
//! Parses Enso sources, measuring time spent in the parser. | ||
|
||
#![feature(test)] | ||
// === Non-Standard Linter Configuration === | ||
#![allow(clippy::option_map_unit_fn)] | ||
#![allow(clippy::precedence)] | ||
|
@@ -11,24 +12,78 @@ | |
|
||
|
||
|
||
// ============= | ||
// === Tests === | ||
// ============= | ||
// =========== | ||
// === CLI === | ||
// =========== | ||
|
||
fn main() { | ||
let args = std::env::args().skip(1); | ||
let parser = enso_parser::Parser::new(); | ||
let parse_time: std::time::Duration = args | ||
.map(|path| { | ||
let code = std::fs::read_to_string(path).unwrap(); | ||
let mut code = code.as_str(); | ||
if let Some((_meta, code_)) = enso_parser::metadata::parse(code) { | ||
code = code_; | ||
} | ||
let code = read_source(path).unwrap(); | ||
let start = std::time::Instant::now(); | ||
std::hint::black_box(parser.run(code)); | ||
std::hint::black_box(parser.run(&code)); | ||
start.elapsed() | ||
}) | ||
.sum(); | ||
println!("Parse time: {} ms", parse_time.as_millis()); | ||
} | ||
|
||
fn read_source(path: impl AsRef<Path>) -> io::Result<String> { | ||
let code = fs::read_to_string(path)?; | ||
Ok(if let Some((_meta, code)) = enso_parser::metadata::parse(&code) { | ||
code.to_owned() | ||
} else { | ||
code | ||
}) | ||
} | ||
|
||
|
||
|
||
// =============================== | ||
// === `cargo bench` interface === | ||
// =============================== | ||
|
||
extern crate test; | ||
|
||
use std::fs::DirEntry; | ||
use std::fs::{self}; | ||
use std::io; | ||
use std::path::Path; | ||
|
||
fn visit_files<F: FnMut(&DirEntry)>(dir: &Path, f: &mut F) -> io::Result<()> { | ||
if dir.is_dir() { | ||
for entry in fs::read_dir(dir)? { | ||
let entry = entry?; | ||
let path = entry.path(); | ||
if path.is_dir() { | ||
visit_files(&path, f)?; | ||
} else { | ||
f(&entry); | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[bench] | ||
fn bench_std_lib(b: &mut test::Bencher) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that there is a framework for benchmarks in the engine. We currently have benchmarks for the engine compiler, like InlineCOmpilerBenchmark. We don't have benchmarks for parser yet, but they should not be difficult to implement. Is this benchmark run automatically on the CI, or is it supposed to be run manually? Shouldn't we just add parser benchmarks to the already existing engine runtime-benchmarks infrastructure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great to have an |
||
let mut sources = vec![]; | ||
visit_files(Path::new("../../../../distribution/lib"), &mut |dir_ent| { | ||
let path = dir_ent.path(); | ||
if let Some(ext) = path.extension() { | ||
if ext == "enso" { | ||
sources.push(read_source(path).unwrap()) | ||
} | ||
} | ||
}) | ||
.unwrap(); | ||
let parser = enso_parser::Parser::new(); | ||
b.bytes = sources.iter().map(|s| s.len() as u64).sum(); | ||
b.iter(|| { | ||
for source in &sources { | ||
test::black_box(parser.run(source)); | ||
} | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,8 @@ private Parser(long stateIn) { | |
|
||
private static native long getMetadata(long state); | ||
|
||
private static native String getWarningTemplate(int warningId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The performance of
This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Rust side, I implemented warnings with a table of messages with the idea being we can transfer the table all at once, ideally at build time. This method is an initial unoptimized implementation that was much simpler. The method is called for each warning encountered, so this temporary solution will not have any performance impact when warnings are not numerous. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment isn't really related to this PR, but I don't know where else to record these findings. Anyway it illustrates what I meant by
I have just performed a measurement on enso$ ./built-distribution/enso-engine-*/enso-*/bin/enso --run test/Base_Tests/ --profiling-path start.npss Nic that is a nice benchmark for parser as it needs to parse 118 There is still five more bottlenecks ahead of |
||
|
||
static native long getUuidHigh(long metadata, long codeOffset, long codeLength); | ||
|
||
static native long getUuidLow(long metadata, long codeOffset, long codeLength); | ||
|
@@ -131,6 +133,10 @@ public Tree parse(CharSequence input) { | |
return Tree.deserialize(message); | ||
} | ||
|
||
public static String getWarningMessage(Warning warning) { | ||
return getWarningTemplate(warning.getId()); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
freeState(state); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With following signature
one can write
yield attachTranslatedWarnings(ir, app)
.