Skip to content

Commit

Permalink
Remove sorting requirement for interface lists (#60541)
Browse files Browse the repository at this point in the history
Fixes #60454.
  • Loading branch information
MichalStrehovsky committed Nov 8, 2021
1 parent 704f023 commit b665721
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 50 deletions.
9 changes: 9 additions & 0 deletions docs/design/specs/Ecma-335-Augments.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This is a list of additions and edits to be made in ECMA-335 specifications. It
- [Signatures](#signatures)
- [Heap sizes](#heap-sizes)
- [Metadata merging](#metadata-merging)
- [Metadata logical format](#metadata-logical-format)
- [Module Initializer](#module-initializer)
- [Default Interface Methods](#default-interface-methods)
- [Static Interface Methods](#static-interface-methods)
Expand Down Expand Up @@ -362,6 +363,14 @@ This text should be deleted, and the _metadata merging_ entry should be removed
> * ~~If there are duplicates and two or more have an accessibility other than
> **compilercontrolled**, an error has occurred.~~
## Metadata logical format

The requirement to sort InterfaceImpl table using the Interface column as a secondary key in § II.22 _Metadata logical format: tables_ is a spec bug. The interface declaration order affects resolution and a requirement to sort it would make it impossible to emit certain sequences of interfaces (e.g. not possible to have an interface list I1, I2, while also having interface list I2, I1 elsewhere in the module).

The text should be deleted:

> Furthermore, ~~the InterfaceImpl table is sorted using the Interface column as a secondary key, and~~ the GenericParam table is sorted using the Number column as a secondary key.
## Module Initializer

All modules may have a module initializer. A module initializer is defined as the type initializer (§ II.10.5.3) of the `<Module>` type (§ II.10.8).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ internal void ValidateOrder()
// GenericParam Owner, Number No**
// GenericParamConstraint Owner No**
// ImplMap MemberForwarded No*
// InterfaceImpl Class, Interface No**
// InterfaceImpl Class No**
// MethodImpl Class No*
// MethodSemantics Association Yes
// NestedClass NestedClass No*
Expand Down Expand Up @@ -1551,27 +1551,12 @@ private void ValidateImplMapTable()

private void ValidateInterfaceImplTable()
{
if (_interfaceImplTable.Count == 0)
for (int i = 1; i < _interfaceImplTable.Count; i++)
{
return;
}

InterfaceImplRow current, previous = _interfaceImplTable[0];
for (int i = 1; i < _interfaceImplTable.Count; i++, previous = current)
{
current = _interfaceImplTable[i];

if (current.Class > previous.Class)
if (_interfaceImplTable[i - 1].Class > _interfaceImplTable[i].Class)
{
continue;
Throw.InvalidOperation_TableNotSorted(TableIndex.InterfaceImpl);
}

if (previous.Class == current.Class && current.Interface > previous.Interface)
{
continue;
}

Throw.InvalidOperation_TableNotSorted(TableIndex.InterfaceImpl);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,40 +803,10 @@ public void ValidateInterfaceImplTable()
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeDefinitionHandle(1));
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());

builder = new MetadataBuilder();
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeDefinitionHandle(1));
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeDefinitionHandle(1));
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());

builder = new MetadataBuilder();
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeDefinitionHandle(2));
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeDefinitionHandle(1));
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());

builder = new MetadataBuilder();
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeReferenceHandle(2));
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeReferenceHandle(1));
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());

builder = new MetadataBuilder();
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeSpecificationHandle(2));
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeSpecificationHandle(1));
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());

builder = new MetadataBuilder();
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeReferenceHandle(1));
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeDefinitionHandle(1));
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());

builder = new MetadataBuilder();
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeSpecificationHandle(1));
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeReferenceHandle(1));
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());

builder = new MetadataBuilder();
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeSpecificationHandle(1));
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeDefinitionHandle(1));
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());
builder.ValidateOrder(); // ok
}

[Fact]
Expand Down

0 comments on commit b665721

Please sign in to comment.