Coder Social home page Coder Social logo

Comments (2)

chris-morgan avatar chris-morgan commented on September 28, 2024

The failures I observe are all connected to Windows.Foundation.GuidHelper.Equals.

I made these changes to allow it to continue in case of error:

diff --git a/Generator/Types/ClassDef.cs b/Generator/Types/ClassDef.cs
index 69a8ddc..0daec82 100644
--- a/Generator/Types/ClassDef.cs
+++ b/Generator/Types/ClassDef.cs
@@ -60,7 +60,14 @@ namespace Generator.Types
             }
             foreach (var m in staticMethods)
             {
-                methodWrappers.Add(new ClassMethodDef(m, this, false));
+                try
+                {
+                    methodWrappers.Add(new ClassMethodDef(m, this, false));
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("Failed class static method, skipping: " + this + "→" + m);
+                }
             }

             // fix name clashes in method wrappers (caused by overloads from different interfaces)
diff --git a/Generator/Types/InterfaceDef.cs b/Generator/Types/InterfaceDef.cs
index 9d6cc7f..536a33e 100644
--- a/Generator/Types/InterfaceDef.cs
+++ b/Generator/Types/InterfaceDef.cs
@@ -59,8 +59,30 @@ namespace Generator.Types

             InterfaceKind = GetInterfaceKind(Generator, this, exclusiveToType);

-            rawMethodDeclarations = methods.Select(m => m.GetRawDeclaration()).ToList();
-            wrapperMethodDeclarations = methods.Select(m => m.GetWrapperDefinition()).ToList();
+            rawMethodDeclarations = new List<string>();
+            foreach (var m in methods)
+            {
+                try
+                {
+                    rawMethodDeclarations.Add(m.GetRawDeclaration());
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("Failed interface raw method declaration, skipping: " + this + "→" + m);
+                }
+            }
+            wrapperMethodDeclarations = new List<string>();
+            foreach (var m in methods)
+            {
+                try
+                {
+                    wrapperMethodDeclarations.Add(m.GetWrapperDefinition());
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("Failed interface wrapper method declaration, skipping: " + this + "→" + m);
+                }
+            }
         }

         public override void Emit()

This causes it to seem to run successfully, with the following console output which confirms the problem to be localised to one method (and its variants):

Failed class static method, skipping: Windows.Foundation.GuidHelper→Equals
Failed interface raw method declaration, skipping: Windows.Foundation.IGuidHelperStatics→Equals
Failed interface wrapper method declaration, skipping: Windows.Foundation.IGuidHelperStatics→Equals

from winrt-rust.

Boddlnagg avatar Boddlnagg commented on September 28, 2024

This is interesting! This method has two parameters that are apparently typed as const references. They have this additional modifier System.Runtime.CompilerServices.IsConst, which I've never seen before.

MSDN says: (https://docs.microsoft.com/de-de/dotnet/api/system.runtime.compilerservices.isconst)

The Microsoft C++ compiler emits this modifier into metadata for any parameter, return type, or object declaration declared as const in the source code.

The ECMA Partition II documentation for CLI says:

The CLI itself shall treat required and optional modifiers in the same manner. Two signatures that differ only by the addition of a custom modifier (required or optional) shall not be considered to match. Custom modifiers have no other effect on the operation of the VES.
[Rationale: The distinction between required and optional modifiers is important to tools other than the CLI that deal with the metadata, typically compilers and program analysers. A required modifier indicates that there is a special semantics to the modified item that should not be ignored, while an optional modifier can simply be ignored.
For example, the const qualifier in the C programming language can be modelled with an optional modifier since the caller of a method that has a const-qualified parameter need not treat it in any special way. On the other hand, a parameter that shall be copy-constructed in C++ shall be marked with a required custom attribute since it is the caller who makes the copy. end rationale]

So this means that in this case I can emit a *const Guid instead of a *mut Guid (or simply ignore it, because there's not really a difference between *const and *mut).

Update:

Actually, there never have been reference input parameters before: *mut Guid previously only existed as an output parameter, but now we have *const Guid as input, which maps to &Guid in the wrapper. Every other method before that took a value type parameter did receive it by value.

Also, ILSpy shows this signature as bool Equals([In] ref Guid target, [In] ref Guid value);.

I have a fix for the generator ready, just need to test if the generated code actually is correct and works.

from winrt-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.