Skip to content

Commit

Permalink
refactor(ops): Rewrite fast call optimizer and codegen (denoland#16514)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Nov 10, 2022
1 parent 92764c0 commit bc33a4b
Show file tree
Hide file tree
Showing 39 changed files with 1,702 additions and 648 deletions.
30 changes: 30 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ proc-macro = true

[dependencies]
once_cell = "1.10.0"
pmutil = "0.5.3"
proc-macro-crate = "1.1.3"
proc-macro2 = "1"
quote = "1"
Expand All @@ -20,4 +21,6 @@ syn = { version = "1", features = ["full", "extra-traits"] }

[dev-dependencies]
deno_core = { path = "../core" }
prettyplease = "0.1.21"
testing_macros = "0.2.7"
trybuild = "1.0.61"
37 changes: 37 additions & 0 deletions ops/attrs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use syn::{
parse::{Parse, ParseStream},
punctuated::Punctuated,
Error, Ident, Result, Token,
};

#[derive(Copy, Clone, Debug, Default)]
pub struct Attributes {
pub is_unstable: bool,
pub is_v8: bool,
pub must_be_fast: bool,
pub deferred: bool,
}

impl Parse for Attributes {
fn parse(input: ParseStream) -> Result<Self> {
let vars = Punctuated::<Ident, Token![,]>::parse_terminated(input)?;

let vars: Vec<_> = vars.iter().map(Ident::to_string).collect();
let vars: Vec<_> = vars.iter().map(String::as_str).collect();
for var in vars.iter() {
if !["unstable", "v8", "fast", "deferred"].contains(var) {
return Err(Error::new(
input.span(),
"invalid attribute, expected one of: unstable, v8, fast, deferred",
));
}
}
Ok(Self {
is_unstable: vars.contains(&"unstable"),
is_v8: vars.contains(&"v8"),
must_be_fast: vars.contains(&"fast"),
deferred: vars.contains(&"deferred"),
})
}
}
32 changes: 32 additions & 0 deletions ops/deno.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

use proc_macro2::{Span, TokenStream};
use proc_macro_crate::{crate_name, FoundCrate};
use quote::quote;
use syn::Ident;

/// Identifier to the `deno_core` crate.
///
/// If macro called in deno_core, `crate` is used.
/// If macro called outside deno_core, `deno_core` OR the renamed
/// version from Cargo.toml is used.
pub(crate) fn import() -> TokenStream {
let found_crate =
crate_name("deno_core").expect("deno_core not present in `Cargo.toml`");

match found_crate {
FoundCrate::Itself => {
// TODO(@littledivy): This won't work for `deno_core` examples
// since `crate` does not refer to `deno_core`.
// examples must re-export deno_core to make this work
// until Span inspection APIs are stabalized.
//
// https://github.com/rust-lang/rust/issues/54725
quote!(crate)
}
FoundCrate::Name(name) => {
let ident = Ident::new(&name, Span::call_site());
quote!(#ident)
}
}
}
Loading

0 comments on commit bc33a4b

Please sign in to comment.