From be4ab5c44ca44d57871645b1c821aed529995fc0 Mon Sep 17 00:00:00 2001 From: James Courtney Date: Fri, 4 Aug 2023 19:19:19 -0700 Subject: [PATCH] Disallow a couple of new features (#393) * Disallow a couple of new features --- .github/workflows/dotnet.yml | 35 +++++++----------- src/FlatSharp.Compiler/MetadataKeys.cs | 2 +- src/FlatSharp.Compiler/Schema/BaseType.cs | 2 + src/FlatSharp/TypeModel/StructMemberModel.cs | 5 +++ .../InvalidAttributeTests.cs | 27 ++++++++++++++ .../FlatSharpTests/ClassLib/TypeModelTests.cs | 2 +- src/ext/flatc/macos_arm/flatc | Bin src/ext/flatc/macos_intel/flatc | Bin 8 files changed, 50 insertions(+), 23 deletions(-) mode change 100644 => 100755 src/ext/flatc/macos_arm/flatc mode change 100644 => 100755 src/ext/flatc/macos_intel/flatc diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index ac3656ee..75b74624 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -27,22 +27,7 @@ jobs: uses: actions/setup-dotnet@v1 with: dotnet-version: 6.0.x - - - if: runner.os == 'Linux' - name: chmod flatc (linux) - working-directory: src/ext/flatc - run: | - chmod 755 linux/flatc - shell: bash - - - if: runner.os == 'MacOS' - name: chmod flatc (mac) - working-directory: src/ext/flatc - run: | - chmod 755 macos_arm/flatc - chmod 755 macos_intel/flatc - shell: bash - + - name: Restore dependencies working-directory: src run: dotnet restore @@ -75,15 +60,23 @@ jobs: working-directory: src run: dotnet build -c Release /p:SignAssembly=true - - if: runner.os == 'Windows' - name: Test (All) - working-directory: src + - name: E2E Test + working-directory: src/Tests/FlatSharpEndToEndTests run: dotnet test -c Release /p:SignAssembly=true --verbosity normal - - name: Test (E2E) - working-directory: src/Tests/FlatSharpEndToEndTests + - name: Poolable E2E Test + working-directory: src/Tests/FlatSharpPoolableEndToEndTests + run: dotnet test -c Release /p:SignAssembly=true --verbosity normal + + - name: Compiler Test + working-directory: src/Tests/FlatSharpCompilerTests run: dotnet test -c Release /p:SignAssembly=true --verbosity normal + - if: runner.os == 'Windows' + name: Legacy Test + working-directory: src/Tests/FlatSharpTests + run: dotnet test -c Release /p:SignAssembly=true --verbosity normal + - if: runner.os == 'Windows' name: Upload Packages uses: actions/upload-artifact@v2 diff --git a/src/FlatSharp.Compiler/MetadataKeys.cs b/src/FlatSharp.Compiler/MetadataKeys.cs index 0373882f..3ec48dcc 100644 --- a/src/FlatSharp.Compiler/MetadataKeys.cs +++ b/src/FlatSharp.Compiler/MetadataKeys.cs @@ -153,6 +153,6 @@ public static class MetadataKeys public static IEnumerable UnsupportedStandardAttributes => new[] { - "force_align", "flexbuffer", "hash", "original_order" + "force_align", "flexbuffer", "hash", "original_order", "vector64" }; } diff --git a/src/FlatSharp.Compiler/Schema/BaseType.cs b/src/FlatSharp.Compiler/Schema/BaseType.cs index 0678cacf..e7d3d994 100644 --- a/src/FlatSharp.Compiler/Schema/BaseType.cs +++ b/src/FlatSharp.Compiler/Schema/BaseType.cs @@ -22,6 +22,7 @@ namespace FlatSharp.Compiler.Schema; public enum BaseType : byte { None, + UType, Bool, Byte, @@ -39,6 +40,7 @@ public enum BaseType : byte Obj, // Used for tables & structs. Union, Array, + Vector64, // Add any new type above this value. MaxBaseType diff --git a/src/FlatSharp/TypeModel/StructMemberModel.cs b/src/FlatSharp/TypeModel/StructMemberModel.cs index a10f65e8..79b8f0d3 100644 --- a/src/FlatSharp/TypeModel/StructMemberModel.cs +++ b/src/FlatSharp/TypeModel/StructMemberModel.cs @@ -52,6 +52,11 @@ internal override void Validate() { throw new InvalidFlatBufferDefinitionException($"Struct member '{this.FriendlyName}' declared the SharedString attribute. SharedString is not valid inside structs."); } + + if (this.Attribute.Key) + { + throw new InvalidFlatBufferDefinitionException($"Struct member '{this.FriendlyName}' declared the 'key' attribute. FlatSharp does not support keys on struct members."); + } } /// diff --git a/src/Tests/FlatSharpCompilerTests/InvalidAttributeTests.cs b/src/Tests/FlatSharpCompilerTests/InvalidAttributeTests.cs index 31d861f4..733259a1 100644 --- a/src/Tests/FlatSharpCompilerTests/InvalidAttributeTests.cs +++ b/src/Tests/FlatSharpCompilerTests/InvalidAttributeTests.cs @@ -14,6 +14,8 @@ * limitations under the License. */ +using FlatSharp.TypeModel; + namespace FlatSharpTests.Compiler; public class InvalidAttributeTests @@ -42,6 +44,18 @@ struct Foo { Value : [int : 4] (force_align: 2); } Assert.Contains("FlatSharp does not support the 'force_align' attribute.", ex.Message); } + [Fact] + public void UnsupportedAttribute_Vector64() + { + string schema = @" + namespace ns; + table Foo { Value : [ int ] (vector64); } + "; + + var ex = Assert.Throws(() => FlatSharpCompiler.CompileAndLoadAssembly(schema, new())); + Assert.Contains("FlatSharp does not support the 'vector64' attribute.", ex.Message); + } + [Fact] public void UnsupportedAttribute_ForceAlign_TableField() { @@ -116,6 +130,19 @@ namespace ns; Assert.Contains("FlatSharp does not support the 'original_order' attribute.", ex.Message); } + [Fact] + public void UnsupportedAttribute_KeyOnStruct() + { + string schema = @$" + {MetadataHelpers.AllAttributes} + namespace ns; + struct Bar {{ k : int (key); }} + "; + + var ex = Assert.Throws(() => FlatSharpCompiler.CompileAndLoadAssembly(schema, new())); + Assert.Contains("Struct member 'ns.Bar.K' declared the 'key' attribute. FlatSharp does not support keys on struct members.", ex.Message); + } + [Fact] public void FlatSharpEnumAttribute_FailsToParse() { diff --git a/src/Tests/FlatSharpTests/ClassLib/TypeModelTests.cs b/src/Tests/FlatSharpTests/ClassLib/TypeModelTests.cs index 093f817a..17ac096e 100644 --- a/src/Tests/FlatSharpTests/ClassLib/TypeModelTests.cs +++ b/src/Tests/FlatSharpTests/ClassLib/TypeModelTests.cs @@ -699,7 +699,7 @@ public void TypeModel_SortedVector_OfStruct_NotAllowed() { var ex = Assert.Throws(() => RuntimeTypeModel.CreateFrom(typeof(SortedVector>>))); - Assert.Equal("Property 'Vector' declares a sorted vector, but the member is not a table. Type = System.Collections.Generic.IList>.", ex.Message); + Assert.Equal("Struct member 'FlatSharpTests.TypeModelTests.SortedVectorKeyStruct.Key' declared the 'key' attribute. FlatSharp does not support keys on struct members.", ex.Message); } [Fact] diff --git a/src/ext/flatc/macos_arm/flatc b/src/ext/flatc/macos_arm/flatc old mode 100644 new mode 100755 diff --git a/src/ext/flatc/macos_intel/flatc b/src/ext/flatc/macos_intel/flatc old mode 100644 new mode 100755