fsharp / fsharp/fslang-suggestions
Code Quotations to fail during compilation or to support unmanaged pointers, not to fail during runtime
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
I propose that next code to fail compilation or not fail in runtime:
```
#nowarn "9"
open System
open Microsoft.FSharp.NativeInterop
open System.Native
open System.Reflection
open System.Runtime.InteropServices
[]
let main argv =
let n = NativePtr.ofNativeInt(nativeint(1))
let x = <@ NativePtr.get n 0 = 123 @>
System.Console.WriteLine(x)
0
```
The existing way of approaching this problem in F# is throw exception during runtime.
```
PS E:\dzmitry\src\uncorefx\src\uncorefx.tests> dotnet --version
2.1.400
PS E:\dzmitry\src\uncorefx\src\uncorefx.tests> dotnet run
Unhandled Exception: System.InvalidOperationException: System.IntPtr is not a GenericTypeDefinition. MakeGenericType may only be called on a type for which Type.IsGenericTypeDefinition is true.
at System.RuntimeType.MakeGenericType(Type[] instantiation)
at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1432-7.Invoke(BindingEnv env)
at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x)
at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1415-4.Invoke(BindingEnv env)
at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x)
at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1415-4.Invoke(BindingEnv env)
at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1437-9.Invoke(BindingEnv env)
at Microsoft.FSharp.Quotations.PatternsModule.deserialize(Type localAssembly, Type[] referencedTypeDefs, Type[] spliceTypes, FSharpExpr[] spliceExprs, Byte[]
bytes)
at Program.main(String[] argv) in E:\dzmitry\src\uncorefx\src\uncorefx.tests\Program.fs:line 101
```
## Pros and Cons
The advantages of making this adjustment to F# that it will explicit that quotations do not support pointers at compile time like C# expressions do or quotation to support pointers to allow quation with pointers scenarios.
## Affidavit (please submit!)
Please tick this by placing a cross in the box:
* [X] This is not a question (e.g. like one you might ask on [stackoverflow](http://stackoverflow.com)) and I have searched stackoverflow for discussions of this issue
* [X] I have [searched both open and closed suggestions on this site](http://github.com/fsharp/fslang-suggestions/issues) and believe this is not a duplicate
* [X] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
Please tick all that apply:
* [X] This is not a breaking change to the F# language design
* [ ] I or my company would be willing to help implement and/or test this
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.