Skip to content

Commit 754328b

Browse files
authored
Merge pull request #1589 from alexcrichton/clamped
Remove the `Clamped` descriptor type
2 parents c0df37b + 621fc9c commit 754328b

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

crates/cli-support/src/anyref.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ fn process_closure_arguments(cfg: &mut Context, function: &mut Function) {
8282
| Descriptor::RefMut(d)
8383
| Descriptor::Option(d)
8484
| Descriptor::Slice(d)
85-
| Descriptor::Clamped(d)
8685
| Descriptor::Vector(d) => process_descriptor(cfg, d),
8786
Descriptor::Closure(c) => process_closure(cfg, c),
8887
Descriptor::Function(c) => process_function(cfg, c),

crates/cli-support/src/descriptor.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ tys! {
4242
pub enum Descriptor {
4343
I8,
4444
U8,
45+
ClampedU8,
4546
I16,
4647
U16,
4748
I32,
@@ -64,7 +65,6 @@ pub enum Descriptor {
6465
Char,
6566
Option(Box<Descriptor>),
6667
Unit,
67-
Clamped(Box<Descriptor>),
6868
}
6969

7070
#[derive(Debug, Clone)]
@@ -105,17 +105,18 @@ pub struct Number {
105105

106106
impl Descriptor {
107107
pub fn decode(mut data: &[u32]) -> Descriptor {
108-
let descriptor = Descriptor::_decode(&mut data);
108+
let descriptor = Descriptor::_decode(&mut data, false);
109109
assert!(data.is_empty(), "remaining data {:?}", data);
110110
descriptor
111111
}
112112

113-
fn _decode(data: &mut &[u32]) -> Descriptor {
113+
fn _decode(data: &mut &[u32], clamped: bool) -> Descriptor {
114114
match get(data) {
115115
I8 => Descriptor::I8,
116116
I16 => Descriptor::I16,
117117
I32 => Descriptor::I32,
118118
I64 => Descriptor::I64,
119+
U8 if clamped => Descriptor::ClampedU8,
119120
U8 => Descriptor::U8,
120121
U16 => Descriptor::U16,
121122
U32 => Descriptor::U32,
@@ -125,11 +126,11 @@ impl Descriptor {
125126
BOOLEAN => Descriptor::Boolean,
126127
FUNCTION => Descriptor::Function(Box::new(Function::decode(data))),
127128
CLOSURE => Descriptor::Closure(Box::new(Closure::decode(data))),
128-
REF => Descriptor::Ref(Box::new(Descriptor::_decode(data))),
129-
REFMUT => Descriptor::RefMut(Box::new(Descriptor::_decode(data))),
130-
SLICE => Descriptor::Slice(Box::new(Descriptor::_decode(data))),
131-
VECTOR => Descriptor::Vector(Box::new(Descriptor::_decode(data))),
132-
OPTIONAL => Descriptor::Option(Box::new(Descriptor::_decode(data))),
129+
REF => Descriptor::Ref(Box::new(Descriptor::_decode(data, clamped))),
130+
REFMUT => Descriptor::RefMut(Box::new(Descriptor::_decode(data, clamped))),
131+
SLICE => Descriptor::Slice(Box::new(Descriptor::_decode(data, clamped))),
132+
VECTOR => Descriptor::Vector(Box::new(Descriptor::_decode(data, clamped))),
133+
OPTIONAL => Descriptor::Option(Box::new(Descriptor::_decode(data, clamped))),
133134
STRING => Descriptor::String,
134135
ANYREF => Descriptor::Anyref,
135136
ENUM => Descriptor::Enum { hole: get(data) },
@@ -141,7 +142,7 @@ impl Descriptor {
141142
}
142143
CHAR => Descriptor::Char,
143144
UNIT => Descriptor::Unit,
144-
CLAMPED => Descriptor::Clamped(Box::new(Descriptor::_decode(data))),
145+
CLAMPED => Descriptor::_decode(data, true),
145146
other => panic!("unknown descriptor: {}", other),
146147
}
147148
}
@@ -217,6 +218,7 @@ impl Descriptor {
217218
let inner = match *self {
218219
Descriptor::String => return Some(VectorKind::String),
219220
Descriptor::Vector(ref d) => &**d,
221+
Descriptor::Slice(ref d) => &**d,
220222
Descriptor::Ref(ref d) => match **d {
221223
Descriptor::Slice(ref d) => &**d,
222224
Descriptor::String => return Some(VectorKind::String),
@@ -226,10 +228,6 @@ impl Descriptor {
226228
Descriptor::Slice(ref d) => &**d,
227229
_ => return None,
228230
},
229-
Descriptor::Clamped(ref d) => match d.vector_kind()? {
230-
VectorKind::U8 => return Some(VectorKind::ClampedU8),
231-
_ => return None,
232-
},
233231
_ => return None,
234232
};
235233
match *inner {
@@ -238,6 +236,7 @@ impl Descriptor {
238236
Descriptor::I32 => Some(VectorKind::I32),
239237
Descriptor::I64 => Some(VectorKind::I64),
240238
Descriptor::U8 => Some(VectorKind::U8),
239+
Descriptor::ClampedU8 => Some(VectorKind::ClampedU8),
241240
Descriptor::U16 => Some(VectorKind::U16),
242241
Descriptor::U32 => Some(VectorKind::U32),
243242
Descriptor::U64 => Some(VectorKind::U64),
@@ -279,13 +278,6 @@ impl Descriptor {
279278
}
280279
}
281280

282-
pub fn is_clamped_by_ref(&self) -> bool {
283-
match self {
284-
Descriptor::Clamped(d) => d.is_by_ref(),
285-
_ => false,
286-
}
287-
}
288-
289281
pub fn is_mut_ref(&self) -> bool {
290282
match *self {
291283
Descriptor::RefMut(_) => true,
@@ -396,12 +388,12 @@ impl Function {
396388
fn decode(data: &mut &[u32]) -> Function {
397389
let shim_idx = get(data);
398390
let arguments = (0..get(data))
399-
.map(|_| Descriptor::_decode(data))
391+
.map(|_| Descriptor::_decode(data, false))
400392
.collect::<Vec<_>>();
401393
Function {
402394
arguments,
403395
shim_idx,
404-
ret: Descriptor::_decode(data),
396+
ret: Descriptor::_decode(data, false),
405397
}
406398
}
407399
}

crates/cli-support/src/js/js2rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
204204
i = i,
205205
val = val,
206206
));
207-
if arg.is_by_ref() || arg.is_clamped_by_ref() {
207+
if arg.is_by_ref() {
208208
if optional {
209209
bail!("optional slices aren't currently supported");
210210
}

crates/cli-support/src/js/rust2js.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
165165
},
166166
));
167167

168-
if !arg.is_by_ref() && !arg.is_clamped_by_ref() {
168+
if !arg.is_by_ref() {
169169
self.prelude(&format!(
170170
"\
171171
{start}

0 commit comments

Comments
 (0)