-
Notifications
You must be signed in to change notification settings - Fork 208
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
unsafe context #1758
Comments
Can you elaborate on exactly what you mean by "Unsafe Contexts"? Is there a difference between "Unsafe" and "Insecure"?
Again, being specific will help here. Not just with what you want, but how you propose it be done. It's a lot to say "do the impossible" with no more explanation! The only Dart-specific request I see in your comment is
Can you describe in a bit of detail what the resulting value would be? What does it mean to have an object with none of its fields set? When you run a constructor, even an empty one such as the following: class A {
final bool condition = true;
const A():
} I believe the constructor is still being run -- it's setting class B {
final bool condition;
const B(this.condition);
} What should class C {
final bool? condition;
const C([this.condition]);
} What should |
Maybe I've misexpressed myself, but what I mean by "unsafe context" would basically be a block of code where the garbage collector doesn't get involved, where you can handle memory allocations and deallocations manually, a block of code that you can handle pointers, basically a piece of unmanaged code. example of c# likeclass TestPointer {
unsafe void run() {
int[] arr = {10, 7, 13, 54, 99};
fixed(int *ptr = arr)
for ( int i = 0; i < 5; i++)
{
print("arr[{0}] = {1}", i, *(ptr + i));
}
}
}
What I meant by that was that it would be possible to do things that are otherwise unfeasible to do with manageable code (GC) https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html This feature does not affect current developers, it would not change the philosophy of dart at all, it would be a resource for experienced programmers to get the most out of dart and at some points where you need maximum performance you could easily without leaving dart create optimized code . |
this is a good think to gain more control on Dynamic memory allocation to improve the time of processament, every this whithout any interruption from the garbage collector |
Some of the features you are asking for already exist - they live in There is no support for stack allocation or inline assembly/intrinsics yet. I have been entertaining some ideas of how we could expose something like inline assembly in Dart but have not made any definitive designs or prototypes for that yet. Though if you want to write sizable chunks of unmanaged code then I’d say you should better use an unmanaged language of your choice and bind to the result through dart:ffi. |
Good to know I'm not the only one thinking about it, the idea is definitely not to write sizable chunks of unmanaged code. The idea would be to have small pieces of code that could be optimized to extract maximum performance from the available hardware. some syntactic sugar for that would be nice, maybe a reserved word to separate the scope from unmanaged code would be nice |
It sounds good. |
Dart code is supposed to be able to be compiled into many different platforms. If you propose a semantics like "unsafe context" you have to specify what it will do in all the contexts into which darts currently compiles. It's not clear to me why you want to write the highly performance relevant code in dart. Why not use FFI and write it in C or Rust? |
What do you want to do with SIMD's that's currently not possible with Dart's SIMD support? |
C# and Java also runs in multiple environments and has a form of unsafe, ie running in multiple environments is not an obstacle. |
The idea of "unsafe context", goes beyond SIMD, as I said above, having an unsafe code area would allow manual memory manipulation, use of pointers, atomics, etc. It facilitates code optimization in small chunks without relying on FFI and without depending on other programming languages, just like you have inline assembly in C++ or unsafe in C# or Unsafe class in java. |
When you are in an insecure context, it is the programmer who has to worry about the environment that is available, check the OS, the hardware if the given instruction is available, that is, the complexity is not on the runtime or implementation side of the language and yes in the programmer who will use this feature. |
Good idea! @insinfo |
Java only runs in the Java Virtual Machine and not multiple different enviroments in the sense that Flutter does. |
For web application it can be contain JS code (prefer blocks): void setupAudioWorkletProcessor() {
unsafe('js') {
registerProcessor('some-audio-worklet-processor', class extends AudioWorkletProcessor {
constructor() {
super();
// ...
}
process(inputs, outputs, parameters) {
// ...
}
});
} else {
throw UnsupportedError('unsupported plafrom');
}
} |
@ChristianKleineidam And what's more, in the future dart will be compiled for WebAssembly, and in WebAssembly unsafe will work |
Flutter isn't Dart but Dart is intended to be "A client-optimized language for fast apps on any platform". |
This part hasn't been reached as it could, the garbage collector interrupting execution all the time doesn't help at all, no multithreading support doesn't help either, but the "unsafe context" can help with that, bringing possibilities of optimization of parts of the code, in a more integrated and easier way |
@PlugFox
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/unsafe-code |
The Unsafe Context would make it possible to optimize certain codes, such as numerical operations, mathematical calculations, layout calculations, vector operations, image processing, this would help for example to optimize certain parts of the flutter (IOS,ANDROID,Desktop) , would also bring many benefits to dart on the server-side backend, speed improvement in running command line applications etc.
It has great potential to bring many benefits, improved interoperability with C/C++ FFI, and WebASM.
with the Insecure Context it would be possible to make manual memory allocations, and use Atomics and SIMD intrinsics.
the implementation of this feature could be similar to java's Unsafe class or C#'s unsafe
Unsafe allows developers to
Directly access CPU and other hardware features
Create an object but not run its constructor
Create a truly anonymous class without the usual verification
Manually manage off-heap memory
Do many other seemingly "impossible things"
along with the Unsafe Context, it would bring intrinsic SIMD and Atomics
Example
The text was updated successfully, but these errors were encountered: