Skip to content

Commit

Permalink
[RFCs FS-1051, FS-1052, FS-1053] support for span, readonly refs, byr…
Browse files Browse the repository at this point in the history
…ef-like structs (#4888)

* initial support for span, readonly refs, byref-like structs

* fix proto build

* make proto work with previous FSharp.Core

* make proto work with previous FSharp.Core

* update baselines

* integrate code cleanup

* integrate code cleanup

* integrate code cleanup

* integrate code cleanup

* fix build

* fix build

* implicit deref of byref returns

* add tests for Memory, ReadOnlySpan and ReadOnlyMemory

* fix tests

* simplify diff

* simplify diff

* remove duplicate error messages

* fix build

* test updates

* fix build

* fix build

* update baselines

* fix uses of NativePtr.toByRef

* switch to inference using byref pointer capabilities

* fix proto build

* update baselines, byref extension methods

* fix test errors

* emit in,out,modreq attributes correctly

* update tests

* fix build

* fix build

* fix tests

* fix tests

* get it right silly boy

* fix test

* minor cleanup

* add more tests

* clarify overloading behaviour + test case

* fix build break

* fix build of tests

* update tests

* add more tests

* byref fixes

* updates for subsumption calls, error message, assign-to-return-byref

* test updates, implicit deref on byref return for normal functions

* update baseline

* improve debug formatting, better error message on implicit deref, improve error messages

* add more tests for recursive functions

* update baselines

* fix baselines

* updates for new test cases

* updates for new test cases

* test updates and byref-to-byreflike

* deal with 'M() <- expr'

* restrict addresses of immutable top-level things

* fix IsByRefLike on struct

* update tests

* fix test

* fix test

* improve check for no-return-of-struct-field-addresses

* fix test case
  • Loading branch information
dsyme authored and TIHan committed Jun 4, 2018
1 parent e21c296 commit 5bfd9fc
Show file tree
Hide file tree
Showing 90 changed files with 6,856 additions and 2,747 deletions.
1 change: 0 additions & 1 deletion DEVGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ To do this, build the non-buildfromsource version of FSharp.Compiler.Private (sr

.\build net40
copy /y src\fsharp\FSharp.Compiler.Private\obj\release\net40\FSComp.* src\buildfromsource\FSharp.Compiler.Private\


#### Configuring proxy server

Expand Down
5 changes: 5 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<package id="Microsoft.FSharp.TupleSample" version="1.0.0-alpha-161121"/>
<package id="Microsoft.VSSDK.BuildTools" version="15.1.192" />

<!-- Testing Span -->
<package id="System.Memory" version="4.5.0-rc1" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0-rc1" />
<package id="NETStandard.Library.NETFramework" version="2.0.0-preview2-25405-01" />

<!-- Annoyingly the build of FSharp.Compiler.Server.Shared references a Visual Studio-specific attribute -->
<!-- That DLL is logically part of the F# Compiler and F# Interactive but is shipped as part of the Visual F# IDE Tools -->
<package id="Microsoft.VisualStudio.Shell.Immutable.10.0" version="10.0.30319" targetFramework="net46" />
Expand Down
82 changes: 72 additions & 10 deletions src/absil/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Microsoft.FSharp.Compiler.AbstractIL.IL


open System
open System.Diagnostics
open System.IO
open System.Collections
open System.Collections.Generic
Expand Down Expand Up @@ -568,7 +569,7 @@ type ILBoxity =
| AsValue

// IL type references have a pre-computed hash code to enable quick lookup tables during binary generation.
[<CustomEquality; CustomComparison>]
[<CustomEquality; CustomComparison; StructuredFormatDisplay("{DebugText}")>]
type ILTypeRef =
{ trefScope: ILScopeRef
trefEnclosing: string list
Expand Down Expand Up @@ -637,11 +638,15 @@ type ILTypeRef =
member tref.QualifiedName =
tref.AddQualifiedNameExtension(tref.BasicQualifiedName)

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

/// For debugging
override x.ToString() = x.FullName


and
[<StructuralEquality; StructuralComparison>]
and [<StructuralEquality; StructuralComparison; StructuredFormatDisplay("{DebugText}")>]
ILTypeSpec =
{ tspecTypeRef: ILTypeRef
/// The type instantiation if the type is generic.
Expand Down Expand Up @@ -671,9 +676,13 @@ and

member x.FullName=x.TypeRef.FullName

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = x.TypeRef.ToString() + if isNil x.GenericArgs then "" else "<...>"

and [<RequireQualifiedAccess; StructuralEquality; StructuralComparison>]
and [<RequireQualifiedAccess; StructuralEquality; StructuralComparison; StructuredFormatDisplay("{DebugText}")>]
ILType =
| Void
| Array of ILArrayShape * ILType
Expand Down Expand Up @@ -740,6 +749,10 @@ and [<RequireQualifiedAccess; StructuralEquality; StructuralComparison>]
match x with
| ILType.TypeVar _ -> true | _ -> false

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = x.QualifiedName

and [<StructuralEquality; StructuralComparison>]
Expand All @@ -756,6 +769,7 @@ let mkILCallSig (cc, args, ret) = { ArgTypes=args; CallingConv=cc; ReturnType=re

let mkILBoxedType (tspec:ILTypeSpec) = tspec.TypeRef.AsBoxedType tspec

[<StructuralEquality; StructuralComparison; StructuredFormatDisplay("{DebugText}")>]
type ILMethodRef =
{ mrefParent: ILTypeRef
mrefCallconv: ILCallingConv
Expand Down Expand Up @@ -783,26 +797,34 @@ type ILMethodRef =
static member Create(a, b, c, d, e, f) =
{ mrefParent= a;mrefCallconv=b;mrefName=c;mrefGenericArity=d; mrefArgs=e;mrefReturn=f }

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = x.DeclaringTypeRef.ToString() + "::" + x.Name + "(...)"


[<StructuralEquality; StructuralComparison>]
[<StructuralEquality; StructuralComparison; StructuredFormatDisplay("{DebugText}")>]
type ILFieldRef =
{ DeclaringTypeRef: ILTypeRef
Name: string
Type: ILType }

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = x.DeclaringTypeRef.ToString() + "::" + x.Name

[<StructuralEquality; StructuralComparison>]
[<StructuralEquality; StructuralComparison; StructuredFormatDisplay("{DebugText}")>]
type ILMethodSpec =
{ mspecMethodRef: ILMethodRef

mspecDeclaringType: ILType

mspecMethodInst: ILGenericArgs }

static member Create(a, b, c) = { mspecDeclaringType=a; mspecMethodRef =b; mspecMethodInst=c }
static member Create(a, b, c) = { mspecDeclaringType=a; mspecMethodRef=b; mspecMethodInst=c }

member x.MethodRef = x.mspecMethodRef

Expand All @@ -820,8 +842,13 @@ type ILMethodSpec =

member x.FormalReturnType = x.MethodRef.ReturnType

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = x.MethodRef.ToString() + "(...)"

[<StructuralEquality; StructuralComparison; StructuredFormatDisplay("{DebugText}")>]
type ILFieldSpec =
{ FieldRef: ILFieldRef
DeclaringType: ILType }
Expand All @@ -832,6 +859,10 @@ type ILFieldSpec =

member x.DeclaringTypeRef = x.FieldRef.DeclaringTypeRef

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = x.FieldRef.ToString()

// --------------------------------------------------------------------
Expand Down Expand Up @@ -865,6 +896,7 @@ type ILSourceDocument =

member x.File=x.sourceFile

[<StructuralEquality; StructuralComparison; StructuredFormatDisplay("{DebugText}")>]
type ILSourceMarker =
{ sourceDocument: ILSourceDocument
sourceLine: int
Expand All @@ -889,6 +921,10 @@ type ILSourceMarker =

member x.EndColumn=x.sourceEndColumn

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = sprintf "(%d, %d)-(%d, %d)" x.Line x.Column x.EndLine x.EndColumn

type ILAttribElem =
Expand All @@ -912,11 +948,16 @@ type ILAttribElem =

type ILAttributeNamedArg = (string * ILType * bool * ILAttribElem)

[<StructuralEquality; StructuralComparison; StructuredFormatDisplay("{DebugText}")>]
type ILAttribute =
{ Method: ILMethodSpec
Data: byte[]
Elements: ILAttribElem list }

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = x.Method.ToString() + "(...)"

[<NoEquality; NoComparison; Struct>]
Expand Down Expand Up @@ -1424,6 +1465,8 @@ type ILReturn =

member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex

member x.WithCustomAttrs(customAttrs) = { x with CustomAttrsStored = storeILCustomAttrs customAttrs }

type ILOverridesSpec =
| OverridesSpec of ILMethodRef * ILType

Expand Down Expand Up @@ -1475,6 +1518,7 @@ type ILGenericVariance =
| CoVariant
| ContraVariant

[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
type ILGenericParameterDef =
{ Name: string
Constraints: ILTypes
Expand All @@ -1487,6 +1531,10 @@ type ILGenericParameterDef =

member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = x.Name

type ILGenericParameterDefs = ILGenericParameterDef list
Expand Down Expand Up @@ -1665,7 +1713,7 @@ type ILMethodDefs(f : (unit -> ILMethodDef[])) =

member x.FindByNameAndArity (nm, arity) = x.FindByName nm |> List.filter (fun x -> List.length x.Parameters = arity)

[<NoComparison; NoEquality>]
[<NoComparison; NoEquality; StructuredFormatDisplay("{DebugText}")>]
type ILEventDef(eventType: ILType option, name: string, attributes: EventAttributes, addMethod: ILMethodRef, removeMethod: ILMethodRef, fireMethod: ILMethodRef option, otherMethods: ILMethodRef list, customAttrsStored: ILAttributesStored, metadataIndex: int32) =

new (eventType, name, attributes, addMethod, removeMethod, fireMethod, otherMethods, customAttrs) =
Expand Down Expand Up @@ -1695,6 +1743,10 @@ type ILEventDef(eventType: ILType option, name: string, attributes: EventAttribu
member x.IsSpecialName = (x.Attributes &&& EventAttributes.SpecialName) <> enum<_>(0)
member x.IsRTSpecialName = (x.Attributes &&& EventAttributes.RTSpecialName) <> enum<_>(0)

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = "event " + x.Name

[<NoEquality; NoComparison>]
Expand All @@ -1705,7 +1757,7 @@ type ILEventDefs =

member x.LookupByName s = let (ILEvents t) = x in t.[s]

[<NoComparison; NoEquality>]
[<NoComparison; NoEquality; StructuredFormatDisplay("{DebugText}")>]
type ILPropertyDef(name: string, attributes: PropertyAttributes, setMethod: ILMethodRef option, getMethod: ILMethodRef option, callingConv: ILThisConvention, propertyType: ILType, init: ILFieldInit option, args: ILTypes, customAttrsStored: ILAttributesStored, metadataIndex: int32) =

new (name, attributes, setMethod, getMethod, callingConv, propertyType, init, args, customAttrs) =
Expand Down Expand Up @@ -1737,6 +1789,11 @@ type ILPropertyDef(name: string, attributes: PropertyAttributes, setMethod: ILMe

member x.IsSpecialName = (x.Attributes &&& PropertyAttributes.SpecialName) <> enum<_>(0)
member x.IsRTSpecialName = (x.Attributes &&& PropertyAttributes.RTSpecialName) <> enum<_>(0)

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = "property " + x.Name

// Index table by name.
Expand Down Expand Up @@ -2469,7 +2526,7 @@ let tname_IntPtr = "System.IntPtr"
[<Literal>]
let tname_UIntPtr = "System.UIntPtr"

[<NoEquality; NoComparison>]
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
// This data structure needs an entirely delayed implementation
type ILGlobals(primaryScopeRef) =

Expand Down Expand Up @@ -2514,6 +2571,11 @@ type ILGlobals(primaryScopeRef) =
member x.typ_Double = m_typ_Double
member x.typ_Bool = m_typ_Bool
member x.typ_Char = m_typ_Char

/// For debugging
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override x.ToString() = "<ILGlobals>"

let mkILGlobals primaryScopeRef = ILGlobals primaryScopeRef
Expand Down
2 changes: 2 additions & 0 deletions src/absil/il.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ type ILReturn =

member CustomAttrs: ILAttributes

member WithCustomAttrs: customAttrs: ILAttributes -> ILReturn

[<RequireQualifiedAccess>]
type ILSecurityAction =
| Request
Expand Down
7 changes: 7 additions & 0 deletions src/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ module Array =

loop p l 0

let existsTrue (arr: bool[]) =
let rec loop n = (n < arr.Length) && (arr.[n] || loop (n+1))
loop 0

let findFirstIndexWhereTrue (arr: _[]) p =
let rec look lo hi =
Expand Down Expand Up @@ -263,6 +266,10 @@ module List =
let rec loop i xs = match xs with [] -> false | h::t -> f i h || loop (i+1) t
loop 0 xs

let existsTrue (xs: bool list) =
let rec loop i xs = match xs with [] -> false | h::t -> h || loop (i+1) t
loop 0 xs

let lengthsEqAndForall2 p l1 l2 =
List.length l1 = List.length l2 &&
List.forall2 p l1 l2
Expand Down
Loading

0 comments on commit 5bfd9fc

Please sign in to comment.