Skip to content

Commit

Permalink
try_emit
Browse files Browse the repository at this point in the history
  • Loading branch information
MingweiSamuel committed Dec 11, 2024
1 parent 5b9b563 commit 327e197
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 62 deletions.
44 changes: 22 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
rust_release: [pinned-nightly, latest-stable]
rust_release: [pinned-nightly, latest-nightly]
exclude:
# For non-pull requests, event_name != 'pull_request' will be true, and 'nothing' is
# truthy, so the entire && operator will resolve to 'nothing'. Then the || operator will
# resolve to 'nothing' so we will exclude 'nothing'. https://stackoverflow.com/a/73822998
- rust_release: ${{ (needs.pre_job.outputs.should_skip != 'true' && 'nothing') || 'pinned-nightly' }}
- rust_release: ${{ (github.event_name != 'pull_request' && 'nothing') || 'latest-stable' }}
- rust_release: ${{ (github.event_name != 'pull_request' && 'nothing') || 'latest-nightly' }}

env:
CARGO_TERM_COLOR: always
Expand All @@ -55,12 +55,12 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: ${{ matrix.rust_release == 'latest-stable' }}
toolchain: nightly
override: ${{ matrix.rust_release == 'latest-nightly' }}
components: rustfmt, clippy

- name: Run sccache-cache
Expand Down Expand Up @@ -96,25 +96,25 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust_release: [pinned-nightly, latest-stable]
rust_release: [pinned-nightly, latest-nightly]
exclude:
# For non-pull requests, event_name != 'pull_request' will be true, and 'nothing' is
# truthy, so the entire && operator will resolve to 'nothing'. Then the || operator will
# resolve to 'nothing' so we will exclude 'nothing'. https://stackoverflow.com/a/73822998
- rust_release: ${{ (needs.pre_job.outputs.should_skip != 'true' && 'nothing') || 'pinned-nightly' }}
- rust_release: ${{ (github.event_name != 'pull_request' && 'nothing') || 'latest-stable' }}
- rust_release: ${{ (github.event_name != 'pull_request' && 'nothing') || 'latest-nightly' }}

steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
toolchain: nightly
target: wasm32-unknown-unknown
override: ${{ matrix.rust_release == 'latest-stable' }}
override: ${{ matrix.rust_release == 'latest-nightly' }}

- name: Check hydroflow_lang
uses: actions-rs/cargo@v1
Expand All @@ -132,13 +132,13 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
rust_release: [pinned-nightly, latest-stable]
rust_release: [pinned-nightly, latest-nightly]
exclude:
# For non-pull requests, event_name != 'pull_request' will be true, and 'nothing' is
# truthy, so the entire && operator will resolve to 'nothing'. Then the || operator will
# resolve to 'nothing' so we will exclude 'nothing'. https://stackoverflow.com/a/73822998
- rust_release: ${{ (needs.pre_job.outputs.should_skip != 'true' && 'nothing') || 'pinned-nightly' }}
- rust_release: ${{ (github.event_name != 'pull_request' && 'nothing') || 'latest-stable' }}
- rust_release: ${{ (github.event_name != 'pull_request' && 'nothing') || 'latest-nightly' }}
- os: ${{ (github.event_name != 'pull_request' && 'nothing') || 'windows-latest' }}

env:
Expand All @@ -152,12 +152,12 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: ${{ matrix.rust_release == 'latest-stable' }}
toolchain: nightly
override: ${{ matrix.rust_release == 'latest-nightly' }}

- name: Run sccache-cache
if: matrix.rust_release == 'pinned-nightly'
Expand Down Expand Up @@ -235,25 +235,25 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust_release: [pinned-nightly, latest-stable]
rust_release: [pinned-nightly, latest-nightly]
exclude:
# For non-pull requests, event_name != 'pull_request' will be true, and 'nothing' is
# truthy, so the entire && operator will resolve to 'nothing'. Then the || operator will
# resolve to 'nothing' so we will exclude 'nothing'. https://stackoverflow.com/a/73822998
- rust_release: ${{ (needs.pre_job.outputs.should_skip != 'true' && 'nothing') || 'pinned-nightly' }}
- rust_release: ${{ (github.event_name != 'pull_request' && 'nothing') || 'latest-stable' }}
- rust_release: ${{ (github.event_name != 'pull_request' && 'nothing') || 'latest-nightly' }}

steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
toolchain: nightly
target: wasm32-unknown-unknown
override: ${{ matrix.rust_release == 'latest-stable' }}
override: ${{ matrix.rust_release == 'latest-nightly' }}

- name: Get wasm-bindgen version
id: wasm-bindgen-version
Expand Down Expand Up @@ -299,7 +299,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand Down Expand Up @@ -366,7 +366,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions hydroflow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ description = "Hydro's low-level dataflow runtime and IR"
workspace = true

[features]
default = [ "macros", "nightly", "debugging" ]
default = [ "macros", "debugging" ]

nightly = []
macros = [ "hydroflow_macro", "hydroflow_datalog" ]
hydroflow_macro = [ "dep:hydroflow_macro" ]
hydroflow_datalog = [ "dep:hydroflow_datalog" ]
Expand Down
6 changes: 1 addition & 5 deletions hydroflow/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg_attr(feature = "nightly", feature(never_type))]
#![warn(missing_docs)]

//! Hydroflow is a low-level dataflow-based runtime system for the [Hydro Project](https://hydro.run/).
Expand Down Expand Up @@ -39,12 +38,9 @@ pub use hydroflow_macro::{
hydroflow_test as test, monotonic_fn, morphism, DemuxEnum,
};

