Skip to content

Commit

Permalink
Merge branch 'main' into oscarpuente/compiler-options
Browse files Browse the repository at this point in the history
  • Loading branch information
orpuente-MS authored Apr 22, 2024
2 parents 8cfd095 + 4d891c1 commit c784755
Show file tree
Hide file tree
Showing 259 changed files with 11,870 additions and 2,159 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/pip @billti @idavis @minestarks
/playground @billti @cesarzc @minestarks
/resource_estimator @billti @ivanbasov @swernli
/samples @cesarzc @DmitryVasilevsky @sezna @swernli
/samples @cesarzc @DmitryVasilevsky @sezna @swernli @tcNickolas
/vscode @billti @idavis @minestarks @sezna
/wasm @billti @cesarzc @sezna @swernli

Expand Down
12 changes: 12 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ version = "0.0.0"
bitflags = "2.4.2"
clap = "4.4"
criterion = { version = "0.5", default-features = false }
difference = "2.0.0"
enum-iterator = "1.5"
env_logger = "0.10"
expect-test = "1.4"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ build of each project, including running tests and checks such as linting. Run w

### Playground

To run the "playground" locally, build the repository, then `cd` into the `playground` directory, and run `npm start`.
This will launch a local web server and output the URL to the console; copy that URL and open it in a browser to use the playground.
If you only want to build the functionality necessary to run the playground, you can use `python .\build.py --wasm --npm --play`.
The `playground` is a small website that loads the Q# editor, compiler, samples, katas, and documentation for the standard library. It's a way to manually validate any changes you make to these components.

