From 8b3cf6b403f25640fbf6fe374f3c9d67e8dddb41 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 6 Mar 2018 10:32:02 +0100 Subject: [PATCH] List.isEmpty instead of iterating through the list to get the count --- src/absil/ilprint.fs | 19 +++++++++---------- src/absil/ilread.fs | 2 +- src/absil/ilwrite.fs | 10 +++++----- src/fsharp/CompileOps.fs | 2 +- src/fsharp/IlxGen.fs | 8 ++++---- src/fsharp/LexFilter.fs | 2 +- src/fsharp/MethodOverrides.fs | 2 +- src/fsharp/NameResolution.fs | 14 +++++++------- src/fsharp/Optimizer.fs | 2 +- src/fsharp/TypeChecker.fs | 27 +++++++++++++-------------- src/fsharp/fsc.fs | 2 +- src/fsharp/fsi/fsi.fs | 2 +- src/fsharp/tast.fs | 2 +- 13 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/absil/ilprint.fs b/src/absil/ilprint.fs index 0344a4fbb5c..abad68c9772 100644 --- a/src/absil/ilprint.fs +++ b/src/absil/ilprint.fs @@ -213,11 +213,10 @@ and goutput_typ_with_shortened_class_syntax env os = function | typ2 -> goutput_typ env os typ2 and goutput_gactuals env os inst = - if inst.Length = 0 then () - else - output_string os "<"; + if not (List.isEmpty inst) then + output_string os "<" output_seq ", " (goutput_gactual env) os inst - output_string os ">"; + output_string os ">" and goutput_gactual env os ty = goutput_typ env os ty @@ -864,14 +863,14 @@ let goutput_superclass env os = function | Some typ -> output_string os "extends "; (goutput_typ_with_shortened_class_syntax env) os typ let goutput_superinterfaces env os imp = - if imp = [] then () else - output_string os "implements "; - output_seq "," (goutput_typ_with_shortened_class_syntax env) os imp + if not (List.isEmpty imp) then + output_string os "implements " + output_seq "," (goutput_typ_with_shortened_class_syntax env) os imp let goutput_implements env os (imp:ILTypes) = - if imp.Length = 0 then () else - output_string os "implements "; - output_seq "," (goutput_typ_with_shortened_class_syntax env) os imp + if not (List.isEmpty imp) then + output_string os "implements " + output_seq "," (goutput_typ_with_shortened_class_syntax env) os imp let the = function Some x -> x | None -> failwith "the" diff --git a/src/absil/ilread.fs b/src/absil/ilread.fs index c1e4ac3b9cf..e89164a42a0 100644 --- a/src/absil/ilread.fs +++ b/src/absil/ilread.fs @@ -1816,7 +1816,7 @@ and seekReadTypeDefOrRef ctxt numtypars boxity (ginst:ILTypes) (TaggedIndex(tag, | tag when tag = tdor_TypeDef -> seekReadTypeDefAsType ctxt boxity ginst idx | tag when tag = tdor_TypeRef -> seekReadTypeRefAsType ctxt boxity ginst idx | tag when tag = tdor_TypeSpec -> - if ginst.Length > 0 then dprintn ("type spec used as type constructor for a generic instantiation: ignoring instantiation") + if not (List.isEmpty ginst) then dprintn ("type spec used as type constructor for a generic instantiation: ignoring instantiation") readBlobHeapAsType ctxt numtypars (seekReadTypeSpecRow ctxt idx) | _ -> failwith "seekReadTypeDefOrRef ctxt" diff --git a/src/absil/ilwrite.fs b/src/absil/ilwrite.fs index 255a3e6193b..e1af01dd561 100644 --- a/src/absil/ilwrite.fs +++ b/src/absil/ilwrite.fs @@ -1307,10 +1307,10 @@ and GetMethodDefOrRefAsUncodedToken (tag, idx) = getUncodedToken tab idx and GetMethodSpecInfoAsUncodedToken cenv env ((_, _, _, _, _, _, minst:ILGenericArgs) as minfo) = - if minst.Length > 0 then - getUncodedToken TableNames.MethodSpec (GetMethodSpecInfoAsMethodSpecIdx cenv env minfo) - else - GetMethodDefOrRefAsUncodedToken (GetMethodRefInfoAsMethodRefOrDef false cenv env (GetMethodRefInfoOfMethodSpecInfo minfo)) + if List.isEmpty minst then + GetMethodDefOrRefAsUncodedToken (GetMethodRefInfoAsMethodRefOrDef false cenv env (GetMethodRefInfoOfMethodSpecInfo minfo)) + else + getUncodedToken TableNames.MethodSpec (GetMethodSpecInfoAsMethodSpecIdx cenv env minfo) and GetMethodSpecAsUncodedToken cenv env mspec = GetMethodSpecInfoAsUncodedToken cenv env (InfoOfMethodSpec mspec) @@ -2475,7 +2475,7 @@ let GenReturnPass3 cenv (returnv: ILReturn) = let GetMethodDefSigAsBytes cenv env (mdef: ILMethodDef) = emitBytesViaBuffer (fun bb -> bb.EmitByte (callconvToByte mdef.GenericParams.Length mdef.CallingConv) - if mdef.GenericParams.Length > 0 then bb.EmitZ32 mdef.GenericParams.Length + if not (List.isEmpty mdef.GenericParams) then bb.EmitZ32 mdef.GenericParams.Length bb.EmitZ32 mdef.Parameters.Length EmitType cenv env bb mdef.Return.Type mdef.ParameterTypes |> List.iter (EmitType cenv env bb)) diff --git a/src/fsharp/CompileOps.fs b/src/fsharp/CompileOps.fs index 7224d157409..069dba4859e 100644 --- a/src/fsharp/CompileOps.fs +++ b/src/fsharp/CompileOps.fs @@ -4287,7 +4287,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti // specified in the attributes |> List.distinctBy (fun s -> try Path.GetFileNameWithoutExtension(s) with _ -> s) - if designTimeAssemblyNames.Length > 0 then + if not (List.isEmpty designTimeAssemblyNames) then // Find the SystemRuntimeAssemblyVersion value to report in the TypeProviderConfig. let primaryAssemblyVersion = diff --git a/src/fsharp/IlxGen.fs b/src/fsharp/IlxGen.fs index edce05ea7b2..704a92f7600 100644 --- a/src/fsharp/IlxGen.fs +++ b/src/fsharp/IlxGen.fs @@ -5188,7 +5188,7 @@ and GenMethodForBinding let permissionSets = CreatePermissionSets cenv.g cenv.amap eenv securityAttributes - let secDecls = if securityAttributes.Length > 0 then (mkILSecurityDecls permissionSets) else (emptyILSecurityDecls) + let secDecls = if List.isEmpty securityAttributes then emptyILSecurityDecls else mkILSecurityDecls permissionSets // Do not push the attributes to the method for events and properties let ilAttrsCompilerGenerated = if v.IsCompilerGenerated then [ cenv.g.CompilerGeneratedAttribute ] else [] @@ -5207,7 +5207,7 @@ and GenMethodForBinding // Does the function have an explicit [] attribute? let isExplicitEntryPoint = HasFSharpAttribute cenv.g cenv.g.attrib_EntryPointAttribute attrs - let mdef = mdef.WithSecurity(securityAttributes.Length > 0).WithPInvoke(hasDllImport) + let mdef = mdef.WithSecurity(not (List.isEmpty securityAttributes)).WithPInvoke(hasDllImport) let mdef = mdef.WithPreserveSig(hasPreserveSigImplFlag || hasPreserveSigNamedArg).WithSynchronized(hasSynchronizedImplFlag).WithNoInlining(hasNoInliningFlag).WithAggressiveInlining(hasAggressiveInliningImplFlag) let mdef = { mdef with @@ -6238,7 +6238,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon:Tycon) = not (HasFSharpAttribute cenv.g cenv.g.attrib_DebuggerTypeProxyAttribute tycon.Attribs)) let permissionSets = CreatePermissionSets cenv.g cenv.amap eenv securityAttrs - let secDecls = if securityAttrs.Length > 0 then (mkILSecurityDecls permissionSets) else (emptyILSecurityDecls) + let secDecls = if List.isEmpty securityAttrs then emptyILSecurityDecls else mkILSecurityDecls permissionSets let ilDebugDisplayAttributes = [ yield! GenAttrs cenv eenv debugDisplayAttrs @@ -6699,7 +6699,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon:Tycon) = | _ -> failwith "??" - let tdef = tdef.WithHasSecurity(securityAttrs.Length > 0) + let tdef = tdef.WithHasSecurity(not (List.isEmpty securityAttrs)) let tdef = { tdef with SecurityDecls = secDecls } diff --git a/src/fsharp/LexFilter.fs b/src/fsharp/LexFilter.fs index 5b9deaf832e..c933a847bbb 100755 --- a/src/fsharp/LexFilter.fs +++ b/src/fsharp/LexFilter.fs @@ -444,7 +444,7 @@ type TokenTup = let (|TyparsCloseOp|_|) (txt:string) = let angles = txt |> Seq.takeWhile (fun c -> c = '>') |> Seq.toList let afterAngles = txt |> Seq.skipWhile (fun c -> c = '>') |> Seq.toList - if angles.Length = 0 then None else + if List.isEmpty angles then None else let afterOp = match (new System.String(Array.ofSeq afterAngles)) with diff --git a/src/fsharp/MethodOverrides.fs b/src/fsharp/MethodOverrides.fs index fdaab282497..2ba55b7f75f 100644 --- a/src/fsharp/MethodOverrides.fs +++ b/src/fsharp/MethodOverrides.fs @@ -709,7 +709,7 @@ let GetAbstractMethInfosForSynMethodDecl(infoReader:InfoReader,ad,memberName:Ide GetIntrinsicMethInfosOfType infoReader (Some(memberName.idText), ad, AllowMultiIntfInstantiations.Yes) IgnoreOverrides bindm ty let dispatchSlots = minfos |> List.filter (fun minfo -> minfo.IsDispatchSlot) let topValSynArities = SynInfo.AritiesOfArgs valSynData - let topValSynArities = if topValSynArities.Length > 0 then topValSynArities.Tail else topValSynArities + let topValSynArities = if List.isEmpty topValSynArities then topValSynArities else topValSynArities.Tail let dispatchSlotsArityMatch = dispatchSlots |> List.filter (fun minfo -> minfo.NumArgs = topValSynArities) dispatchSlots,dispatchSlotsArityMatch diff --git a/src/fsharp/NameResolution.fs b/src/fsharp/NameResolution.fs index dcbc1f074ec..822bb76a5b2 100644 --- a/src/fsharp/NameResolution.fs +++ b/src/fsharp/NameResolution.fs @@ -568,7 +568,7 @@ let AddValRefToNameEnv nenv (vref:ValRef) = /// Add a set of active pattern result tags to the environment. let AddActivePatternResultTagsToNameEnv (apinfo: PrettyNaming.ActivePatternInfo) nenv ty m = - if apinfo.Names.Length = 0 then nenv else + if List.isEmpty apinfo.Names then nenv else let apresl = List.indexed apinfo.Names { nenv with eUnqualifiedItems = @@ -675,13 +675,13 @@ let private AddPartsOfTyconRefToNameEnv bulkAddMode ownDefinition (g:TcGlobals) | _ -> Item.UnqualifiedType [tcref])) else tab - if isILOrRequiredQualifiedAccess || ucrefs.Length = 0 then + if isILOrRequiredQualifiedAccess || List.isEmpty ucrefs then tab else AddUnionCases2 bulkAddMode tab ucrefs let ePatItems = - if isILOrRequiredQualifiedAccess || ucrefs.Length = 0 then + if isILOrRequiredQualifiedAccess || List.isEmpty ucrefs then nenv.ePatItems else AddUnionCases1 nenv.ePatItems ucrefs @@ -1725,14 +1725,14 @@ let CheckForTypeLegitimacyAndMultipleGenericTypeAmbiguities // no explicit type instantiation typeNameResInfo.StaticArgsInfo.HasNoStaticArgsInfo && // some type arguments required on all types (note sorted by typar count above) - tcref.Typars(m).Length > 0 && + not (List.isEmpty (tcref.Typars m)) && // plausible types have different arities (tcrefs |> Seq.distinctBy (fun (_,tcref) -> tcref.Typars(m).Length) |> Seq.length > 1) -> [ for (resInfo,tcref) in tcrefs do let resInfo = resInfo.AddWarning (fun _typarChecker -> errorR(Error(FSComp.SR.nrTypeInstantiationNeededToDisambiguateTypesWithSameName(tcref.DisplayName, tcref.DisplayNameWithStaticParametersAndUnderscoreTypars),m))) yield (resInfo,tcref) ] - | [(resInfo,tcref)] when typeNameResInfo.StaticArgsInfo.HasNoStaticArgsInfo && tcref.Typars(m).Length > 0 && typeNameResInfo.ResolutionFlag = ResolveTypeNamesToTypeRefs -> + | [(resInfo,tcref)] when typeNameResInfo.StaticArgsInfo.HasNoStaticArgsInfo && not (List.isEmpty (tcref.Typars m)) && typeNameResInfo.ResolutionFlag = ResolveTypeNamesToTypeRefs -> let resInfo = resInfo.AddWarning (fun (ResultTyparChecker typarChecker) -> if not (typarChecker()) then @@ -3223,9 +3223,9 @@ let NeedsWorkAfterResolution namedItem = | Item.CtorGroup(_,minfos) -> minfos.Length > 1 || minfos |> List.exists (fun minfo -> not (isNil minfo.FormalMethodInst)) | Item.Property(_,pinfos) -> pinfos.Length > 1 | Item.ImplicitOp(_, { contents = Some(TraitConstraintSln.FSMethSln(_, vref, _)) }) - | Item.Value vref | Item.CustomBuilder (_,vref) -> vref.Typars.Length > 0 + | Item.Value vref | Item.CustomBuilder (_,vref) -> not (List.isEmpty vref.Typars) | Item.CustomOperation (_,_,Some minfo) -> not (isNil minfo.FormalMethodInst) - | Item.ActivePatternCase apref -> apref.ActivePatternVal.Typars.Length > 0 + | Item.ActivePatternCase apref -> not (List.isEmpty apref.ActivePatternVal.Typars) | _ -> false /// Specifies additional work to do after an item has been processed further in type checking. diff --git a/src/fsharp/Optimizer.fs b/src/fsharp/Optimizer.fs index d107cd1a78b..7ce763fede8 100644 --- a/src/fsharp/Optimizer.fs +++ b/src/fsharp/Optimizer.fs @@ -2507,7 +2507,7 @@ and TryInlineApplication cenv env finfo (tyargs: TType list, args: Expr list, m) false else true)))) -> - let isBaseCall = args.Length > 0 && + let isBaseCall = not (List.isEmpty args) && match args.[0] with | Expr.Val(vref, _, _) when vref.BaseOrThisInfo = BaseVal -> true | _ -> false diff --git a/src/fsharp/TypeChecker.fs b/src/fsharp/TypeChecker.fs index 3a1fa009c4f..20b79d67ffc 100755 --- a/src/fsharp/TypeChecker.fs +++ b/src/fsharp/TypeChecker.fs @@ -2810,7 +2810,7 @@ let TcVal checkAttributes cenv env tpenv (vref:ValRef) optInst optAfterResolutio // If we have got an explicit instantiation then use that | Some(vrefFlags, checkTys) -> let checkInst (tinst:TypeInst) = - if not v.IsMember && not v.PermitsExplicitTypeInstantiation && tinst.Length > 0 && v.Typars.Length > 0 then + if not v.IsMember && not v.PermitsExplicitTypeInstantiation && not (List.isEmpty tinst) && not (List.isEmpty v.Typars) then warning(Error(FSComp.SR.tcDoesNotAllowExplicitTypeArguments(v.DisplayName), m)) match vrec with | ValInRecScope false -> @@ -7493,13 +7493,13 @@ and TcComputationExpression cenv env overallTy mWhole interpExpr builderTy tpenv | StripApps(SingleIdent nm, [StripApps(SingleIdent nm2, args); arg2]) when PrettyNaming.IsInfixOperator nm.idText && expectedArgCountForCustomOperator nm2 > 0 && - args.Length > 0 -> + not (List.isEmpty args) -> let estimatedRangeOfIntendedLeftAndRightArguments = unionRanges (List.last args).Range arg2.Range errorR(Error(FSComp.SR.tcUnrecognizedQueryBinaryOperator(), estimatedRangeOfIntendedLeftAndRightArguments)) true | SynExpr.Tuple( (StripApps(SingleIdent nm2, args) :: _), _, m) when expectedArgCountForCustomOperator nm2 > 0 && - args.Length > 0 -> + not (List.isEmpty args) -> let estimatedRangeOfIntendedLeftAndRightArguments = unionRanges (List.last args).Range m.EndRange errorR(Error(FSComp.SR.tcUnrecognizedQueryBinaryOperator(), estimatedRangeOfIntendedLeftAndRightArguments)) true @@ -11252,7 +11252,7 @@ and AnalyzeAndMakeAndPublishRecursiveValue overridesOK isGeneratedEventVal cenv let prelimTyscheme = TypeScheme(enclosingDeclaredTypars@declaredTypars, ty) let partialValReprInfo = TranslateTopValSynInfo mBinding (TcAttributes cenv envinner) valSynInfo let topValInfo = UseSyntacticArity declKind prelimTyscheme partialValReprInfo - let hasDeclaredTypars = declaredTypars.Length > 0 + let hasDeclaredTypars = not (List.isEmpty declaredTypars) let prelimValScheme = ValScheme(bindingId, prelimTyscheme, topValInfo, memberInfoOpt, false, inlineFlag, NormalVal, vis, false, false, false, hasDeclaredTypars) // Check the literal r.h.s., if any @@ -13574,14 +13574,14 @@ module MutRecBindingChecking = let ad = env.eAccessRights let mvvs = ForceRaise (ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m OpenQualified env.eNameResEnv ad p false) let modrefs = mvvs |> List.map p23 - if modrefs.Length > 0 && modrefs |> List.forall (fun modref -> modref.IsNamespace) then + if not (List.isEmpty modrefs) && modrefs |> List.forall (fun modref -> modref.IsNamespace) then errorR(Error(FSComp.SR.tcModuleAbbreviationForNamespace(fullDisplayTextOfModRef (List.head modrefs)), m)) let modrefs = modrefs |> List.filter (fun mvv -> not mvv.IsNamespace) + if List.isEmpty modrefs then env else modrefs |> List.iter (fun modref -> CheckEntityAttributes cenv.g modref m |> CommitOperationResult) - let env = (if modrefs.Length > 0 then AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env else env) + let env = AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env env - /// Update the contents accessible via the recursive namespace declaration, if any let TcMutRecDefns_UpdateNSContents mutRecNSInfo = match mutRecNSInfo with @@ -15128,10 +15128,10 @@ module EstablishTypeDefinitionCores = if allowed then if kind = explicitKind then warning(PossibleUnverifiableCode(m)) - elif thisTyconRef.Typars(m).Length > 0 then - errorR (Error(FSComp.SR.tcGenericTypesCannotHaveStructLayout(), m)) - else + elif List.isEmpty (thisTyconRef.Typars m) then errorR (Error(FSComp.SR.tcOnlyStructsCanHaveStructLayout(), m)) + else + errorR (Error(FSComp.SR.tcGenericTypesCannotHaveStructLayout(), m)) | None -> () let hiddenReprChecks(hasRepr) = @@ -16361,14 +16361,13 @@ let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synS let modrefs = unfilteredModrefs |> List.filter (fun modref -> not modref.IsNamespace) - if unfilteredModrefs.Length > 0 && List.isEmpty modrefs then + if not (List.isEmpty unfilteredModrefs) && List.isEmpty modrefs then errorR(Error(FSComp.SR.tcModuleAbbreviationForNamespace(fullDisplayTextOfModRef (List.head unfilteredModrefs)), m)) + if List.isEmpty modrefs then return env else modrefs |> List.iter (fun modref -> CheckEntityAttributes cenv.g modref m |> CommitOperationResult) - let env = - if modrefs.Length > 0 then AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env - else env + let env = AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env return env | SynModuleSigDecl.HashDirective _ -> diff --git a/src/fsharp/fsc.fs b/src/fsharp/fsc.fs index 345071f35ed..699b6c52ec8 100644 --- a/src/fsharp/fsc.fs +++ b/src/fsharp/fsc.fs @@ -1966,7 +1966,7 @@ let main2b (tcImportsCapture,dynamicAssemblyCreator) (Args (ctok, tcConfig: TcCo // remove any security attributes from the top-level assembly attribute list let topAttrs = {topAttrs with assemblyAttrs=topAssemblyAttrs} let permissionSets = ilxGenerator.CreatePermissionSets securityAttrs - let secDecls = if securityAttrs.Length > 0 then mkILSecurityDecls permissionSets else emptyILSecurityDecls + let secDecls = if List.isEmpty securityAttrs then emptyILSecurityDecls else mkILSecurityDecls permissionSets let ilxMainModule = MainModuleBuilder.CreateMainModule (ctok, tcConfig, tcGlobals, tcImports, pdbfile, assemblyName, outfile, topAttrs, idata, optDataResources, codegenResults, assemVerFromAttrib, metadataVersion, secDecls) diff --git a/src/fsharp/fsi/fsi.fs b/src/fsharp/fsi/fsi.fs index 8f0fbc9c814..b0d55326c4a 100644 --- a/src/fsharp/fsi/fsi.fs +++ b/src/fsharp/fsi/fsi.fs @@ -2029,7 +2029,7 @@ type internal FsiInteractionProcessor // When the last declaration has a shape of DoExp (i.e., non-binding), // transform it to a shape of "let it = ", so we can refer it. - let defsA = if defsA.Length <= 1 || defsB.Length > 0 then defsA else + let defsA = if defsA.Length <= 1 || not (List.isEmpty defsB) then defsA else match List.headAndTail (List.rev defsA) with | SynModuleDecl.DoExpr(_,exp,_), rest -> (rest |> List.rev) @ (fsiDynamicCompiler.BuildItBinding exp) | _ -> defsA diff --git a/src/fsharp/tast.fs b/src/fsharp/tast.fs index ea3c0e2de0e..58a348c1861 100755 --- a/src/fsharp/tast.fs +++ b/src/fsharp/tast.fs @@ -604,7 +604,7 @@ type Entity = | [] -> nm | tps -> let nm = DemangleGenericTypeName nm - if withUnderscoreTypars && tps.Length > 0 then + if withUnderscoreTypars && not (List.isEmpty tps) then nm + "<" + String.concat "," (Array.create tps.Length "_") + ">" else nm