Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better COM overload mechanism #39

Open
marler8997 opened this issue Jul 16, 2024 · 0 comments
Open

Better COM overload mechanism #39

marler8997 opened this issue Jul 16, 2024 · 0 comments

Comments

@marler8997
Copy link
Collaborator

marler8997 commented Jul 16, 2024

Currently we have 2 ways of dealing with symbol conflicts when it comes to COM methods that rely on "overloading". If we have 2 methods within the same type/interface with the same name, we just start putting a number suffix, i.e. Foo, Foo2, Foo3 etc. For symbol conflicts across types an interfaces, they currently all go into their own type/namespace so they don't conflict right now, however, I'd like to include wrapper methods for all inherited interfaces directly in the COM type. To allow this, my current idea is to require all types with this issue to have a set of name variations for each overload. For example, if you have a method Foo1 defined multiple times, you'll need to specify a set of unique suffixes for each variation i.e. FooDog, FooCat, FooCamel, etc. With this mechanism it might be best to require all methods to have a non-empty suffix so as to make it easier for users to follow this pattern. In fact, it might be best to declare a function with the base name that asserts a compile error and lists the available overloads.

Another variation of this is we could have the base function take an enum and the corresponding function, i.e. Foo(.dog)(...), Foo(.cat)(...), Foo(.camel)(...).

Here's some example code exploring options:

const std = @import("std");

const Cat = struct { };
const Dog = struct { };
const Camel = struct { };

const Solution1 = struct {
    fn Foo(self: *Solution1) void {
        _ = self;
        @compileError("Foo has 3 overloads, FooCat, FooDog and FooCamel");
    }
    fn FooCat(self: *Solution1, _: *Cat) void { _ = self; }
    fn FooDog(self: *Solution1, _: *Dog) void { _ = self; }
    fn FooCamel(self: *Solution1, _: *Camel) void { _ = self; }
};

const Solution2 = struct {
    pub const FooOverload = enum {
        cat, dog, camel
    };
    fn FooFunc(comptime overload: FooOverload) type {
        return switch (overload) {
            .cat => fn(*Solution2, *Cat) void,
            .dog => fn(*Solution2, *Dog) void,
            .camel => fn(*Solution2, *Camel) void,
        };
    }
    fn Foo(comptime overload: FooOverload) FooFunc(overload) {
        return switch (overload) {
            .cat => (struct {
                pub fn f(self: *Solution2, _: *Cat) void {
                    _ = self;
                }
            }).f,
            else => @panic("todo"),
        };
    }
};

pub fn main() !void {
    var sol1: Solution1 = .{};
    var cat: Cat = .{};
    var dog: Dog = .{};
    var camel: Camel = .{};
    //sol1.Foo();
    sol1.FooCat(&cat);
    sol1.FooDog(&dog);
    sol1.FooCamel(&camel);

    var sol2_instance: Solution2 = .{};
    const sol2 = &sol2_instance;
    //sol2.Foo(.cat)(&cat); ??? can this even work ???
    Solution2.Foo(.cat)(sol2, &cat);
}

Looks like we have about 103 of these overloads within the same type/interface:

