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

Implementation of Unsafe Class #745

Open
arakis opened this issue Nov 3, 2019 · 4 comments
Open

Implementation of Unsafe Class #745

arakis opened this issue Nov 3, 2019 · 4 comments
Assignees
Labels

Comments

@arakis
Copy link
Member

arakis commented Nov 3, 2019

If we provide an Implementation of Unsafe class and ref structs, this will a big boost into the right direction and makes low level system programming much more type safe and easier.

The most important functions, in the order:

public static int SizeOf<T>()
public static ref TTo As<TFrom, TTo>(ref TFrom source)
public static void* AsPointer<T>(ref T value)

If the above methods are implemented correctly, the following methods should work "automatically", because they depend on the above methods:

public static ref T AsRef<T>(void* source)
public static void Write<T>(void* destination, T value)
public static T Read<T>(void* source)

It could be necessary to provide the ByReference<T> Type.

Please keep in mind that SizeOf() should NOT rely on metadata lookup for each call, it will be horrible slow. As I know, Mosa is duplicating for every generic call the code - so compiler should know the size of T at compile time. And if the methods are correctly implemented as Intrinsics, they could be inlined within the calling method, wich means, that nearly every Call to the above methods is done in very less (maybe only a single) instruction, especially the ref struct methods.

After all the above stuff is working, the following features will work without any additional Compiler support:

  • removing unsafe-pointers and replace them via ref structs
  • ref structs
  • Span
  • ReadonlySpan
  • Memory
  • And much more cool stuff.

Here's a small reference implementation incl. a test scenario at the end of the file:
https://github.com/abanu-org/abanu/blob/fd6a45042722596198763b9b63c6b92484d73dc2/src/Abanu.Lib/BitReader.cs

It would be nice if this feature could get a reasonable priority.

@tgiphil
Copy link
Member

tgiphil commented Feb 7, 2020

@tgiphil tgiphil added this to To do in Features [Archive] Sep 28, 2020
@tgiphil tgiphil assigned charsleysa and unassigned tgiphil Aug 29, 2021
@tgiphil
Copy link
Member

tgiphil commented Sep 9, 2021

@charsleysa Is this completed?

@charsleysa
Copy link
Member

@charsleysa Is this completed?

Not quite, I think some of the read and write methods are still missing, maybe roughly 80% complete.

@tgiphil tgiphil moved this from To do to In progress in Features [Archive] Sep 16, 2021
@AnErrupTion
Copy link
Collaborator

This is mostly done, just a few functions (2 I think) and the Unsafe class is fully implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

No branches or pull requests

4 participants