Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/absil/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ let runningOnMono =

let _ = if logging then dprintn "* warning: Il.logging is on"

let isNil x = match x with [] -> true | _ -> false
let nonNil x = match x with [] -> false | _ -> true
let int_order = LanguagePrimitives.FastGenericComparer<int>

let notlazy v = Lazy.CreateFromValue v
Expand Down Expand Up @@ -2639,7 +2637,7 @@ let rec rescopeILTypeSpecQuick scoref (tspec:ILTypeSpec) =
let tref = tspec.TypeRef
let tinst = tspec.GenericArgs
let qtref = qrescope_tref scoref tref
if ILList.isEmpty tinst && isNone qtref then
if ILList.isEmpty tinst && Option.isNone qtref then
None (* avoid reallocation in the common case *)
else
match qtref with
Expand Down Expand Up @@ -4267,14 +4265,14 @@ let resolveILMethodRefWithRescope r td (mref:ILMethodRef) =
let nargs = args.Length
let nm = mref.Name
let possibles = td.Methods.FindByNameAndArity (nm,nargs)
if isNil possibles then failwith ("no method named "+nm+" found in type "+td.Name);
if List.isEmpty possibles then failwith ("no method named " + nm + " found in type " + td.Name)
match
possibles |> List.filter (fun md ->
mref.CallingConv = md.CallingConv &&
// REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct
(md.Parameters,mref.ArgTypes) ||> ILList.lengthsEqAndForall2 (fun p1 p2 -> r p1.Type = p2) &&
(md.Parameters,mref.ArgTypes) ||> ILList.lengthsEqAndForall2 (fun p1 p2 -> r p1.Type = p2) &&
// REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct
r md.Return.Type = mref.ReturnType) with
r md.Return.Type = mref.ReturnType) with
| [] -> failwith ("no method named "+nm+" with appropriate argument types found in type "+td.Name)
| [mdef] -> mdef
| _ -> failwith ("multiple methods named "+nm+" appear with identical argument types in type "+td.Name)
Expand Down
11 changes: 3 additions & 8 deletions src/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ let (>>>&) (x:int32) (n:int32) = int32 (uint32 x >>> n)

let notlazy v = Lazy<_>.CreateFromValue v

