Skip to content

Commit b08ac6b

Browse files
Point at fork of wasmtime-macro
1 parent 40f2770 commit b08ac6b

9 files changed

Lines changed: 4833 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7204,8 +7204,6 @@ dependencies = [
72047204
[[package]]
72057205
name = "wasmtime-internal-wit-bindgen"
72067206
version = "46.0.0"
7207-
source = "registry+https://github.com/rust-lang/crates.io-index"
7208-
checksum = "e859103d8336304b8beebbf89a620c2f53a118fd5fbce41bc572cf4bacc8111d"
72097207
dependencies = [
72107208
"anyhow",
72117209
"bitflags",

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@ codegen-units = 1
9191

9292
# If you want to use a crate with local modifications, you can set a path or git dependency here.
9393
# For git dependencies, also add your source to ALLOWED_SOURCES in src/tools/tidy/src/extdeps.rs.
94-
#[patch.crates-io]
95-
94+
[patch.crates-io]
95+
wasmtime-internal-wit-bindgen = { path = "./vendored/wit-bindgen" }

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ ignore = [
4747
"src/tools/rustc-perf",
4848
"src/tools/rustfmt",
4949
"src/gcc",
50+
"vendored",
5051

5152
# These are ignored by a standard cargo fmt run.
5253
"compiler/rustc_codegen_cranelift/scripts",

vendored/wit-bindgen/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "wasmtime-internal-wit-bindgen"
3+
version = "46.0.0"
4+
description = "INTERNAL: `*.wit` support for the `wasmtime` crate's macros"
5+
license = "Apache-2.0 WITH LLVM-exception"
6+
repository = "https://github.com/bytecodealliance/wasmtime"
7+
documentation = "https://docs.rs/wasmtime-wit-bindgen/"
8+
edition = "2024"
9+
rust-version = "1.94.0"
10+
11+
[dependencies]
12+
anyhow = "1"
13+
heck = "0.5.0"
14+
wit-parser = "0.251.0"
15+
indexmap = { version = "2.14.0", default-features = false, features = ['std'] }
16+
bitflags = "2.9.4"
17+
18+
[features]
19+
async = []
20+
component-model-async = []

vendored/wit-bindgen/src/config.rs

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
use crate::{LookupItem, lookup_keys};
2+
use anyhow::Result;
3+
use wit_parser::{Function, FunctionKind, Resolve, WorldKey};
4+
5+
bitflags::bitflags! {
6+
#[derive(Default, Copy, Clone, Debug)]
7+
pub struct FunctionFlags: u8 {
8+
const ASYNC = 1 << 0;
9+
const TRAPPABLE = 1 << 1;
10+
const STORE = 1 << 2;
11+
const TRACING = 1 << 3;
12+
const VERBOSE_TRACING = 1 << 4;
13+
const IGNORE_WIT = 1 << 5;
14+
const EXACT = 1 << 6;
15+
}
16+
}
17+
18+
#[derive(Default, Debug, Clone)]
19+
pub struct FunctionConfig {
20+
rules: Vec<FunctionRule>,
21+
pub(crate) default: FunctionFlags,
22+
}
23+
24+
#[derive(Debug, Clone)]
25+
struct FunctionRule {
26+
filter: String,
27+
flags: FunctionFlags,
28+
used: bool,
29+
}
30+
31+
#[derive(Debug, Clone)]
32+
pub enum FunctionFilter {
33+
Name(String),
34+
Default,
35+
}
36+
37+
impl FunctionConfig {
38+
/// Creates a blank set of configuration.
39+
pub fn new() -> FunctionConfig {
40+
FunctionConfig::default()
41+
}
42+
43+
/// Adds a new rule to this configuration.
44+
///
45+
/// Note that the order rules are added is significant as only the first
46+
/// matching rule is used for a function.
47+
pub fn push(&mut self, filter: FunctionFilter, flags: FunctionFlags) {
48+
match filter {
49+
FunctionFilter::Name(filter) => {
50+
self.rules.push(FunctionRule {
51+
filter,
52+
flags,
53+
used: false,
54+
});
55+
}
56+
FunctionFilter::Default => {
57+
self.default = flags;
58+
}
59+
}
60+
}
61+
62+
/// Returns the set of configuration flags associated with `func`.
63+
///
64+
/// The `name` provided should include the full name of the function
65+
/// including its interface. The `kind` is the classification of the
66+
/// function in WIT which affects the default set of flags.
67+
pub(crate) fn flags(
68+
&mut self,
69+
resolve: &Resolve,
70+
ns: Option<&WorldKey>,
71+
func: &Function,
72+
) -> FunctionFlags {
73+
let mut wit_flags = FunctionFlags::empty();
74+
75+
// If the kind is async, then set the async/store flags as that's a
76+
// concurrent function which requires access to both.
77+
match &func.kind {
78+
FunctionKind::Freestanding
79+
| FunctionKind::Method(_)
80+
| FunctionKind::Static(_)
81+
| FunctionKind::Constructor(_) => {}
82+
83+
FunctionKind::AsyncFreestanding
84+
| FunctionKind::AsyncMethod(_)
85+
| FunctionKind::AsyncStatic(_) => {
86+
wit_flags |= FunctionFlags::ASYNC | FunctionFlags::STORE;
87+
}
88+
}
89+
90+
let mut ret = FunctionFlags::empty();
91+
self.add_function_flags(resolve, ns, &func.name, &mut ret);
92+
if !ret.contains(FunctionFlags::IGNORE_WIT) {
93+
ret |= wit_flags;
94+
}
95+
ret
96+
}
97+
98+
pub(crate) fn resource_drop_flags(
99+
&mut self,
100+
resolve: &Resolve,
101+
ns: Option<&WorldKey>,
102+
resource_name: &str,
103+
) -> FunctionFlags {
104+
let mut ret = FunctionFlags::empty();
105+
self.add_function_flags(resolve, ns, &format!("[drop]{resource_name}"), &mut ret);
106+
ret
107+
}
108+
109+
fn add_function_flags(
110+
&mut self,
111+
resolve: &Resolve,
112+
key: Option<&WorldKey>,
113+
name: &str,
114+
base: &mut FunctionFlags,
115+
) {
116+
let mut apply_rules = |name: &str, is_exact: bool| {
117+
for rule in self.rules.iter_mut() {
118+
if name != rule.filter {
119+
continue;
120+
}
121+
if !is_exact && rule.flags.contains(FunctionFlags::EXACT) {
122+
continue;
123+
}
124+
rule.used = true;
125+
*base |= rule.flags;
126+
127+
// only the first rule is used.
128+
return true;
129+
}
130+
131+
false
132+
};
133+
match key {
134+
Some(key) => {
135+
for (lookup, projection) in lookup_keys(resolve, key, LookupItem::Name(name)) {
136+
if apply_rules(&lookup, projection.is_empty()) {
137+
return;
138+
}
139+
}
140+
}
141+
None => {
142+
if apply_rules(name, true) {
143+
return;
144+
}
145+
}
146+
}
147+
148+
*base |= self.default;
149+
}
150+
151+
pub(crate) fn assert_all_rules_used(&self, kind: &str) -> Result<()> {
152+
let mut unused = Vec::new();
153+
for rule in self.rules.iter().filter(|r| !r.used) {
154+
unused.push(format!("{:?}: {:?}", rule.filter, rule.flags));
155+
}
156+
157+
if unused.is_empty() {
158+
return Ok(());
159+
}
160+
161+
anyhow::bail!("unused `{kind}` rules found: {unused:?}");
162+
}
163+
}

0 commit comments

Comments
 (0)