To see instructions for building the playground, refer to [Building the Playground Locally](./playground/README.md#building-the-playground-locally).

### Python

Expand Down
1 change: 1 addition & 0 deletions compiler/qsc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ qsc_ast = { path = "../qsc_ast" }
qsc_fir = { path = "../qsc_fir" }
qsc_hir = { path = "../qsc_hir" }
qsc_passes = { path = "../qsc_passes" }
qsc_partial_eval = { path = "../qsc_partial_eval" }
qsc_project = { path = "../qsc_project", features = ["fs"] }
qsc_rca = { path = "../qsc_rca" }
qsc_circuit = { path = "../qsc_circuit" }
Expand Down
16 changes: 8 additions & 8 deletions compiler/qsc/benches/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use indoc::indoc;
use qsc::{interpret::Interpreter, PackageType};
use qsc_data_structures::language_features::LanguageFeatures;
use qsc_eval::output::GenericReceiver;
use qsc_frontend::compile::{RuntimeCapabilityFlags, SourceMap};
use qsc_frontend::compile::{SourceMap, TargetCapabilityFlags};

const TELEPORT: &str = include_str!("../../../samples/algorithms/Teleportation.qs");
const DEUTSCHJOZSA: &str = include_str!("../../../samples/algorithms/DeutschJozsa.qs");
Expand All @@ -22,7 +22,7 @@ pub fn teleport(c: &mut Criterion) {
true,
sources,
PackageType::Exe,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
LanguageFeatures::default(),
)
.expect("code should compile");
Expand All @@ -41,7 +41,7 @@ pub fn deutsch_jozsa(c: &mut Criterion) {
true,
sources,
PackageType::Exe,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
LanguageFeatures::default(),
)
.expect("code should compile");
Expand All @@ -60,7 +60,7 @@ pub fn large_file(c: &mut Criterion) {
true,
sources,
PackageType::Exe,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
LanguageFeatures::default(),
)
.expect("code should compile");
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn array_append(c: &mut Criterion) {
true,
sources,
PackageType::Exe,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
LanguageFeatures::default(),
)
.expect("code should compile");
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn array_update(c: &mut Criterion) {
true,
sources,
PackageType::Exe,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
LanguageFeatures::default(),
)
.expect("code should compile");
Expand All @@ -141,7 +141,7 @@ pub fn array_literal(c: &mut Criterion) {
true,
sources,
PackageType::Exe,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
LanguageFeatures::default(),
)
.expect("code should compile");
Expand Down Expand Up @@ -177,7 +177,7 @@ pub fn large_nested_iteration(c: &mut Criterion) {
true,
sources,
PackageType::Exe,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
LanguageFeatures::default(),
)
.expect("code should compile");
Expand Down
8 changes: 4 additions & 4 deletions compiler/qsc/benches/large.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ allocator::assign_global!();
use criterion::{criterion_group, criterion_main, Criterion};
use qsc::compile::{self, compile};
use qsc_data_structures::language_features::LanguageFeatures;
use qsc_frontend::compile::{PackageStore, RuntimeCapabilityFlags, SourceMap};
use qsc_frontend::compile::{PackageStore, SourceMap, TargetCapabilityFlags};
use qsc_passes::PackageType;

const INPUT: &str = include_str!("./large.qs");

pub fn large_file(c: &mut Criterion) {
c.bench_function("Large input file compilation", |b| {
let mut store = PackageStore::new(compile::core());
let std = store.insert(compile::std(&store, RuntimeCapabilityFlags::all()));
let std = store.insert(compile::std(&store, TargetCapabilityFlags::all()));
b.iter(|| {
let sources = SourceMap::new([("large.qs".into(), INPUT.into())], None);
let (_, reports) = compile(
&store,
&[std],
sources,
PackageType::Exe,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
LanguageFeatures::default(),
);
assert!(reports.is_empty());
Expand All @@ -38,7 +38,7 @@ pub fn large_file_interpreter(c: &mut Criterion) {
true,
sources,
PackageType::Exe,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
LanguageFeatures::default(),
)
.expect("code should compile");
Expand Down
4 changes: 2 additions & 2 deletions compiler/qsc/benches/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ allocator::assign_global!();

use criterion::{criterion_group, criterion_main, Criterion};
use qsc::compile;
use qsc_frontend::compile::{PackageStore, RuntimeCapabilityFlags};
use qsc_frontend::compile::{PackageStore, TargetCapabilityFlags};

pub fn library(c: &mut Criterion) {
c.bench_function("Core + Standard library compilation", |b| {
b.iter(|| {
let store = PackageStore::new(compile::core());
compile::std(&store, RuntimeCapabilityFlags::all())
compile::std(&store, TargetCapabilityFlags::all())
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/qsc/benches/rca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
use qsc::incremental::Compiler;
use qsc_data_structures::language_features::LanguageFeatures;
use qsc_fir::fir::PackageStore;
use qsc_frontend::compile::{PackageStore as HirPackageStore, RuntimeCapabilityFlags, SourceMap};
use qsc_frontend::compile::{PackageStore as HirPackageStore, SourceMap, TargetCapabilityFlags};
use qsc_lowerer::{map_hir_package_to_fir, Lowerer};
use qsc_passes::PackageType;
use qsc_rca::{Analyzer, PackageStoreComputeProperties};
Expand Down Expand Up @@ -130,7 +130,7 @@ impl Default for CompilationContext {
true,
SourceMap::default(),
PackageType::Lib,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
LanguageFeatures::default(),
)
.expect("should be able to create a new compiler");
Expand Down
4 changes: 2 additions & 2 deletions compiler/qsc/src/bin/memtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! Records the memory usage of the compiler.
use qsc::{compile, CompileUnit};
use qsc_frontend::compile::{PackageStore, RuntimeCapabilityFlags};
use qsc_frontend::compile::{PackageStore, TargetCapabilityFlags};
use std::{
alloc::{GlobalAlloc, Layout, System},
sync::atomic::{AtomicU64, Ordering},
Expand Down Expand Up @@ -48,7 +48,7 @@ static ALLOCATOR: AllocationCounter<System> = AllocationCounter::new(System);
#[must_use]
pub fn compile_stdlib() -> CompileUnit {
let store = PackageStore::new(compile::core());
compile::std(&store, RuntimeCapabilityFlags::all())
compile::std(&store, TargetCapabilityFlags::all())
}

fn main() {
Expand Down
6 changes: 3 additions & 3 deletions compiler/qsc/src/bin/qsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use qsc::compile::compile;
use qsc_codegen::qir_base;
use qsc_data_structures::language_features::LanguageFeatures;
use qsc_frontend::{
compile::{PackageStore, RuntimeCapabilityFlags, SourceContents, SourceMap, SourceName},
compile::{PackageStore, SourceContents, SourceMap, SourceName, TargetCapabilityFlags},
error::WithSource,
};
use qsc_hir::hir::{Package, PackageId};
Expand Down Expand Up @@ -74,9 +74,9 @@ fn main() -> miette::Result<ExitCode> {
let mut dependencies = Vec::new();

let (package_type, capabilities) = if cli.emit.contains(&Emit::Qir) {
(PackageType::Exe, RuntimeCapabilityFlags::empty())
(PackageType::Exe, TargetCapabilityFlags::empty())
} else {
(PackageType::Lib, RuntimeCapabilityFlags::all())
(PackageType::Lib, TargetCapabilityFlags::all())
};

if !cli.nostdlib {
Expand Down
6 changes: 3 additions & 3 deletions compiler/qsc/src/bin/qsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use qsc_eval::{
state::format_state_id,
val::Value,
};
use qsc_frontend::compile::{RuntimeCapabilityFlags, SourceContents, SourceMap, SourceName};
use qsc_frontend::compile::{SourceContents, SourceMap, SourceName, TargetCapabilityFlags};
use qsc_passes::PackageType;
use qsc_project::{FileSystem, Manifest, StdFs};
use std::{
Expand Down Expand Up @@ -106,7 +106,7 @@ fn main() -> miette::Result<ExitCode> {
!cli.nostdlib,
SourceMap::new(sources, cli.entry.map(std::convert::Into::into)),
PackageType::Exe,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
features,
) {
Ok(interpreter) => interpreter,
Expand All @@ -126,7 +126,7 @@ fn main() -> miette::Result<ExitCode> {
!cli.nostdlib,
SourceMap::new(sources, None),
PackageType::Lib,
RuntimeCapabilityFlags::all(),
TargetCapabilityFlags::all(),
features,
) {
Ok(interpreter) => interpreter,
Expand Down
33 changes: 21 additions & 12 deletions compiler/qsc/src/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

use qsc_codegen::qir::hir_to_qir;
use qsc_codegen::qir::fir_to_qir;
use qsc_data_structures::language_features::LanguageFeatures;
use qsc_frontend::compile::{PackageStore, RuntimeCapabilityFlags, SourceMap};
use qsc_frontend::compile::{PackageStore, SourceMap, TargetCapabilityFlags};
use qsc_partial_eval::ProgramEntry;
use qsc_passes::{PackageType, PassContext};

use crate::compile;

pub fn get_qir(
sources: SourceMap,
language_features: LanguageFeatures,
capabilities: RuntimeCapabilityFlags,
capabilities: TargetCapabilityFlags,
) -> Result<String, String> {
let core = compile::core();
let mut package_store = PackageStore::new(core);
Expand All @@ -35,17 +36,25 @@ pub fn get_qir(
}

let package_id = package_store.insert(unit);

let caps_results = PassContext::run_fir_passes_on_hir(&package_store, package_id, capabilities);
let (fir_store, fir_package_id) = qsc_passes::lower_hir_to_fir(&package_store, package_id);
let caps_results = PassContext::run_fir_passes_on_fir(&fir_store, fir_package_id, capabilities);
let package = fir_store.get(fir_package_id);
let entry = ProgramEntry {
exec_graph: package.entry_exec_graph.clone(),
expr: (
fir_package_id,
package
.entry
.expect("package must have an entry expression"),
)
.into(),
};
// Ensure it compiles before trying to add it to the store.
match caps_results {
Ok(compute_properties) => hir_to_qir(
&package_store,
package_id,
capabilities,
Some(compute_properties),
)
.map_err(|e| e.to_string()),
Ok(compute_properties) => {
fir_to_qir(&fir_store, capabilities, Some(compute_properties), &entry)
.map_err(|e| e.to_string())
}
Err(_) => {
// This should never happen, as the program should be checked for errors before trying to
// generate code for it. But just in case, simply report the failure.
Expand Down
Loading

0 comments on commit c784755

Please sign in to comment.