Skip to content

Commit

Permalink
Remove obsolete list aliases (#1556)
Browse files Browse the repository at this point in the history
* Bye bye FlatList

* Bye bye ILList

* Remove Flatlist from proto

* Remove more tautological calls
  • Loading branch information
forki authored and dsyme committed Sep 23, 2016
1 parent 7ea2852 commit 1df5ca9
Show file tree
Hide file tree
Showing 38 changed files with 426 additions and 995 deletions.
233 changes: 48 additions & 185 deletions src/absil/il.fs

Large diffs are not rendered by default.

62 changes: 6 additions & 56 deletions src/absil/il.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@ module internal Microsoft.FSharp.Compiler.AbstractIL.IL
open Internal.Utilities
open System.Collections.Generic

/// The type used to store relatively small lists in the Abstract IL data structures, i.e. for ILTypes, ILGenericArgs, ILParameters and ILLocals.
/// See comments in il.fs for why we've isolated this representation and the possible future choices we might use here.
#if ABSIL_USES_ARRAY_FOR_ILLIST
type ILList<'T> = 'T []
#endif

#if ABSIL_USES_THREELIST_FOR_ILLIST
type ILList<'T> = ThreeList<'T>
#endif

//#if ABSIL_USES_LIST_FOR_ILLIST
type ILList<'T> = 'T list
//#endif

type PrimaryAssembly =
| Mscorlib
| DotNetCore
Expand Down Expand Up @@ -361,28 +347,8 @@ and [<StructuralEquality; StructuralComparison>]
/// Actual generic parameters are always types.

and ILGenericArgs = ILList<ILType>
and ILTypes = ILList<ILType>


[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module ILList =
val inline map : ('T -> 'U) -> ILList<'T> -> ILList<'U>
val inline mapi : (int -> 'T -> 'U) -> ILList<'T> -> ILList<'U>
val inline isEmpty : ILList<'T> -> bool
val inline toList : ILList<'T> -> 'T list
val inline ofList : 'T list -> ILList<'T>
val inline lengthsEqAndForall2 : ('T -> 'U -> bool) -> ILList<'T> -> ILList<'U> -> bool
val inline init : int -> (int -> 'T) -> ILList<'T>
val inline empty<'T> : ILList<'T>
val inline toArray : ILList<'T> -> 'T[]
val inline ofArray : 'T[] -> ILList<'T>
val inline nth : ILList<'T> -> int -> 'T
val inline iter : ('T -> unit) -> ILList<'T> -> unit
val inline iteri : (int -> 'T -> unit) -> ILList<'T> -> unit
val inline foldBack : ('T -> 'State -> 'State) -> ILList<'T> -> 'State -> 'State
val inline exists : ('T -> bool) -> ILList<'T> -> bool

and ILGenericArgs = list<ILType>
and ILTypes = list<ILType>

/// Formal identities of methods. Method refs refer to methods on
/// named types. In general you should work with ILMethodSpec objects
Expand Down Expand Up @@ -817,8 +783,7 @@ type ILLocal =
IsPinned: bool;
DebugInfo: (string * int * int) option }


type ILLocals = ILList<ILLocal>
type ILLocals = list<ILLocal>

/// IL method bodies
[<RequireQualifiedAccess; NoComparison; NoEquality>]
Expand Down Expand Up @@ -891,10 +856,9 @@ type ILParameter =
IsOptional: bool;
CustomAttrs: ILAttributes }

type ILParameters = ILList<ILParameter>
type ILParameters = list<ILParameter>

val typesOfILParamsRaw : ILParameters -> ILTypes
val typesOfILParamsList : ILParameter list -> ILType list
val typesOfILParams : ILParameters -> ILType list

/// Method return values.
[<RequireQualifiedAccess; NoEquality; NoComparison>]
Expand Down Expand Up @@ -1658,7 +1622,6 @@ val decodeILAttribData:
val mkSimpleAssRef: string -> ILAssemblyRef
val mkSimpleModRef: string -> ILModuleRef

val emptyILGenericArgs: ILGenericArgs
val mkILTyvarTy: uint16 -> ILType

/// Make type refs.
Expand All @@ -1667,18 +1630,15 @@ val mkILTyRef: ILScopeRef * string -> ILTypeRef
val mkILTyRefInTyRef: ILTypeRef * string -> ILTypeRef

type ILGenericArgsList = ILType list
val mkILGenericArgs : ILGenericArgsList -> ILGenericArgs

/// Make type specs.
val mkILNonGenericTySpec: ILTypeRef -> ILTypeSpec
val mkILTySpec: ILTypeRef * ILGenericArgsList -> ILTypeSpec
val mkILTySpecRaw: ILTypeRef * ILGenericArgs -> ILTypeSpec

/// Make types.
val mkILTy: ILBoxity -> ILTypeSpec -> ILType
val mkILNamedTy: ILBoxity -> ILTypeRef -> ILGenericArgsList -> ILType
val mkILNamedTyRaw: ILBoxity -> ILTypeRef -> ILGenericArgs -> ILType
val mkILBoxedTy: ILTypeRef -> ILGenericArgsList -> ILType
val mkILBoxedTyRaw: ILTypeRef -> ILGenericArgs -> ILType
val mkILValueTy: ILTypeRef -> ILGenericArgsList -> ILType
val mkILNonGenericBoxedTy: ILTypeRef -> ILType
val mkILNonGenericValueTy: ILTypeRef -> ILType
Expand All @@ -1688,16 +1648,11 @@ val isILArrTy: ILType -> bool
val destILArrTy: ILType -> ILArrayShape * ILType
val mkILBoxedType : ILTypeSpec -> ILType

val mkILTypes : ILType list -> ILTypes

/// Make method references and specs.
val mkILMethRefRaw: ILTypeRef * ILCallingConv * string * int * ILTypes * ILType -> ILMethodRef
val mkILMethRef: ILTypeRef * ILCallingConv * string * int * ILType list * ILType -> ILMethodRef
val mkILMethSpec: ILMethodRef * ILBoxity * ILGenericArgsList * ILGenericArgsList -> ILMethodSpec
val mkILMethSpecForMethRefInTyRaw: ILMethodRef * ILType * ILGenericArgs -> ILMethodSpec
val mkILMethSpecForMethRefInTy: ILMethodRef * ILType * ILGenericArgsList -> ILMethodSpec
val mkILMethSpecInTy: ILType * ILCallingConv * string * ILType list * ILType * ILGenericArgsList -> ILMethodSpec
val mkILMethSpecInTyRaw: ILType * ILCallingConv * string * ILTypes * ILType * ILGenericArgs -> ILMethodSpec

/// Construct references to methods on a given type .
val mkILNonGenericMethSpecInTy: ILType * ILCallingConv * string * ILType list * ILType -> ILMethodSpec
Expand All @@ -1722,17 +1677,14 @@ val mkILFieldRef: ILTypeRef * string * ILType -> ILFieldRef
val mkILFieldSpec: ILFieldRef * ILType -> ILFieldSpec
val mkILFieldSpecInTy: ILType * string * ILType -> ILFieldSpec

val mkILCallSigRaw: ILCallingConv * ILTypes * ILType -> ILCallingSignature
val mkILCallSig: ILCallingConv * ILType list * ILType -> ILCallingSignature

/// Make generalized verions of possibly-generic types,
/// e.g. Given the ILTypeDef for List, return the type "List<T>".
val mkILFormalBoxedTy: ILTypeRef -> ILGenericParameterDef list -> ILType
val mkILFormalNamedTy: ILBoxity -> ILTypeRef -> ILGenericParameterDef list -> ILType

val mkILFormalTyparsRaw: ILTypes -> ILGenericParameterDefs
val mkILFormalTypars: ILType list -> ILGenericParameterDefs
val mkILFormalGenericArgsRaw: ILGenericParameterDefs -> ILGenericArgs
val mkILFormalGenericArgs: ILGenericParameterDefs -> ILGenericArgsList
val mkILSimpleTypar : string -> ILGenericParameterDef
/// Make custom attributes.
Expand Down Expand Up @@ -1794,8 +1746,6 @@ val mkILParamAnon: ILType -> ILParameter
val mkILParamNamed: string * ILType -> ILParameter
val mkILReturn: ILType -> ILReturn
val mkILLocal: ILType -> (string * int * int) option -> ILLocal
val mkILLocals : ILLocal list -> ILLocals
val emptyILLocals : ILLocals

/// Make a formal generic parameters.
val mkILEmptyGenericParams: ILGenericParameterDefs
Expand Down
59 changes: 0 additions & 59 deletions src/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -483,64 +483,6 @@ module ResultOrException =
| Result x -> success x
| Exception _err -> f()


//-------------------------------------------------------------------------
// Library: extensions to flat list (immutable arrays)
//------------------------------------------------------------------------
#if FLAT_LIST_AS_ARRAY_STRUCT
//#else
module FlatList =

let order (eltOrder: IComparer<_>) =
{ new IComparer<FlatList<_>> with
member __.Compare(xs,ys) =
match xs.array,ys.array with
| null,null -> 0
| _,null -> 1
| null,_ -> -1
| arr1,arr2 -> Array.order eltOrder arr1 arr2 }

let mapq f (x:FlatList<_>) =
match x.array with
| null -> x
| arr ->
let arr' = Array.map f arr in
let n = arr.Length in
let rec check i = if i >= n then true else arr.[i] === arr'.[i] && check (i+1)
if check 0 then x else FlatList(arr')

let mapFold f acc (x:FlatList<_>) =
match x.array with
| null ->
FlatList.Empty,acc
| arr ->
let arr,acc = Array.mapFold f acc x.array
FlatList(arr),acc

#endif
#if FLAT_LIST_AS_LIST

#else

module FlatList =
let toArray xs = List.toArray xs
let choose f xs = List.choose f xs
let order eltOrder = List.order eltOrder
let mapq f (x:FlatList<_>) = List.mapq f x
let mapFold f acc (x:FlatList<_>) = List.mapFold f acc x

#endif

#if FLAT_LIST_AS_ARRAY
//#else
module FlatList =
let order eltOrder = Array.order eltOrder
let mapq f x = Array.mapq f x
let mapFold f acc x = Array.mapFold f acc x
#endif



/// Computations that can cooperatively yield by returning a continuation
///
/// - Any yield of a NotYetDone should typically be "abandonable" without adverse consequences. No resource release
Expand Down Expand Up @@ -781,7 +723,6 @@ module NameMap =
let ofKeyedList f l = List.foldBack (fun x acc -> Map.add (f x) x acc) l Map.empty
let ofList l : NameMap<'T> = Map.ofList l
let ofSeq l : NameMap<'T> = Map.ofSeq l
let ofFlatList (l:FlatList<_>) : NameMap<'T> = FlatList.toMap l
let toList (l: NameMap<'T>) = Map.toList l
let layer (m1 : NameMap<'T>) m2 = Map.foldBack Map.add m1 m2

Expand Down
32 changes: 16 additions & 16 deletions src/absil/ilmorph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let rec typ_tref2tref f x =
| ILType.FunctionPointer x ->
ILType.FunctionPointer
{ x with
ArgTypes=ILList.map (typ_tref2tref f) x.ArgTypes;
ArgTypes=List.map (typ_tref2tref f) x.ArgTypes;
ReturnType=typ_tref2tref f x.ReturnType}
| ILType.Byref t -> ILType.Byref (typ_tref2tref f t)
| ILType.Boxed cr -> mkILBoxedType (tspec_tref2tref f cr)
Expand All @@ -65,7 +65,7 @@ let rec typ_tref2tref f x =
| ILType.Modified (req,tref,ty) -> ILType.Modified (req, f tref, typ_tref2tref f ty)
| ILType.Void -> ILType.Void
and tspec_tref2tref f (x:ILTypeSpec) =
mkILTySpecRaw(f x.TypeRef, ILList.map (typ_tref2tref f) x.GenericArgs)
mkILTySpec(f x.TypeRef, List.map (typ_tref2tref f) x.GenericArgs)

let rec typ_scoref2scoref_tyvar2typ ((_fscope,ftyvar) as fs)x =
match x with
Expand All @@ -81,9 +81,9 @@ and tspec_scoref2scoref_tyvar2typ fs (x:ILTypeSpec) =
ILTypeSpec.Create(morphILScopeRefsInILTypeRef (fst fs) x.TypeRef,typs_scoref2scoref_tyvar2typ fs x.GenericArgs)
and callsig_scoref2scoref_tyvar2typ f x =
{ x with
ArgTypes=ILList.map (typ_scoref2scoref_tyvar2typ f) x.ArgTypes;
ArgTypes=List.map (typ_scoref2scoref_tyvar2typ f) x.ArgTypes;
ReturnType=typ_scoref2scoref_tyvar2typ f x.ReturnType}
and typs_scoref2scoref_tyvar2typ f i = ILList.map (typ_scoref2scoref_tyvar2typ f) i
and typs_scoref2scoref_tyvar2typ f i = List.map (typ_scoref2scoref_tyvar2typ f) i
and gparams_scoref2scoref_tyvar2typ f i = List.map (gparam_scoref2scoref_tyvar2typ f) i
and gparam_scoref2scoref_tyvar2typ _f i = i
and morphILScopeRefsInILTypeRef fscope (x:ILTypeRef) =
Expand All @@ -92,27 +92,27 @@ and morphILScopeRefsInILTypeRef fscope (x:ILTypeRef) =

let callsig_typ2typ f (x: ILCallingSignature) =
{ CallingConv=x.CallingConv;
ArgTypes=ILList.map f x.ArgTypes;
ArgTypes=List.map f x.ArgTypes;
ReturnType=f x.ReturnType}

let gparam_typ2typ f gf = {gf with Constraints = ILList.map f gf.Constraints}
let gparam_typ2typ f gf = {gf with Constraints = List.map f gf.Constraints}
let gparams_typ2typ f gfs = List.map (gparam_typ2typ f) gfs
let typs_typ2typ (f: ILType -> ILType) x = ILList.map f x
let typs_typ2typ (f: ILType -> ILType) x = List.map f x
let mref_typ2typ (f: ILType -> ILType) (x:ILMethodRef) =
ILMethodRef.Create(enclosingTypeRef= (f (mkILBoxedType (mkILNonGenericTySpec x.EnclosingTypeRef))).TypeRef,
callingConv=x.CallingConv,
name=x.Name,
genericArity=x.GenericArity,
argTypes= ILList.map f x.ArgTypes,
argTypes= List.map f x.ArgTypes,
returnType= f x.ReturnType)


type formal_scopeCtxt = Choice<ILMethodSpec, ILFieldSpec>

let mspec_typ2typ (((factualty : ILType -> ILType) , (fformalty: formal_scopeCtxt -> ILType -> ILType))) (x: ILMethodSpec) =
mkILMethSpecForMethRefInTyRaw(mref_typ2typ (fformalty (Choice1Of2 x)) x.MethodRef,
factualty x.EnclosingType,
typs_typ2typ factualty x.GenericArgs)
mkILMethSpecForMethRefInTy(mref_typ2typ (fformalty (Choice1Of2 x)) x.MethodRef,
factualty x.EnclosingType,
typs_typ2typ factualty x.GenericArgs)

let fref_typ2typ (f: ILType -> ILType) x =
{ x with EnclosingTypeRef = (f (mkILBoxedType (mkILNonGenericTySpec x.EnclosingTypeRef))).TypeRef;
Expand Down Expand Up @@ -155,7 +155,7 @@ let fdef_typ2typ ilg ftype (fd: ILFieldDef) =
CustomAttrs=cattrs_typ2typ ilg ftype fd.CustomAttrs}

let local_typ2typ f (l: ILLocal) = {l with Type = f l.Type}
let varargs_typ2typ f (varargs: ILVarArgs) = Option.map (ILList.map f) varargs
let varargs_typ2typ f (varargs: ILVarArgs) = Option.map (List.map f) varargs
(* REVIEW: convert varargs *)
let morphILTypesInILInstr ((factualty,fformalty)) i =
let factualty = factualty (Some i)
Expand Down Expand Up @@ -205,7 +205,7 @@ let fdefs_fdef2fdef f (m:ILFieldDefs) = mkILFields (List.map f m.AsList)
(* use this when the conversion produces just one type... *)
let morphILTypeDefs f (m: ILTypeDefs) = mkILTypeDefsFromArray (Array.map f m.AsArray)

let locals_typ2typ f ls = ILList.map (local_typ2typ f) ls
let locals_typ2typ f ls = List.map (local_typ2typ f) ls

let ilmbody_instr2instr_typ2typ fs (il: ILMethodBody) =
let (finstr,ftype) = fs
Expand All @@ -228,7 +228,7 @@ let mdef_typ2typ_ilmbody2ilmbody ilg fs md =
{md with
GenericParams=gparams_typ2typ ftype' md.GenericParams;
mdBody= body';
Parameters = ILList.map (param_typ2typ ilg ftype') md.Parameters;
Parameters = List.map (param_typ2typ ilg ftype') md.Parameters;
Return = return_typ2typ ilg ftype' md.Return;
CustomAttrs=cattrs_typ2typ ilg ftype' md.CustomAttrs }

Expand All @@ -254,7 +254,7 @@ let pdef_typ2typ ilg f p =
SetMethod = Option.map (mref_typ2typ f) p.SetMethod;
GetMethod = Option.map (mref_typ2typ f) p.GetMethod;
Type = f p.Type;
Args = ILList.map f p.Args;
Args = List.map f p.Args;
CustomAttrs = cattrs_typ2typ ilg f p.CustomAttrs }

let pdefs_typ2typ ilg f (pdefs: ILPropertyDefs) = mkILProperties (List.map (pdef_typ2typ ilg f) pdefs.AsList)
Expand All @@ -267,7 +267,7 @@ let rec tdef_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg enc fs td =
let ftype' = ftype (Some (enc,td)) None
let mdefs' = fmdefs (enc,td) td.Methods
let fdefs' = fdefs_typ2typ ilg ftype' td.Fields
{td with Implements= ILList.map ftype' td.Implements;
{td with Implements= List.map ftype' td.Implements;
GenericParams= gparams_typ2typ ftype' td.GenericParams;
Extends = Option.map ftype' td.Extends;
Methods=mdefs';
Expand Down
4 changes: 2 additions & 2 deletions src/absil/ilpars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type SigArg = SigArg of (string option * ILType) | Sentinel
let decodeVarargs args =
let rec normals = function
| [] -> ([],None)
| Sentinel :: t -> ([],Some (ILList.ofList (varargs t)))
| Sentinel :: t -> ([],Some (varargs t))
| SigArg (_,p)::t -> let (n,r) = normals t in (p::n, r)
and varargs = function
| [] -> []
Expand All @@ -46,7 +46,7 @@ let resolveMethodSpecScopeThen (ResolvedAtMethodSpecScope f) g =
let resolveFormalMethodSpecScope tspeco obj =
match tspeco with
None -> resolveMethodSpecScope obj mkILEmptyGenericParams
| Some (tspec:ILTypeSpec) -> resolveMethodSpecScope obj (mkILFormalTyparsRaw tspec.GenericArgs)
| Some (tspec:ILTypeSpec) -> resolveMethodSpecScope obj (mkILFormalTypars tspec.GenericArgs)

let resolveCurrentMethodSpecScope obj =
resolveMethodSpecScope obj mkILEmptyGenericParams
Expand Down
8 changes: 4 additions & 4 deletions src/absil/ilprint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ and goutput_ldtoken_info env os = function
| ILToken.ILField x -> output_string os "field "; goutput_fspec env os x

and goutput_typ_with_shortened_class_syntax env os = function
ILType.Boxed tspec when tspec.GenericArgs = emptyILGenericArgs ->
ILType.Boxed tspec when tspec.GenericArgs = [] ->
goutput_tref env os tspec.TypeRef
| typ2 -> goutput_typ env os typ2

Expand Down Expand Up @@ -339,7 +339,7 @@ and goutput_mref env os (mref:ILMethodRef) =
and goutput_mspec env os (mspec:ILMethodSpec) =
let fenv =
ppenv_enter_method mspec.GenericArity
(ppenv_enter_tdef (mkILFormalTyparsRaw mspec.EnclosingType.GenericArgs) env)
(ppenv_enter_tdef (mkILFormalTypars mspec.EnclosingType.GenericArgs) env)
output_callconv os mspec.CallingConv;
output_string os " ";
goutput_typ fenv os mspec.FormalReturnType;
Expand All @@ -357,7 +357,7 @@ and goutput_vararg_mspec env os (mspec, varargs) =
| Some varargs' ->
let fenv =
ppenv_enter_method mspec.GenericArity
(ppenv_enter_tdef (mkILFormalTyparsRaw mspec.EnclosingType.GenericArgs) env)
(ppenv_enter_tdef (mkILFormalTypars mspec.EnclosingType.GenericArgs) env)
output_callconv os mspec.CallingConv;
output_string os " ";
goutput_typ fenv os mspec.FormalReturnType;
Expand Down Expand Up @@ -386,7 +386,7 @@ and goutput_vararg_sig env os (csig:ILCallingSignature,varargs:ILVarArgs) =
output_string os ")";

and goutput_fspec env os (x:ILFieldSpec) =
let fenv = ppenv_enter_tdef (mkILFormalTyparsRaw x.EnclosingType.GenericArgs) env
let fenv = ppenv_enter_tdef (mkILFormalTypars x.EnclosingType.GenericArgs) env
goutput_typ fenv os x.FormalType;
output_string os " ";
goutput_dlocref env os x.EnclosingType;
Expand Down
Loading

0 comments on commit 1df5ca9

Please sign in to comment.