let isSome x = match x with None -> false | _ -> true
let isNone x = match x with None -> true | _ -> false
let isNil x = match x with [] -> true | _ -> false
let nonNil x = match x with [] -> false | _ -> true
let isNull (x : 'T) = match (x :> obj) with null -> true | _ -> false
let isNonNull (x : 'T) = match (x :> obj) with null -> false | _ -> true
let nonNull msg x = if isNonNull x then x else failwith ("null: " ^ msg)
let inline isNonNull x = not (isNull x)
let inline nonNull msg x = if isNull x then failwith ("null: " ^ msg) else x
let (===) x y = LanguagePrimitives.PhysicalEquality x y

//---------------------------------------------------------------------
Expand Down Expand Up @@ -438,7 +433,7 @@ module String =
else
None

let hasPrefix s t = isSome (tryDropPrefix s t)
let hasPrefix s t = Option.isSome (tryDropPrefix s t)
let dropPrefix s t = match (tryDropPrefix s t) with Some(res) -> res | None -> failwith "dropPrefix"

let dropSuffix s t = match (tryDropSuffix s t) with Some(res) -> res | None -> failwith "dropSuffix"
Expand Down
2 changes: 1 addition & 1 deletion src/absil/ilprint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ and goutput_gparam env os (gf: ILGenericParameterDef) =
output_parens (output_seq "," (goutput_typ env)) os gf.Constraints

and goutput_gparams env os b =
if nonNil b then
if not (List.isEmpty b) then
output_string os "<"; output_seq "," (goutput_gparam env) os b; output_string os ">"; ()

and output_bcc os bcc =
Expand Down
6 changes: 3 additions & 3 deletions src/absil/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ let dataEndPoints ctxtH =
let rva = ctxt.resourcesAddr + offset
res := ("manifest resource", rva) :: !res
!res
if isNil dataStartPoints then []
if List.isEmpty dataStartPoints then []
else
let methodRVAs =
let res = ref []
Expand Down Expand Up @@ -2184,7 +2184,7 @@ and seekReadMemberRefAsMethodDataUncached ctxtH (MemberRefAsMspecIdx (numtypars,

and seekReadMemberRefAsMethDataNoVarArgs ctxt numtypars idx : MethodData =
let (VarArgMethodData(enclTyp, cc, nm, argtys,varargs, retty,minst)) = seekReadMemberRefAsMethodData ctxt numtypars idx
if isSome varargs then dprintf "ignoring sentinel and varargs in ILMethodDef token signature"
if Option.isSome varargs then dprintf "ignoring sentinel and varargs in ILMethodDef token signature"
(MethodData(enclTyp, cc, nm, argtys, retty,minst))

and seekReadMethodSpecAsMethodData ctxt numtypars idx =
Expand Down Expand Up @@ -3987,7 +3987,7 @@ let OpenILModuleReaderAfterReadingAllBytes infile opts =
{ modul = modul
ilAssemblyRefs = ilAssemblyRefs
dispose = (fun () -> ClosePdbReader pdb) }
if isNone pdb && succeeded then
if Option.isNone pdb && succeeded then
ilModuleReaderCache.Put(key, ilModuleReader)
ilModuleReader

Expand Down
2 changes: 1 addition & 1 deletion src/absil/ilreflect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ let rec buildMethodPass3 cenv tref modB (typB:TypeBuilder) emEnv (mdef : ILMetho
| ".cctor" | ".ctor" ->
let consB = envGetConsB emEnv mref
// Constructors can not have generic parameters
assert isNil mdef.GenericParams
assert List.isEmpty mdef.GenericParams
// Value parameters
let defineParameter (i,attr,name) = consB.DefineParameterAndLog(i+1,attr,name)
mdef.Parameters |> ILList.iteri (emitParameter cenv emEnv defineParameter);
Expand Down
24 changes: 12 additions & 12 deletions src/absil/ilwrite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ and GetTypeDescAsTypeRefIdx cenv (scoref,enc,n) =
GetTypeRefAsTypeRefIdx cenv (mkILNestedTyRef (scoref,enc,n))

and GetResolutionScopeAsElem cenv (scoref,enc) =
if isNil enc then
if List.isEmpty enc then
match scoref with
| ILScopeRef.Local -> (rs_Module, 1)
| ILScopeRef.Assembly aref -> (rs_AssemblyRef, GetAssemblyRefAsIdx cenv aref)
Expand Down Expand Up @@ -1205,16 +1205,16 @@ and GenTypeDefPass2 pidx enc cenv (td:ILTypeDef) =

// Add entries to auxiliary mapping tables, e.g. Nested, PropertyMap etc.
// Note Nested is organised differntly to the others...
if nonNil enc then
if not (List.isEmpty enc) then
AddUnsharedRow cenv TableNames.Nested
(UnsharedRow
[| SimpleIndex (TableNames.TypeDef, tidx)
SimpleIndex (TableNames.TypeDef, pidx) |]) |> ignore
let props = td.Properties.AsList
if nonNil props then
if not (List.isEmpty props) then
AddUnsharedRow cenv TableNames.PropertyMap (GetTypeDefAsPropertyMapRow cenv tidx) |> ignore
let events = td.Events.AsList
if nonNil events then
if not (List.isEmpty events) then
AddUnsharedRow cenv TableNames.EventMap (GetTypeDefAsEventMapRow cenv tidx) |> ignore

// Now generate or assign index numbers for tables referenced by the maps.
Expand Down Expand Up @@ -1308,7 +1308,7 @@ let GetMethodRefInfoAsMemberRefIdx cenv env ((_,typ,_,_,_,_,_) as minfo) =
FindOrAddSharedRow cenv TableNames.MemberRef (MethodRefInfoAsMemberRefRow cenv env fenv minfo)

let GetMethodRefInfoAsMethodRefOrDef isAlwaysMethodDef cenv env ((nm,typ:ILType,cc,args,ret,varargs,genarity) as minfo) =
if isNone varargs && (isAlwaysMethodDef || isTypeLocal typ) then
if Option.isNone varargs && (isAlwaysMethodDef || isTypeLocal typ) then
if not typ.IsNominal then failwith "GetMethodRefInfoAsMethodRefOrDef: unexpected local tref-typ"
try (mdor_MethodDef, GetMethodRefAsMethodDefIdx cenv (mkILMethRefRaw(typ.TypeRef, cc, nm, genarity, args,ret)))
with MethodDefNotFound -> (mdor_MemberRef, GetMethodRefInfoAsMemberRefIdx cenv env minfo)
Expand Down Expand Up @@ -1623,7 +1623,7 @@ module Codebuf =
let adjustments = ref []

while (!remainingReqdFixups <> [] || not !doneLast) do
let doingLast = isNil !remainingReqdFixups
let doingLast = List.isEmpty !remainingReqdFixups
let origStartOfNoBranchBlock = !origWhere
let newStartOfNoBranchBlock = !newWhere

Expand Down Expand Up @@ -2076,7 +2076,7 @@ module Codebuf =


let mkScopeNode cenv (localSigs: _[]) (startOffset,endOffset,ls: ILLocalDebugMapping list,childScopes) =
if (isNil ls || not cenv.generatePdb) then childScopes
if List.isEmpty ls || not cenv.generatePdb then childScopes
else
[ { Children= Array.ofList childScopes
StartOffset=startOffset
Expand Down Expand Up @@ -2253,7 +2253,7 @@ let GenILMethodBody mname cenv env (il: ILMethodBody) =
let codeSize = code.Length
let methbuf = ByteBuffer.Create (codeSize * 3)
// Do we use the tiny format?
if ILList.isEmpty il.Locals && il.MaxStack <= 8 && isNil seh && codeSize < 64 then
if ILList.isEmpty il.Locals && il.MaxStack <= 8 && List.isEmpty seh && codeSize < 64 then
// Use Tiny format
let alignedCodeSize = align 4 (codeSize + 1)
let codePadding = (alignedCodeSize - (codeSize + 1))
Expand Down Expand Up @@ -2285,7 +2285,7 @@ let GenILMethodBody mname cenv env (il: ILMethodBody) =
methbuf.EmitBytes code
methbuf.EmitPadding codePadding

if nonNil seh then
if not (List.isEmpty seh) then
// Can we use the small exception handling table format?
let smallSize = (seh.Length * 12 + 4)
let canUseSmall =
Expand Down Expand Up @@ -2463,7 +2463,7 @@ let rec GetParamAsParamRow cenv _env seq (param: ILParameter) =
StringE (GetStringHeapIdxOption cenv param.Name) |]

and GenParamPass3 cenv env seq (param: ILParameter) =
if param.IsIn=false && param.IsOut=false && param.IsOptional=false && isNone param.Default && isNone param.Name && isNone param.Marshal
if not param.IsIn && not param.IsOut && not param.IsOptional && Option.isNone param.Default && Option.isNone param.Name && Option.isNone param.Marshal
then ()
else
let pidx = AddUnsharedRow cenv TableNames.Param (GetParamAsParamRow cenv env seq param)
Expand All @@ -2483,7 +2483,7 @@ let GenReturnAsParamRow (returnv : ILReturn) =
StringE 0 |]

let GenReturnPass3 cenv (returnv: ILReturn) =
if isSome returnv.Marshal || nonNil returnv.CustomAttrs.AsList then
if Option.isSome returnv.Marshal || not (List.isEmpty returnv.CustomAttrs.AsList) then
let pidx = AddUnsharedRow cenv TableNames.Param (GenReturnAsParamRow returnv)
GenCustomAttrsPass3Or4 cenv (hca_ParamDef,pidx) returnv.CustomAttrs
match returnv.Marshal with
Expand Down Expand Up @@ -2770,7 +2770,7 @@ let rec GenTypeDefPass3 enc cenv (td:ILTypeDef) =
match td.Layout with
| ILTypeDefLayout.Auto -> ()
| ILTypeDefLayout.Sequential layout | ILTypeDefLayout.Explicit layout ->
if isSome layout.Pack || isSome layout.Size then
if Option.isSome layout.Pack || Option.isSome layout.Size then
AddUnsharedRow cenv TableNames.ClassLayout
(UnsharedRow
[| UShort (match layout.Pack with None -> uint16 0x0 | Some p -> p)
Expand Down
12 changes: 6 additions & 6 deletions src/fsharp/AttributeChecking.fs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ let private CheckILAttributes g cattrs m =
/// Check F# attributes for 'ObsoleteAttribute', 'CompilerMessageAttribute' and 'ExperimentalAttribute',
/// returning errors and warnings as data
let CheckFSharpAttributes g attribs m =
if isNil attribs then CompleteD
if List.isEmpty attribs then CompleteD
else
(match TryFindFSharpAttribute g g.attrib_SystemObsolete attribs with
| Some(Attrib(_,_,[ AttribStringArg s ],_,_,_,_)) ->
Expand Down Expand Up @@ -338,12 +338,12 @@ let private CheckProvidedAttributes g m (provAttribs: Tainted<IProvidedCustomAtt
/// Indicate if a list of IL attributes contains 'ObsoleteAttribute'. Used to suppress the item in intellisense.
let CheckILAttributesForUnseen g cattrs _m =
let (AttribInfo(tref,_)) = g.attrib_SystemObsolete
isSome (TryDecodeILAttribute g tref cattrs)
Option.isSome (TryDecodeILAttribute g tref cattrs)

/// Checks the attributes for CompilerMessageAttribute, which has an IsHidden argument that allows
/// items to be suppressed from intellisense.
let CheckFSharpAttributesForHidden g attribs =
nonNil attribs &&
not (List.isEmpty attribs) &&
(match TryFindFSharpAttribute g g.attrib_CompilerMessageAttribute attribs with
| Some(Attrib(_,_,[AttribStringArg _; AttribInt32Arg messageNumber],
ExtractAttribNamedArg "IsHidden" (AttribBoolArg v),_,_,_)) ->
Expand All @@ -354,13 +354,13 @@ let CheckFSharpAttributesForHidden g attribs =

/// Indicate if a list of F# attributes contains 'ObsoleteAttribute'. Used to suppress the item in intellisense.
let CheckFSharpAttributesForObsolete g attribs =
nonNil attribs && (HasFSharpAttribute g g.attrib_SystemObsolete attribs)
not (List.isEmpty attribs) && (HasFSharpAttribute g g.attrib_SystemObsolete attribs)

/// Indicate if a list of F# attributes contains 'ObsoleteAttribute'. Used to suppress the item in intellisense.
/// Also check the attributes for CompilerMessageAttribute, which has an IsHidden argument that allows
/// items to be suppressed from intellisense.
let CheckFSharpAttributesForUnseen g attribs _m =
nonNil attribs &&
not (List.isEmpty attribs) &&
(CheckFSharpAttributesForObsolete g attribs ||
CheckFSharpAttributesForHidden g attribs)

Expand Down Expand Up @@ -402,7 +402,7 @@ let CheckMethInfoAttributes g m tyargsOpt minfo =
(fun fsAttribs ->
let res =
CheckFSharpAttributes g fsAttribs m ++ (fun () ->
if isNone tyargsOpt && HasFSharpAttribute g g.attrib_RequiresExplicitTypeArgumentsAttribute fsAttribs then
if Option.isNone tyargsOpt && HasFSharpAttribute g g.attrib_RequiresExplicitTypeArgumentsAttribute fsAttribs then
ErrorD(Error(FSComp.SR.tcFunctionRequiresExplicitTypeArguments(minfo.LogicalName),m))
else
CompleteD)
Expand Down
Loading