AI.MachineLearning.WinML.json -- IMLOperatorKernelContext -- GetOutputTensor
Data.HtmlHelp.json -- IITPropList -- Set
Data.HtmlHelp.json -- IITPropList -- SetPersist
Data.HtmlHelp.json -- IITWordWheel -- Lookup
Data.HtmlHelp.json -- IITResultSet -- Add
Data.HtmlHelp.json -- IITResultSet -- Set
Data.HtmlHelp.json -- IITResultSet -- GetColumn
Graphics.Direct2D.json -- ID2D1SvgStrokeDashArray -- UpdateDashes
Graphics.Direct2D.json -- ID2D1SvgStrokeDashArray -- GetDashes
Graphics.Direct2D.json -- ID2D1SvgElement -- SetAttributeValue
Graphics.Direct2D.json -- ID2D1SvgElement -- GetAttributeValue
Graphics.DirectComposition.json -- IDCompositionVisual -- SetOffsetX
Graphics.DirectComposition.json -- IDCompositionVisual -- SetOffsetY
Graphics.DirectComposition.json -- IDCompositionVisual -- SetTransform
Graphics.DirectComposition.json -- IDCompositionVisual -- SetClip
Graphics.DirectComposition.json -- IDCompositionTranslateTransform -- SetOffsetX
Graphics.DirectComposition.json -- IDCompositionTranslateTransform -- SetOffsetY
Graphics.DirectComposition.json -- IDCompositionScaleTransform -- SetScaleX
Graphics.DirectComposition.json -- IDCompositionScaleTransform -- SetScaleY
Graphics.DirectComposition.json -- IDCompositionScaleTransform -- SetCenterX
Graphics.DirectComposition.json -- IDCompositionScaleTransform -- SetCenterY
Graphics.DirectComposition.json -- IDCompositionRotateTransform -- SetAngle
Graphics.DirectComposition.json -- IDCompositionRotateTransform -- SetCenterX
Graphics.DirectComposition.json -- IDCompositionRotateTransform -- SetCenterY
Graphics.DirectComposition.json -- IDCompositionSkewTransform -- SetAngleX
Graphics.DirectComposition.json -- IDCompositionSkewTransform -- SetAngleY
Graphics.DirectComposition.json -- IDCompositionSkewTransform -- SetCenterX
Graphics.DirectComposition.json -- IDCompositionSkewTransform -- SetCenterY
Graphics.DirectComposition.json -- IDCompositionMatrixTransform -- SetMatrixElement
Graphics.DirectComposition.json -- IDCompositionEffectGroup -- SetOpacity
Graphics.DirectComposition.json -- IDCompositionTranslateTransform3D -- SetOffsetX
Graphics.DirectComposition.json -- IDCompositionTranslateTransform3D -- SetOffsetY
Graphics.DirectComposition.json -- IDCompositionTranslateTransform3D -- SetOffsetZ
Graphics.DirectComposition.json -- IDCompositionScaleTransform3D -- SetScaleX
Graphics.DirectComposition.json -- IDCompositionScaleTransform3D -- SetScaleY
Graphics.DirectComposition.json -- IDCompositionScaleTransform3D -- SetScaleZ
Graphics.DirectComposition.json -- IDCompositionScaleTransform3D -- SetCenterX
Graphics.DirectComposition.json -- IDCompositionScaleTransform3D -- SetCenterY
Graphics.DirectComposition.json -- IDCompositionScaleTransform3D -- SetCenterZ
Graphics.DirectComposition.json -- IDCompositionRotateTransform3D -- SetAngle
Graphics.DirectComposition.json -- IDCompositionRotateTransform3D -- SetAxisX
Graphics.DirectComposition.json -- IDCompositionRotateTransform3D -- SetAxisY
Graphics.DirectComposition.json -- IDCompositionRotateTransform3D -- SetAxisZ
Graphics.DirectComposition.json -- IDCompositionRotateTransform3D -- SetCenterX
Graphics.DirectComposition.json -- IDCompositionRotateTransform3D -- SetCenterY
Graphics.DirectComposition.json -- IDCompositionRotateTransform3D -- SetCenterZ
Graphics.DirectComposition.json -- IDCompositionMatrixTransform3D -- SetMatrixElement
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetLeft
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetTop
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetRight
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetBottom
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetTopLeftRadiusX
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetTopLeftRadiusY
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetTopRightRadiusX
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetTopRightRadiusY
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetBottomLeftRadiusX
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetBottomLeftRadiusY
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetBottomRightRadiusX
Graphics.DirectComposition.json -- IDCompositionRectangleClip -- SetBottomRightRadiusY
Graphics.DirectComposition.json -- IDCompositionVisual3 -- SetOffsetZ
Graphics.DirectComposition.json -- IDCompositionVisual3 -- SetOpacity
Graphics.DirectComposition.json -- IDCompositionVisual3 -- SetTransform
Graphics.DirectComposition.json -- IDCompositionGaussianBlurEffect -- SetStandardDeviation
Graphics.DirectComposition.json -- IDCompositionBrightnessEffect -- SetWhitePointX
Graphics.DirectComposition.json -- IDCompositionBrightnessEffect -- SetWhitePointY
Graphics.DirectComposition.json -- IDCompositionBrightnessEffect -- SetBlackPointX
Graphics.DirectComposition.json -- IDCompositionBrightnessEffect -- SetBlackPointY
Graphics.DirectComposition.json -- IDCompositionColorMatrixEffect -- SetMatrixElement
Graphics.DirectComposition.json -- IDCompositionShadowEffect -- SetStandardDeviation
Graphics.DirectComposition.json -- IDCompositionShadowEffect -- SetRed
Graphics.DirectComposition.json -- IDCompositionShadowEffect -- SetGreen
Graphics.DirectComposition.json -- IDCompositionShadowEffect -- SetBlue
Graphics.DirectComposition.json -- IDCompositionShadowEffect -- SetAlpha
Graphics.DirectComposition.json -- IDCompositionHueRotationEffect -- SetAngle
Graphics.DirectComposition.json -- IDCompositionSaturationEffect -- SetSaturation
Graphics.DirectComposition.json -- IDCompositionLinearTransferEffect -- SetRedYIntercept
Graphics.DirectComposition.json -- IDCompositionLinearTransferEffect -- SetRedSlope
Graphics.DirectComposition.json -- IDCompositionLinearTransferEffect -- SetGreenYIntercept
Graphics.DirectComposition.json -- IDCompositionLinearTransferEffect -- SetGreenSlope
Graphics.DirectComposition.json -- IDCompositionLinearTransferEffect -- SetBlueYIntercept
Graphics.DirectComposition.json -- IDCompositionLinearTransferEffect -- SetBlueSlope
Graphics.DirectComposition.json -- IDCompositionLinearTransferEffect -- SetAlphaYIntercept
Graphics.DirectComposition.json -- IDCompositionLinearTransferEffect -- SetAlphaSlope
Graphics.DirectComposition.json -- IDCompositionTableTransferEffect -- SetRedTableValue
Graphics.DirectComposition.json -- IDCompositionTableTransferEffect -- SetGreenTableValue
Graphics.DirectComposition.json -- IDCompositionTableTransferEffect -- SetBlueTableValue
Graphics.DirectComposition.json -- IDCompositionTableTransferEffect -- SetAlphaTableValue
Graphics.DirectComposition.json -- IDCompositionArithmeticCompositeEffect -- SetCoefficient1
Graphics.DirectComposition.json -- IDCompositionArithmeticCompositeEffect -- SetCoefficient2
Graphics.DirectComposition.json -- IDCompositionArithmeticCompositeEffect -- SetCoefficient3
Graphics.DirectComposition.json -- IDCompositionArithmeticCompositeEffect -- SetCoefficient4
Graphics.DirectComposition.json -- IDCompositionAffineTransform2DEffect -- SetTransformMatrixElement
Graphics.DirectComposition.json -- IDCompositionAffineTransform2DEffect -- SetSharpness
Graphics.DirectWrite.json -- IDWriteFactory3 -- CreateFontFaceReference
Graphics.DirectWrite.json -- IDWriteFontSet -- GetPropertyValues
Graphics.DirectWrite.json -- IDWriteFontSet -- GetMatchingFonts
Graphics.DirectWrite.json -- IDWriteFontSetBuilder -- AddFontFaceReference
Graphics.DirectWrite.json -- IDWriteGdiInterop1 -- GetFontSignature
Graphics.DirectWrite.json -- IDWriteFontFace4 -- GetGlyphImageFormats
Graphics.DirectWrite.json -- IDWriteFactory4 -- ComputeGlyphOrigins
Graphics.DirectWrite.json -- IDWriteFontSet1 -- GetFilteredFonts
Graphics.DirectWrite.json -- IDWriteFontSet1 -- GetFilteredFontIndices
Graphics.DirectWrite.json -- IDWriteFontSet1 -- GetFontAxisRanges

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant