Skip to content

Commit b9d14ef

Browse files
author
katelyn martin
committed
Revert "Enable more than one handle type in *.witx (WebAssembly#421)"
This reverts commit 834679b.
1 parent dbc1b13 commit b9d14ef

File tree

13 files changed

+48
-252
lines changed

13 files changed

+48
-252
lines changed

phases/ephemeral/witx/typenames.witx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,8 @@
281281
)
282282
)
283283

284-
(resource $fd)
285284
;;; A file descriptor handle.
286-
(typename $fd (handle $fd))
285+
(typename $fd (handle))
287286

288287
;;; A region of memory for scatter/gather reads.
289288
(typename $iovec

phases/old/snapshot_0/witx/typenames.witx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,8 @@
273273
)
274274
)
275275

276-
(resource $fd)
277276
;;; A file descriptor handle.
278-
(typename $fd (handle $fd))
277+
(typename $fd (handle))
279278

280279
;;; A region of memory for scatter/gather reads.
281280
(typename $iovec

phases/snapshot/witx/typenames.witx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,8 @@
273273
)
274274
)
275275

276-
(resource $fd)
277276
;;; A file descriptor handle.
278-
(typename $fd (handle $fd))
277+
(typename $fd (handle))
279278

280279
;;; A region of memory for scatter/gather reads.
281280
(typename $iovec

tools/witx/src/ast.rs

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ pub struct Module {
4545
types: Vec<Rc<NamedType>>,
4646
type_map: HashMap<Id, Rc<NamedType>>,
4747

48-
resources: Vec<Rc<Resource>>,
49-
resource_map: HashMap<Id, Rc<Resource>>,
50-
5148
funcs: Vec<Rc<Function>>,
5249
func_map: HashMap<Id, Rc<Function>>,
5350

@@ -64,8 +61,6 @@ impl Module {
6461
module_id,
6562
types: Default::default(),
6663
type_map: Default::default(),
67-
resources: Default::default(),
68-
resource_map: Default::default(),
6964
funcs: Default::default(),
7065
func_map: Default::default(),
7166
constants: Default::default(),
@@ -85,14 +80,6 @@ impl Module {
8580
self.types.push(ty);
8681
}
8782

88-
pub(crate) fn push_resource(&mut self, r: Rc<Resource>) {
89-
assert!(self
90-
.resource_map
91-
.insert(r.name.clone(), r.clone())
92-
.is_none());
93-
self.resources.push(r);
94-
}
95-
9683
pub(crate) fn push_func(&mut self, func: Rc<Function>) {
9784
assert!(self
9885
.func_map
@@ -113,14 +100,6 @@ impl Module {
113100
self.types.iter()
114101
}
115102

116-
pub fn resource(&self, name: &Id) -> Option<Rc<Resource>> {
117-
self.resource_map.get(name).cloned()
118-
}
119-
120-
pub fn resources<'a>(&'a self) -> impl Iterator<Item = &'a Rc<Resource>> + 'a {
121-
self.resources.iter()
122-
}
123-
124103
/// All of the (unique) types used as "err" variant of results returned from
125104
/// functions.
126105
pub fn error_types<'a>(&'a self) -> impl Iterator<Item = TypeRef> + 'a {
@@ -520,37 +499,11 @@ impl Case {
520499
}
521500

522501
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
523-
pub struct Resource {
524-
/// The local name within the module this resource is defined within. This
525-
/// may differ from the id of the resource itself.
526-
pub name: Id,
527-
/// The unique id assigned to this resource.
528-
pub resource_id: ResourceId,
529-
/// Documentation in the defining module, if any.
530-
pub docs: String,
531-
}
532-
533-
/// A unique id used to determine whether two handles are nominally referring
534-
/// to the same resource.
535-
///
536-
/// An id is composed of the definition location (a module id) and the original
537-
/// name within that module.
538-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
539-
pub struct ResourceId {
540-
pub name: Id,
541-
pub module_id: ModuleId,
542-
}
543-
544-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
545-
pub struct HandleDatatype {
546-
/// The resource that this handle references, used for determining if two
547-
/// handle types are nominally equal to one another.
548-
pub resource_id: ResourceId,
549-
}
502+
pub struct HandleDatatype {}
550503

551504
impl HandleDatatype {
552-
pub fn type_equal(&self, other: &HandleDatatype) -> bool {
553-
self.resource_id == other.resource_id
505+
pub fn type_equal(&self, _other: &HandleDatatype) -> bool {
506+
true
554507
}
555508
}
556509

tools/witx/src/parser.rs

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ mod kw {
3434
wast::custom_keyword!(noreturn);
3535
wast::custom_keyword!(pointer);
3636
wast::custom_keyword!(record);
37-
wast::custom_keyword!(r#as = "as");
3837
wast::custom_keyword!(r#const = "const");
3938
wast::custom_keyword!(r#enum = "enum");
4039
wast::custom_keyword!(r#union = "union");
4140
wast::custom_keyword!(r#use = "use");
4241
wast::custom_keyword!(repr);
43-
wast::custom_keyword!(resource);
4442
wast::custom_keyword!(s16);
4543
wast::custom_keyword!(s32);
4644
wast::custom_keyword!(s64);
@@ -229,7 +227,6 @@ impl<'a> Parse<'a> for TopLevelModule<'a> {
229227
if parser.peek2::<kw::r#use>()
230228
|| parser.peek2::<annotation::witx>()
231229
|| parser.peek2::<kw::typename>()
232-
|| parser.peek2::<kw::resource>()
233230
{
234231
decls.push(Documented {
235232
comments,
@@ -282,7 +279,6 @@ impl<'a> Parse<'a> for TopLevelSyntax<'a> {
282279
#[derive(Debug, Clone)]
283280
pub enum DeclSyntax<'a> {
284281
Typename(TypenameSyntax<'a>),
285-
Resource(ResourceSyntax<'a>),
286282
Const(Documented<'a, ConstSyntax<'a>>),
287283
}
288284

@@ -293,8 +289,6 @@ impl<'a> Parse<'a> for DeclSyntax<'a> {
293289
Ok(DeclSyntax::Typename(parser.parse()?))
294290
} else if l.peek::<annotation::witx>() {
295291
Ok(DeclSyntax::Const(parser.parse()?))
296-
} else if l.peek::<kw::resource>() {
297-
Ok(DeclSyntax::Resource(parser.parse()?))
298292
} else {
299293
Err(l.error())
300294
}
@@ -319,7 +313,7 @@ impl<'a> Parse<'a> for UseSyntax<'a> {
319313

320314
#[derive(Debug, Clone, PartialEq, Eq)]
321315
pub enum UsedNames<'a> {
322-
List(Vec<UseName<'a>>),
316+
List(Vec<wast::Id<'a>>),
323317
All(wast::Span),
324318
}
325319

@@ -339,32 +333,6 @@ impl<'a> Parse<'a> for UsedNames<'a> {
339333
}
340334
}
341335

342-
#[derive(Debug, Clone, PartialEq, Eq)]
343-
pub struct UseName<'a> {
344-
pub other_name: wast::Id<'a>,
345-
pub our_name: wast::Id<'a>,
346-
}
347-
348-
impl<'a> Parse<'a> for UseName<'a> {
349-
fn parse(parser: Parser<'a>) -> Result<Self> {
350-
let (other_name, our_name) = if parser.peek::<wast::Id>() {
351-
let name = parser.parse()?;
352-
(name, name)
353-
} else {
354-
parser.parens(|p| {
355-
let other_name = p.parse()?;
356-
p.parse::<kw::r#as>()?;
357-
let our_name = p.parse()?;
358-
Ok((other_name, our_name))
359-
})?
360-
};
361-
Ok(UseName {
362-
other_name,
363-
our_name,
364-
})
365-
}
366-
}
367-
368336
#[derive(Debug, Clone, PartialEq, Eq)]
369337
pub struct TypenameSyntax<'a> {
370338
pub ident: wast::Id<'a>,
@@ -389,7 +357,7 @@ pub enum TypedefSyntax<'a> {
389357
Record(RecordSyntax<'a>),
390358
Union(UnionSyntax<'a>),
391359
Variant(VariantSyntax<'a>),
392-
Handle(HandleSyntax<'a>),
360+
Handle(HandleSyntax),
393361
List(Box<TypedefSyntax<'a>>),
394362
Pointer(Box<TypedefSyntax<'a>>),
395363
ConstPointer(Box<TypedefSyntax<'a>>),
@@ -553,19 +521,6 @@ impl<'a> Parse<'a> for ConstSyntax<'a> {
553521
}
554522
}
555523

556-
#[derive(Debug, Clone, PartialEq, Eq)]
557-
pub struct ResourceSyntax<'a> {
558-
pub ident: wast::Id<'a>,
559-
}
560-
561-
impl<'a> Parse<'a> for ResourceSyntax<'a> {
562-
fn parse(parser: Parser<'a>) -> Result<Self> {
563-
parser.parse::<kw::resource>()?;
564-
let ident = parser.parse()?;
565-
Ok(ResourceSyntax { ident })
566-
}
567-
}
568-
569524
#[derive(Debug, Clone, PartialEq, Eq)]
570525
pub struct FlagsSyntax<'a> {
571526
pub repr: Option<BuiltinType>,
@@ -701,15 +656,12 @@ impl<'a> Parse<'a> for CaseSyntax<'a> {
701656
}
702657

703658
#[derive(Debug, Clone, PartialEq, Eq)]
704-
pub struct HandleSyntax<'a> {
705-
pub resource: wast::Id<'a>,
706-
}
659+
pub struct HandleSyntax {}
707660

708-
impl<'a> Parse<'a> for HandleSyntax<'a> {
661+
impl<'a> Parse<'a> for HandleSyntax {
709662
fn parse(parser: Parser<'a>) -> Result<Self> {
710663
parser.parse::<kw::handle>()?;
711-
let resource = parser.parse()?;
712-
Ok(HandleSyntax { resource })
664+
Ok(HandleSyntax {})
713665
}
714666
}
715667

tools/witx/src/toplevel.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,19 @@ mod test {
165165
e => panic!("wrong error: {:?}", e),
166166
}
167167
}
168+
169+
#[test]
170+
fn use_invalid() {
171+
match parse_witx_with("/a", &MockFs::new(&[("/a", "(use bbbbbbb)")]))
172+
.err()
173+
.unwrap()
174+
{
175+
WitxError::Parse(e) => {
176+
let err = e.to_string();
177+
assert!(err.contains("expected an identifier"), "bad error: {}", err);
178+
assert!(err.contains("/a:1:6"));
179+
}
180+
e => panic!("wrong error: {:?}", e),
181+
}
182+
}
168183
}

0 commit comments

Comments
 (0)