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

write iasync info #83

Merged
merged 6 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions swiftwinrt/abi_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ namespace swiftwinrt
// on the swift side
static std::set<std::string_view> removed_types = {
"Windows.Foundation.Collections.CollectionChange",
"Windows.Foundation.Collections.IVectorChangedEventArgs"
};

"Windows.Foundation.Collections.IVectorChangedEventArgs",
};
static bool should_write(metadata_type const& type)
{
return !removed_types.contains(type.swift_full_name());
Expand All @@ -115,7 +114,6 @@ namespace swiftwinrt
// Forced dependencies
w.write(R"^-^(// Header files for imported files
#include "inspectable.h"
#include "AsyncInfo.h"
#include "EventToken.h"
#include "windowscontracts.h"
)^-^");
Expand Down
9 changes: 3 additions & 6 deletions swiftwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ namespace swiftwinrt
{
static void write_enum_def(writer& w, enum_type const& type)
{
// Async status is defined in it's own header with a nice name of AsyncStatus.
// Metadata attributes don't have backing code
if (get_full_type_name(type) == "Windows.Foundation.AsyncStatus" ||
type.swift_logical_namespace() == "Windows.Foundation.Metadata" || !can_write(w, type))
if (type.swift_logical_namespace() == "Windows.Foundation.Metadata" || !can_write(w, type))
{
return;
}
Expand All @@ -19,8 +17,7 @@ namespace swiftwinrt

static void write_enum_extension(writer& w, enum_type const& type)
{
if (get_full_type_name(type) == "Windows.Foundation.AsyncStatus" ||
type.swift_logical_namespace() == "Windows.Foundation.Metadata" || !can_write(w, type))
if (type.swift_logical_namespace() == "Windows.Foundation.Metadata" || !can_write(w, type))
{
return;
}
Expand Down Expand Up @@ -1184,7 +1181,7 @@ public static func makeAbi() -> CABI {
auto implements = w.write_temp("%", bind_each([&](writer& w, std::pair<std::string, interface_info> const& iface) {
s();
write_swift_type_identifier(w, *iface.second.type);
}, interfaces));
}, interfaces));

// check the type name is a collection so we don't get any potential unknown or unwanted
// typenames like IMapChangedEventArgs
Expand Down
5 changes: 0 additions & 5 deletions swiftwinrt/code_writers/can_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ namespace swiftwinrt
{
return can_write(w, *typed);
}
if (auto mapped = dynamic_cast<const mapped_type*>(type))
{
// TODO: https://linear.app/the-browser-company/issue/WIN-103/swiftwinrt-write-iasyncinfo
if (mapped->type().TypeName() == "IAsyncInfo") return false;
}
return true;
}

Expand Down
8 changes: 8 additions & 0 deletions swiftwinrt/file_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ namespace swiftwinrt
auto package_template = find_resource(RESOURCE_TYPE_OTHER_FILE_STR, RESOURCE_NAME_CWINRT_PACKAGE_SWIFT_STR);
fill_template_placeholders_to_file(package_template, dir_path / "Package.swift");
}

auto support_files = get_named_resources_of_type(
GetModuleHandle(NULL), RESOURCE_TYPE_C_INCLUDE_FILE_STR, /* make_lowercase: */ true);
stevenbrix marked this conversation as resolved.
Show resolved Hide resolved
for (const auto& support_file : support_files)
{
auto path = dir_path / "include" / (support_file.first + ".h");
fill_template_placeholders_to_file(support_file.second, path);
}
}

static void write_namespace_abi(std::string_view const& ns, type_cache const& members, include_only_used_filter const& filter)
Expand Down
1 change: 0 additions & 1 deletion swiftwinrt/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,6 @@ namespace swiftwinrt
}
if (mapped->swift_type_name() == "EventRegistrationToken") return param_category::struct_type;
if (mapped->swift_type_name() == "IAsyncInfo") return param_category::object_type;
if (mapped->swift_type_name() == "AsyncStatus") return param_category::enum_type;
if (mapped->swift_type_name() == "HResult") return param_category::fundamental_type;
assert(false); // unexpected mapped type
}
Expand Down
2 changes: 1 addition & 1 deletion swiftwinrt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ Where <spec> is one or more of:

