Skip to content

Commit

Permalink
Tracking branch: Multi-File Support (#918)
Browse files Browse the repository at this point in the history
This PR contains the re-application of #901, plus:
1. QIR generation for projects
1. RE for projects
1. Histogram for projects
1. Prioritize open text buffers over disk contents, if present
1. Various bugfixes and memory usage improvements 
1. Python project support

---------

Co-authored-by: Mine Starks <[email protected]>
Co-authored-by: Mine Starks <[email protected]>
Co-authored-by: Ian Davis <[email protected]>
Co-authored-by: Stefan J. Wernli <[email protected]>
  • Loading branch information
5 people authored Jan 4, 2024
1 parent 09ded18 commit 8ace063
Show file tree
Hide file tree
Showing 64 changed files with 4,351 additions and 1,218 deletions.
175 changes: 175 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ criterion = { version = "0.5", default-features = false }
enum-iterator = "1.4"
env_logger = "0.10.0"
expect-test = "1.4"
futures = "0.3"
futures-util = "0.3"
fasteval = "0.2"
getrandom = { version = "0.2" }
indoc = "2.0"
Expand All @@ -53,10 +55,13 @@ rustc-hash = "1.1.0"
serde = "1.0"
serde-wasm-bindgen = "0.6"
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
rand = "0.8"
serde_json = { version = "1.0" }
pyo3 = { version = "0.20" }
quantum-sparse-sim = { git = "https://github.com/qir-alliance/qir-runner", rev = "f000e0066f56338595be37092cd0498f72ab10a2", default-features = false }
async-trait = "0.1"
tokio = { version = "1.34", features = ["macros", "rt"] }

[profile.release]
debug = 1
Expand Down
2 changes: 1 addition & 1 deletion compiler/qsc/src/bin/qsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn main() -> miette::Result<ExitCode> {
let fs = StdFs;
let manifest = Manifest::load()?;
if let Some(manifest) = manifest {
let project = fs.load_project(manifest)?;
let project = fs.load_project(&manifest)?;
let mut project_sources = project.sources;

sources.append(&mut project_sources);
Expand Down
2 changes: 1 addition & 1 deletion compiler/qsc/src/bin/qsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn main() -> miette::Result<ExitCode> {
let fs = StdFs;
let manifest = Manifest::load()?;
if let Some(manifest) = manifest {
let project = fs.load_project(manifest)?;
let project = fs.load_project(&manifest)?;
let mut project_sources = project.sources;

sources.append(&mut project_sources);
Expand Down
12 changes: 6 additions & 6 deletions compiler/qsc/src/interpret/stateful.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,15 +622,15 @@ impl<'a> BreakpointCollector<'a> {
}

fn add_stmt(&mut self, stmt: &qsc_fir::fir::Stmt) {
let source: &Source = self.get_source(self.offset);
let source: &Source = self.get_source(stmt.span.lo);
if source.offset == self.offset {
let span = stmt.span - source.offset;
let bps = BreakpointSpan {
id: stmt.id.into(),
lo: span.lo,
hi: span.hi,
};
if span != Span::default() {
let bps = BreakpointSpan {
id: stmt.id.into(),
lo: span.lo,
hi: span.hi,
};
self.statements.insert(bps);
}
}
Expand Down
43 changes: 43 additions & 0 deletions compiler/qsc/src/interpret/stateful/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,8 @@ mod given_interpreter {

#[cfg(test)]
mod with_sources {
use std::sync::Arc;

use super::*;
use expect_test::expect;
use indoc::indoc;
Expand Down Expand Up @@ -1126,6 +1128,47 @@ mod given_interpreter {
is_only_value(&result, &output, &Value::String("hello there...".into()));
}

#[test]
fn multiple_files_are_loaded_from_sources_into_eval_context() {
let sources: [(Arc<str>, Arc<str>); 2] = [
(
"a.qs".into(),
r#"
namespace Test {
function Hello() : String {
"hello there..."
}
}"#
.into(),
),
(
"b.qs".into(),
r#"
namespace Test2 {
open Test;
operation Main() : String {
Hello();
Hello()
}
}"#
.into(),
),
];

let sources = SourceMap::new(sources, None);
let interpreter = Interpreter::new(
true,
sources,
PackageType::Lib,
RuntimeCapabilityFlags::all(),
)
.expect("interpreter should be created");
let bps = interpreter.get_breakpoints("a.qs");
assert_eq!(1, bps.len());
let bps = interpreter.get_breakpoints("b.qs");
assert_eq!(2, bps.len());
}

#[test]
fn multiple_namespaces_are_loaded_from_sources_into_eval_context() {
let source = indoc! { r#"
Expand Down
4 changes: 4 additions & 0 deletions compiler/qsc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ pub mod ast {
pub use qsc_ast::{ast::*, *};
}

pub mod project {
pub use qsc_project::{DirEntry, EntryType, FileSystem, Manifest, ManifestDescriptor};
}

pub use qsc_data_structures::span::Span;

pub use qsc_passes::{PackageType, PassContext};
Expand Down
Loading

0 comments on commit 8ace063

Please sign in to comment.