// TODO(mingwei): Use the [nightly "never" type `!`](https://doc.rust-lang.org/std/primitive.never.html)
/// Stand-in for the [nightly "never" type `!`](https://doc.rust-lang.org/std/primitive.never.html)
#[cfg(not(feature = "nightly"))]
pub type Never = std::convert::Infallible;
/// The [nightly "never" type `!`](https://doc.rust-lang.org/std/primitive.never.html)
#[cfg(feature = "nightly")]
pub type Never = !;

#[cfg(doctest)]
mod booktest {
Expand Down
14 changes: 10 additions & 4 deletions hydroflow_datalog/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use hydroflow_datalog_core::diagnostic::Diagnostic;
use hydroflow_datalog_core::{gen_hydroflow_graph, hydroflow_graph_to_program};
use proc_macro2::Span;
use quote::{quote, ToTokens};
Expand Down Expand Up @@ -31,10 +32,15 @@ pub fn datalog(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
program.to_token_stream().into()
}
Err(diagnostics) => {
for diagnostic in diagnostics {
diagnostic.emit();
}
proc_macro::TokenStream::from(quote!(hydroflow::scheduled::graph::Hydroflow::new()))
let diagnostic_tokens = Diagnostic::try_emit_all(diagnostics.iter())
.err()
.unwrap_or_default();
proc_macro::TokenStream::from(quote! {
{
#diagnostic_tokens
hydroflow::scheduled::graph::Hydroflow::new()
}
})
}
}
}
1 change: 1 addition & 0 deletions hydroflow_datalog_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::{HashMap, HashSet};
use std::ops::Deref;

pub use hydroflow_lang::diagnostic;
use hydroflow_lang::diagnostic::{Diagnostic, Level};
use hydroflow_lang::graph::{
eliminate_extra_unions_tees, partition_graph, FlatGraphBuilder, HydroflowGraph,
Expand Down
14 changes: 5 additions & 9 deletions hydroflow_lang/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,15 @@ pub struct SerdeSpan {
impl From<Span> for SerdeSpan {
fn from(span: Span) -> Self {
#[cfg(nightly)]
let path = span
.unwrap()
.source_file()
.path()
.display()
.to_string()
.into();
let path = std::panic::catch_unwind(|| span.unwrap())
.map(|span| span.source_file().path().display().to_string())
.ok();

#[cfg(not(nightly))]
let path = "unknown".into();
let path = None::<String>;

Self {
path,
path: path.map_or(Cow::Borrowed("unknown"), Cow::Owned),
line: span.start().line,
column: span.start().column,
}
Expand Down
1 change: 1 addition & 0 deletions hydroflow_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ syn = { version = "2.0.46", features = [ "parsing", "extra-traits" ] }
hydroflow_lang = { path = "../hydroflow_lang", version = "^0.10.0" }
itertools = "0.10.0"
quote = "1.0.35"
rustc_version = "0.4.0"
9 changes: 9 additions & 0 deletions hydroflow_macro/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use hydroflow_lang::graph::ops::{PortListSpec, OPERATORS};
use hydroflow_lang::graph::PortIndexValue;
use itertools::Itertools;
use quote::ToTokens;
use rustc_version::{version_meta, Channel};

const FILENAME: &str = "surface_ops_gen.md";

Expand Down Expand Up @@ -207,6 +208,14 @@ fn update_book() -> Result<()> {
}

fn main() {
println!("cargo::rustc-check-cfg=cfg(nightly)");
if matches!(
version_meta().map(|meta| meta.channel),
Ok(Channel::Nightly)
) {
println!("cargo:rustc-cfg=nightly");
}

if Err(VarError::NotPresent) != std::env::var("CARGO_CFG_HYDROFLOW_GENERATE_DOCS") {
if let Err(err) = update_book() {
eprintln!("hydroflow_macro/build.rs error: {:?}", err);
Expand Down
33 changes: 13 additions & 20 deletions hydroflow_macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg_attr(
feature = "diagnostics",
nightly,
feature(proc_macro_diagnostic, proc_macro_span, proc_macro_def_site)
)]

Expand Down Expand Up @@ -72,25 +72,16 @@ fn hydroflow_syntax_internal(
.iter()
.filter(|diag: &&Diagnostic| Some(diag.level) <= min_diagnostic_level);

#[cfg(feature = "diagnostics")]
{
diagnostics.for_each(Diagnostic::emit);
tokens.into()
}

#[cfg(not(feature = "diagnostics"))]
{
let diagnostics = diagnostics.map(Diagnostic::to_tokens);
quote! {
{
#(
#diagnostics
)*
#tokens
}
let diagnostic_tokens = Diagnostic::try_emit_all(diagnostics)
.err()
.unwrap_or_default();
quote! {
{
#diagnostic_tokens
#tokens
}
.into()
}
.into()
}

/// Parse Hydroflow "surface syntax" without emitting code.
Expand Down Expand Up @@ -123,8 +114,10 @@ pub fn hydroflow_parser(input: proc_macro::TokenStream) -> proc_macro::TokenStre
}
}

diagnostics.iter().for_each(Diagnostic::emit);
quote! {}.into()
Diagnostic::try_emit_all(diagnostics.iter())
.err()
.unwrap_or_default()
.into()
}

#[doc(hidden)]
Expand Down

0 comments on commit 327e197

Please sign in to comment.