Skip to content

Conversation

@kennykerr
Copy link
Collaborator

Building on #3861, this update adds parsing support interface methods, covering most of the type system capabilities required for WinRT and Win32 method signatures. Here's an example of a .rdl interface:

mod Test {
    interface ITest {
        fn ToString(&self) -> String;
        fn Close(&self);
        fn Add(&self, a: u8, b: u16) -> u32;
        fn RefMut(&self, p: &mut u32);
        fn RefConst(&self, p: &u32);
        fn PtrMut(&self, p: *mut u32);
        fn PtrConst(&self, p: *const u32);
    }
}

As you can see, the sytax largely follows Rust, with the addition of the interface keyword. We could use the Rust trait keyword, but I'm worried that may be more confusing.

Most of it should be self-explanatory. The RefMut and RefConst method parameters are edge cases required by the WinRT type system for ref and out parameters, while the PtrMut and PtrConst method parameters are examples typically found in Win32 APIs. As you can imagine, .rdl will support both type systems but I still need to distinguish between them so you don't accidentally add non-WinRT types to a WinRT interface for example.

The reader will encode this interface into a .winmd file as follows:

.class interface public auto ansi abstract windowsruntime Test.ITest
{
	// Methods
	.method public hidebysig newslot abstract virtual 
		instance string ToString () cil managed 
	{
	} // end of method ITest::ToString

	.method public hidebysig newslot abstract virtual 
		instance void Close () cil managed 
	{
	} // end of method ITest::Close

	.method public hidebysig newslot abstract virtual 
		instance uint32 Add (
			[in] uint8 a,
			[in] uint16 b
		) cil managed 
	{
	} // end of method ITest::Add

	.method public hidebysig newslot abstract virtual 
		instance void RefMut (
			[out] uint32& p
		) cil managed 
	{
	} // end of method ITest::RefMut

	.method public hidebysig newslot abstract virtual 
		instance void RefConst (
			[in] uint32& modreq([mscorlib]System.Runtime.CompilerServices.IsConst) p
		) cil managed 
	{
	} // end of method ITest::RefConst

	.method public hidebysig newslot abstract virtual 
		instance void PtrMut (
			[out] uint32* p
		) cil managed 
	{
	} // end of method ITest::PtrMut

	.method public hidebysig newslot abstract virtual 
		instance void PtrConst (
			[in] uint32* modreq([mscorlib]System.Runtime.CompilerServices.IsConst) p
		) cil managed 
	{
	} // end of method ITest::PtrConst

} // end of class Test.ITest

More concisely, here's how ILSpy models it in C#:

public interface ITest
{
	string ToString();

	void Close();

	uint Add([In] byte a, [In] ushort b);

	void RefMut([Out] uint p);

	void RefConst([In] ref uint p);

	unsafe void PtrMut([Out] uint* p);

	unsafe void PtrConst([In] uint* p);
}

Stay tuned for more!

@kennykerr kennykerr merged commit 11fef60 into master Jan 30, 2026
32 checks passed
@kennykerr kennykerr deleted the rdl-methods branch January 30, 2026 21:22
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

Successfully merging this pull request may close these issues.

2 participants