for (auto& ns : namespaces)
{
module_group.add([&, &ns = ns]
module_group.add([&, &ns = ns]
stevenbrix marked this conversation as resolved.
Show resolved Hide resolved
{
auto types = mdCache.compile_namespaces({ ns }, mf);
write_namespace_abi (ns, types, mf);
Expand Down
27 changes: 1 addition & 26 deletions swiftwinrt/metadata_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ void metadata_cache::process_namespace_types(
target.enums.reserve(members.enums.size());
for (auto const& e : members.enums)
{
// 'AsyncStatus' is an enum
if (isFoundationNamespace)
{
if (auto ptr = mapped_type::from_typedef(e))
{
[[maybe_unused]] auto [itr, added] = table.emplace(e.TypeName(), *ptr);
XLANG_ASSERT(added);
continue;
}
}

target.enums.emplace_back(e);
[[maybe_unused]] auto [itr, added] = table.emplace(e.TypeName(), target.enums.back());
XLANG_ASSERT(added);
Expand Down Expand Up @@ -113,16 +102,6 @@ void metadata_cache::process_namespace_types(
target.interfaces.reserve(members.interfaces.size());
for (auto const& i : members.interfaces)
{
// 'IAsyncInfo' is an interface
if (isFoundationNamespace)
{
if (auto ptr = mapped_type::from_typedef(i))
{
[[maybe_unused]] auto [itr, added] = table.emplace(i.TypeName(), *ptr);
XLANG_ASSERT(added);
continue;
}
}
target.interfaces.emplace_back(i);
[[maybe_unused]] auto [itr, added] = table.emplace(i.TypeName(), target.interfaces.back());
XLANG_ASSERT(added);
Expand Down Expand Up @@ -473,11 +452,7 @@ void metadata_cache::process_interface_dependencies(init_state& state, interface

for (auto const& interfaces : get_interfaces(state, type.type()))
{
// TODO: https://linear.app/the-browser-company/issue/WIN-103/swiftwinrt-write-iasyncinfo
if (!interfaces.first.ends_with("IAsyncInfo"))
{
type.required_interfaces.push_back(interfaces);
}
type.required_interfaces.push_back(interfaces);
}

for (auto const& method : type.type().MethodList())
Expand Down
10 changes: 9 additions & 1 deletion swiftwinrt/metadata_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace swiftwinrt

inline void add_interface_dependencies_to_queue(processing_queue& to_process, interface_type const& type)
{
for (auto& member : type.functions)
for (const auto& member : type.functions)
{
if (member.return_type)
{
Expand All @@ -45,7 +45,15 @@ namespace swiftwinrt
to_process.emplace(param.type);
}
}
for (const auto& prop : type.properties)
{
to_process.emplace(prop.type);
}

for (const auto& event: type.events)
stevenbrix marked this conversation as resolved.
Show resolved Hide resolved
{
to_process.emplace(event.type);
}
for (auto& [_, required] : type.required_interfaces)
{
to_process.emplace(required.type);
Expand Down
3 changes: 3 additions & 0 deletions swiftwinrt/resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#define RESOURCE_TYPE_SWIFT_SUPPORT_FILE SWIFT_SUPPORT_FILE
#define RESOURCE_TYPE_SWIFT_SUPPORT_FILE_STR "SWIFT_SUPPORT_FILE"

#define RESOURCE_TYPE_C_INCLUDE_FILE C_HEADER_FILE
#define RESOURCE_TYPE_C_INCLUDE_FILE_STR "C_HEADER_FILE"

#define RESOURCE_TYPE_OTHER_FILE OTHER_FILE
#define RESOURCE_TYPE_OTHER_FILE_STR "OTHER_FILE"

Expand Down
2 changes: 1 addition & 1 deletion swiftwinrt/resources.rc
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ EventSource RESOURCE_TYPE_SWIFT_SUPPORT_FILE "Resources\\Support\\Events\\EventS
WinRTDelegate RESOURCE_TYPE_SWIFT_SUPPORT_FILE "Resources\\Support\\Events\\WinRTDelegate.swift"

RESOURCE_NAME_CWINRT_SHIM_C RESOURCE_TYPE_OTHER_FILE "Resources\\CWinRT\\shim.c"
RESOURCE_NAME_CWINRT_PACKAGE_SWIFT RESOURCE_TYPE_OTHER_FILE "Resources\\CWinRT\\Package.swift"
RESOURCE_NAME_CWINRT_PACKAGE_SWIFT RESOURCE_TYPE_OTHER_FILE "Resources\\CWinRT\\Package.swift"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#pragma once
// Header files for imported files
#include "inspectable.h"
#include "AsyncInfo.h"
#include "EventToken.h"
#include "windowscontracts.h"
#include "Windows.Foundation.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#pragma once
// Header files for imported files
#include "inspectable.h"
#include "AsyncInfo.h"
#include "EventToken.h"
#include "windowscontracts.h"
#include "Windows.Foundation.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ private var IID___x_ABI_CWindows_CFoundation_CIAsyncAction: IID {
IID(Data1: 0x5A648006, Data2: 0x843A, Data3: 0x4DA9, Data4: ( 0x86,0x5B,0x9D,0x26,0xE5,0xDF,0xAD,0x7B ))// 5A648006-843A-4DA9-865B-9D26E5DFAD7B
}

private var IID___x_ABI_CWindows_CFoundation_CIAsyncInfo: IID {
IID(Data1: 0x00000036, Data2: 0x0000, Data3: 0x0000, Data4: ( 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 ))// 00000036-0000-0000-C000-000000000046
}

private var IID___x_ABI_CWindows_CFoundation_CIClosable: IID {
IID(Data1: 0x30D5A829, Data2: 0x7FA4, Data3: 0x4026, Data4: ( 0x83,0xBB,0xD7,0x5B,0xAE,0x4E,0xA9,0x9E ))// 30D5A829-7FA4-4026-83BB-D75BAE4EA99E
}
Expand Down Expand Up @@ -79,11 +83,12 @@ public enum __ABI_Windows_Foundation {

GetIids: {
let size = MemoryLayout<IID>.size
let iids = CoTaskMemAlloc(UInt64(size) * 3).assumingMemoryBound(to: IID.self)
let iids = CoTaskMemAlloc(UInt64(size) * 4).assumingMemoryBound(to: IID.self)
stevenbrix marked this conversation as resolved.
Show resolved Hide resolved
iids[0] = IUnknown.IID
iids[1] = IInspectable.IID
iids[2] = __ABI_Windows_Foundation.IAsyncActionWrapper.IID
$1!.pointee = 3
iids[3] = __ABI_Windows_Foundation.IAsyncInfoWrapper.IID
$1!.pointee = 4
$2!.pointee = iids
return S_OK
},
Expand Down Expand Up @@ -126,6 +131,140 @@ public enum __ABI_Windows_Foundation {
)

public typealias IAsyncActionWrapper = InterfaceWrapperBase<__IMPL_Windows_Foundation.IAsyncActionImpl>
open class IAsyncInfo: test_component.IInspectable {
override public class var IID: IID { IID___x_ABI_CWindows_CFoundation_CIAsyncInfo }

open func get_IdImpl() throws -> UINT32 {
var result: UINT32 = 0
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIAsyncInfo.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.get_Id(pThis, &result))
}
return result
}

open func get_StatusImpl() throws -> __x_ABI_CWindows_CFoundation_CAsyncStatus {
var result: __x_ABI_CWindows_CFoundation_CAsyncStatus = .init(0)
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIAsyncInfo.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.get_Status(pThis, &result))
}
return result
}

open func get_ErrorCodeImpl() throws -> HRESULT {
var result: HRESULT = 0
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIAsyncInfo.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.get_ErrorCode(pThis, &result))
}
return result
}

open func CancelImpl() throws {
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIAsyncInfo.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.Cancel(pThis))
}
}

open func CloseImpl() throws {
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIAsyncInfo.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.Close(pThis))
}
}

}

internal static var IAsyncInfoVTable: __x_ABI_CWindows_CFoundation_CIAsyncInfoVtbl = .init(
QueryInterface: {
guard let pUnk = $0, let riid = $1, let ppvObject = $2 else { return E_INVALIDARG }
ppvObject.pointee = nil

switch riid.pointee {
case IUnknown.IID, IInspectable.IID, ISwiftImplemented.IID, IAgileObject.IID, IAsyncInfoWrapper.IID:
_ = pUnk.pointee.lpVtbl.pointee.AddRef(pUnk)
ppvObject.pointee = UnsafeMutableRawPointer(pUnk)
return S_OK
default:
guard let instance = IAsyncInfoWrapper.tryUnwrapFrom(raw: pUnk),
let iUnknownRef = instance.queryInterface(riid.pointee) else { return failWith(err: E_NOINTERFACE )}
ppvObject.pointee = UnsafeMutableRawPointer(iUnknownRef.ref)
return S_OK

}
},

AddRef: {
guard let wrapper = IAsyncInfoWrapper.fromRaw($0) else { return 1 }
_ = wrapper.retain()
return ULONG(_getRetainCount(wrapper.takeUnretainedValue()))
},

Release: {
guard let wrapper = IAsyncInfoWrapper.fromRaw($0) else { return 1 }
return ULONG(_getRetainCount(wrapper.takeRetainedValue()))
},

GetIids: {
let size = MemoryLayout<IID>.size
let iids = CoTaskMemAlloc(UInt64(size) * 3).assumingMemoryBound(to: IID.self)
iids[0] = IUnknown.IID
iids[1] = IInspectable.IID
iids[2] = __ABI_Windows_Foundation.IAsyncInfoWrapper.IID
$1!.pointee = 3
$2!.pointee = iids
return S_OK
},

GetRuntimeClassName: {
_ = $0
let hstring = try! HString("Windows.Foundation.IAsyncInfo").detach()
$1!.pointee = hstring
return S_OK
},

GetTrustLevel: {
_ = $0
$1!.pointee = TrustLevel(rawValue: 0)
return S_OK
},

get_Id: {
guard let __unwrapped__instance = IAsyncInfoWrapper.tryUnwrapFrom(raw: $0) else { return E_INVALIDARG }
let result = __unwrapped__instance.id
$1?.initialize(to: result)
return S_OK
},

get_Status: {
guard let __unwrapped__instance = IAsyncInfoWrapper.tryUnwrapFrom(raw: $0) else { return E_INVALIDARG }
let result = __unwrapped__instance.status
$1?.initialize(to: result)
return S_OK
},

get_ErrorCode: {
guard let __unwrapped__instance = IAsyncInfoWrapper.tryUnwrapFrom(raw: $0) else { return E_INVALIDARG }
let result = __unwrapped__instance.errorCode
$1?.initialize(to: result)
return S_OK
},

Cancel: {
do {
guard let __unwrapped__instance = IAsyncInfoWrapper.tryUnwrapFrom(raw: $0) else { return E_INVALIDARG }
try __unwrapped__instance.cancel()
return S_OK
} catch { return failWith(err: E_FAIL) }
},

Close: {
do {
guard let __unwrapped__instance = IAsyncInfoWrapper.tryUnwrapFrom(raw: $0) else { return E_INVALIDARG }
try __unwrapped__instance.close()
return S_OK
} catch { return failWith(err: E_FAIL) }
}
)

public typealias IAsyncInfoWrapper = InterfaceWrapperBase<__IMPL_Windows_Foundation.IAsyncInfoImpl>
open class IClosable: test_component.IInspectable {
override public class var IID: IID { IID___x_ABI_CWindows_CFoundation_CIClosable }

Expand Down Expand Up @@ -761,7 +900,7 @@ extension __ABI_Windows_Foundation {
open class AsyncActionCompletedHandler: test_component.IUnknown {
override public class var IID: IID { IID___x_ABI_CWindows_CFoundation_CIAsyncActionCompletedHandler }

open func InvokeImpl(_ asyncInfo: UnsafeMutablePointer<__x_ABI_CWindows_CFoundation_CIAsyncAction>?, _ asyncStatus: AsyncStatus) throws {
open func InvokeImpl(_ asyncInfo: UnsafeMutablePointer<__x_ABI_CWindows_CFoundation_CIAsyncAction>?, _ asyncStatus: __x_ABI_CWindows_CFoundation_CAsyncStatus) throws {
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIAsyncActionCompletedHandler.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.Invoke(pThis, asyncInfo, asyncStatus))
}
Expand Down Expand Up @@ -800,7 +939,7 @@ extension __ABI_Windows_Foundation {
Invoke: {
guard let __unwrapped__instance = AsyncActionCompletedHandlerWrapper.tryUnwrapFrom(raw: $0) else { return E_INVALIDARG }
let asyncInfo: test_component.AnyIAsyncAction? = __ABI_Windows_Foundation.IAsyncActionWrapper.unwrapFrom(abi: $1)
let asyncStatus: AsyncStatus = $2
let asyncStatus: test_component.AsyncStatus = $2
__unwrapped__instance(asyncInfo, asyncStatus)
return S_OK
}
Expand Down
Loading