Skip to content

Commit 5f12064

Browse files
authored
Merge pull request #294 from fitzgen/more-docs
Fill in some doc comments + tidy up some things
2 parents a804a0e + 3bce3fb commit 5f12064

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

crates/backend/src/ast.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use proc_macro2::{Ident, Span, TokenStream, TokenTree};
22
use quote::ToTokens;
33
use shared;
44
use syn;
5-
use syn::AttrStyle;
65

76
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
87
#[derive(Default)]
@@ -1126,7 +1125,7 @@ fn extract_doc_comments(attrs: &[syn::Attribute]) -> Vec<String> {
11261125
// We want to filter out any Puncts so just grab the Literals
11271126
a.tts.clone().into_iter().filter_map(|t| match t {
11281127
TokenTree::Literal(lit) => {
1129-
// this will always return the quoted string, we deal with
1128+
// this will always return the quoted string, we deal with
11301129
// that in the cli when we read in the comments
11311130
Some(lit.to_string())
11321131
},
@@ -1139,4 +1138,4 @@ fn extract_doc_comments(attrs: &[syn::Attribute]) -> Vec<String> {
11391138
})
11401139
//Fold up the [[String]] iter we created into Vec<String>
11411140
.fold(vec![], |mut acc, a| {acc.extend(a); acc})
1142-
}
1141+
}

crates/cli/src/bin/wasm2es6js.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ extern crate serde_derive;
33
extern crate docopt;
44
extern crate parity_wasm;
55
extern crate wasm_bindgen_cli_support;
6-
#[macro_use]
76
extern crate failure;
87

98
use std::fs::File;

src/closure.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ impl<T> Drop for Closure<T>
174174
///
175175
/// This trait is not stable and it's not recommended to use this in bounds or
176176
/// implement yourself.
177+
#[doc(hidden)]
177178
pub unsafe trait WasmClosure: 'static {
178179
fn describe();
179180

src/convert.rs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,59 @@ use describe::*;
1313
#[cfg(feature = "std")]
1414
use std::prelude::v1::*;
1515

16-
#[derive(PartialEq, Eq, Copy, Clone)]
17-
pub struct Descriptor {
18-
#[doc(hidden)]
19-
pub __x: [u8; 4],
20-
}
21-
16+
/// A trait for anything that can be converted into a type that can cross the
17+
/// wasm ABI directly, eg `u32` or `f64`.
18+
///
19+
/// This is the opposite operation as `FromWasmAbi` and `Ref[Mut]FromWasmAbi`.
2220
pub trait IntoWasmAbi: WasmDescribe {
21+
/// The wasm ABI type that this converts into when crossing the ABI
22+
/// boundary.
2323
type Abi: WasmAbi;
24+
25+
/// Convert `self` into `Self::Abi` so that it can be sent across the wasm
26+
/// ABI boundary.
2427
fn into_abi(self, extra: &mut Stack) -> Self::Abi;
2528
}
2629

30+
/// A trait for anything that can be recovered by-value from the wasm ABI
31+
/// boundary, eg a Rust `u8` can be recovered from the wasm ABI `u32` type.
32+
///
33+
/// This is the by-value variant of the opposite operation as `IntoWasmAbi`.
2734
pub trait FromWasmAbi: WasmDescribe {
35+
/// The wasm ABI type that this converts from when coming back out from the
36+
/// ABI boundary.
2837
type Abi: WasmAbi;
29-
unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self;
3038

39+
/// Recover a `Self` from `Self::Abi`.
40+
///
41+
/// # Safety
42+
///
43+
/// This is only safe to call when -- and implementations may assume that --
44+
/// the supplied `Self::Abi` was previously generated by a call to `<Self as
45+
/// IntoWasmAbi>::into_abi()` or the moral equivalent in JS.
46+
unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self;
3147
}
3248

49+
/// A trait for anything that can be recovered as some sort of shared reference
50+
/// from the wasm ABI boundary.
51+
///
52+
/// This is the shared reference variant of the opposite operation as
53+
/// `IntoWasmAbi`.
3354
pub trait RefFromWasmAbi: WasmDescribe {
55+
/// The wasm ABI type references to `Self` are recovered from.
3456
type Abi: WasmAbi;
57+
58+
/// The type that holds the reference to `Self` for the duration of the
59+
/// invocation of the function that has an `&Self` parameter. This is
60+
/// required to ensure that the lifetimes don't persist beyond one function
61+
/// call, and so that they remain anonymous.
3562
type Anchor: Deref<Target=Self>;
63+
64+
/// Recover a `Self::Anchor` from `Self::Abi`.
65+
///
66+
/// # Safety
67+
///
68+
/// Same as `FromWasmAbi::from_abi`.
3669
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor;
3770
}
3871

@@ -142,7 +175,7 @@ impl IntoWasmAbi for char {
142175

143176
impl FromWasmAbi for char {
144177
type Abi = u32;
145-
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> char {
178+
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> char {
146179
char::from_u32_unchecked(js)
147180
}
148181
}
@@ -539,4 +572,4 @@ stack_closures! {
539572
(A B C D E)
540573
(A B C D E F)
541574
(A B C D E F G)
542-
}
575+
}

0 commit comments

Comments
 (0)