未验证 提交 d4eabe21 编写于 作者: E Eugene Auduchinok 提交者: GitHub

Remove getting needless list length (#12998)

* Remove getting needless list length

* Cleanup

* Update illib.fs

* List.isSingleItem -> List.isSingleton
Co-authored-by: NDon Syme <dsyme@users.noreply.github.com>
上级 c44b8112
......@@ -376,8 +376,9 @@ let mkUnionCompare g tcref (tycon: Tycon) =
let dtree = TDSwitch(thise, cases, dflt, m)
mbuilder.Close(dtree, m, g.int_ty)
let expr =
if ucases.Length = 1 then expr else
let expr =
if List.isSingleton ucases then expr else
let tagsEqTested =
mkCond DebugPointAtBinding.NoneAtSticky m g.int_ty
(mkILAsmCeq g m thistage thattage)
......@@ -437,8 +438,9 @@ let mkUnionCompareWithComparer g tcref (tycon: Tycon) (_thisv, thise) (_thatobjv
let dtree = TDSwitch(thise, cases, dflt, m)
mbuilder.Close(dtree, m, g.int_ty)
let expr =
if ucases.Length = 1 then expr else
let expr =
if List.isSingleton ucases then expr else
let tagsEqTested =
mkCond DebugPointAtBinding.NoneAtSticky m g.int_ty
(mkILAsmCeq g m thistage thattage)
......@@ -497,8 +499,9 @@ let mkUnionEquality g tcref (tycon: Tycon) =
let dtree = TDSwitch(thise, cases, dflt, m)
mbuilder.Close(dtree, m, g.bool_ty)
let expr =
if ucases.Length = 1 then expr else
let expr =
if List.isSingleton ucases then expr else
let tagsEqTested =
mkCond DebugPointAtBinding.NoneAtSticky m g.bool_ty
(mkILAsmCeq g m thistage thattage)
......@@ -559,8 +562,9 @@ let mkUnionEqualityWithComparer g tcref (tycon: Tycon) (_thisv, thise) thatobje
let dtree = TDSwitch(thise, cases, dflt, m)
mbuilder.Close(dtree, m, g.bool_ty)
let expr =
if ucases.Length = 1 then expr else
let expr =
if List.isSingleton ucases then expr else
let tagsEqTested =
mkCond DebugPointAtBinding.NoneAtSticky m g.bool_ty
(mkILAsmCeq g m thistage thattage)
......
......@@ -326,9 +326,15 @@ let TcComputationExpression (cenv: cenv) env (overallTy: OverallTy) tpenv (mWhol
|> dict
/// Decide if the identifier represents a use of a custom query operator
let tryGetDataForCustomOperation (nm: Ident) =
let tryGetDataForCustomOperation (nm: Ident) =
let isOpDataCountAllowed opDatas =
match opDatas with
| [_] -> true
| _ :: _ -> cenv.g.langVersion.SupportsFeature LanguageFeature.OverloadsForCustomOperations
| _ -> false
match customOperationMethodsIndexedByKeyword.TryGetValue nm.idText with
| true, opDatas when (opDatas.Length = 1 || (opDatas.Length > 0 && cenv.g.langVersion.SupportsFeature LanguageFeature.OverloadsForCustomOperations)) ->
| true, opDatas when isOpDataCountAllowed opDatas ->
for opData in opDatas do
let opName, maintainsVarSpaceUsingBind, maintainsVarSpace, _allowInto, isLikeZip, isLikeJoin, isLikeGroupJoin, _joinConditionWord, methInfo = opData
if (maintainsVarSpaceUsingBind && maintainsVarSpace) || (isLikeZip && isLikeJoin) || (isLikeZip && isLikeGroupJoin) || (isLikeJoin && isLikeGroupJoin) then
......@@ -1907,10 +1913,10 @@ let TcSequenceExpression (cenv: cenv) env tpenv comp (overallTy: OverallTy) m =
//
// This transformation is visible in quotations and thus needs to remain.
| (TPat_as (TPat_wild _, PBind (v, _), _),
vs,
[_],
DebugPoints(Expr.App (Expr.Val (vf, _, _), _, [genEnumElemTy], [yieldExpr], _mYield), recreate))
when vs.Length = 1 && valRefEq cenv.g vf cenv.g.seq_singleton_vref ->
when valRefEq cenv.g vf cenv.g.seq_singleton_vref ->
// The debug point mFor is attached to the 'map'
// The debug point mIn is attached to the lambda
// Note: the 'yield' part of the debug point for 'yield expr' is currently lost in debug points.
......
......@@ -4658,7 +4658,7 @@ module TcDeclarations =
let _, tcref =
match ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.Binding OpenQualified envForDecls.NameEnv ad longPath resInfo PermitDirectReferenceToGeneratedType.No with
| Result res -> res
| res when inSig && longPath.Length = 1 ->
| res when inSig && List.isSingleton longPath ->
errorR(Deprecated(FSComp.SR.tcReservedSyntaxForAugmentation(), m))
ForceRaise res
| res -> ForceRaise res
......
......@@ -903,9 +903,10 @@ let TcFieldInit (_m: range) lit = ilFieldToTastConst lit
// Adjust the arities that came from the parsing of the toptyp (arities) to be a valSynData.
// This means replacing the "[unitArg]" arising from a "unit -> ty" with a "[]".
let AdjustValSynInfoInSignature g ty (SynValInfo(argsData, retData) as sigMD) =
if argsData.Length = 1 && argsData.Head.Length = 1 && isFunTy g ty && typeEquiv g g.unit_ty (domainOfFunTy g ty) then
match argsData with
| [[_]] when isFunTy g ty && typeEquiv g g.unit_ty (domainOfFunTy g ty) ->
SynValInfo(argsData.Head.Tail :: argsData.Tail, retData)
else
| _ ->
sigMD
/// The ValReprInfo for a value, except the number of typars is not yet inferred
......
......@@ -1699,10 +1699,10 @@ and SolveMemberConstraint (csenv: ConstraintSolverEnv) ignoreUnresolvedOverload
| "?>=" | "?>" | "?<=" | "?<" | "?=" | "?<>"
| ">=?" | ">?" | "<=?" | "<?" | "=?" | "<>?"
| "?>=?" | "?>?" | "?<=?" | "?<?" | "?=?" | "?<>?" ->
if tys.Length = 1 then FSComp.SR.csTypeDoesNotSupportOperatorNullable(tyString, opName)
if List.isSingleton tys then FSComp.SR.csTypeDoesNotSupportOperatorNullable(tyString, opName)
else FSComp.SR.csTypesDoNotSupportOperatorNullable(tyString, opName)
| _ ->
if tys.Length = 1 then FSComp.SR.csTypeDoesNotSupportOperator(tyString, opName)
| _ ->
if List.isSingleton tys then FSComp.SR.csTypeDoesNotSupportOperator(tyString, opName)
else FSComp.SR.csTypesDoNotSupportOperator(tyString, opName)
return! ErrorD(ConstraintSolverError(err, m, m2))
......
......@@ -164,7 +164,7 @@ module DispatchSlotChecking =
match vsl with
| [thisv] :: vs ->
// Check for empty variable list from a () arg
let vs = if vs.Length = 1 && argInfos.IsEmpty then [] else vs
let vs = if List.isSingleton vs && argInfos.IsEmpty then [] else vs
let implKind =
if isInterfaceTy g implty then
CanImplementAnyInterfaceSlot
......
......@@ -1246,7 +1246,7 @@ and private CanAutoOpenTyconRef (g: TcGlobals) m (tcref: TyconRef) =
g.langVersion.SupportsFeature LanguageFeature.OpenTypeDeclaration &&
not tcref.IsILTycon &&
TryFindFSharpBoolAttribute g g.attrib_AutoOpenAttribute tcref.Attribs = Some true &&
tcref.Typars(m).Length = 0
tcref.Typars(m) |> List.isEmpty
/// Add any implied contents of a type definition to the environment.
and private AddPartsOfTyconRefToNameEnv bulkAddMode ownDefinition (g: TcGlobals) amap ad m nenv (tcref: TyconRef) =
......
......@@ -3314,7 +3314,7 @@ and StripPreComputationsFromComputedFunction g f0 args mkApp =
fs, (remake >> (fun innerExprR -> Expr.DebugPoint (dp, innerExprR)))
| _ ->
[f], (fun newExprs -> (assert (newExprs.Length = 1)); List.head newExprs)
[f], (fun newExprs -> (assert (List.isSingleton newExprs)); List.head newExprs)
match strip f0 with
| [f], remake ->
......
......@@ -722,7 +722,7 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
| Some witnessArgIdx ->
let witnessR = QP.mkVar witnessArgIdx
let args = if args.Length = 0 then [ mkUnit g m ] else args
let args = if List.isEmpty args then [ mkUnit g m ] else args
let argsR = ConvExprs cenv env args
(witnessR, argsR) ||> List.fold (fun fR argR -> QP.mkApp (fR, argR))
......
......@@ -2851,7 +2851,7 @@ module SimplifyTypes =
simplify &&
isTTyparCoercesToType tpc &&
Zset.contains tp singletons &&
tp.Constraints.Length = 1)
List.isSingleton tp.Constraints)
let inplace = inplace |> List.map (function tp, TyparConstraint.CoercesTo(ty, _) -> tp, ty | _ -> failwith "not isTTyparCoercesToType")
{ singletons = singletons
......@@ -9269,23 +9269,29 @@ type Entity with
tycon.TypeContents.tcaug_adhoc
|> NameMultiMap.find nm
|> List.exists (fun vref ->
match vref.MemberInfo with
| None -> false
| Some membInfo ->
let argInfos = ArgInfosOfMember g vref
argInfos.Length = 1 &&
List.lengthsEqAndForall2 (typeEquiv g) (List.map fst (List.head argInfos)) argtys &&
membInfo.MemberFlags.IsOverrideOrExplicitImpl)
match vref.MemberInfo with
| None -> false
| Some membInfo ->
let argInfos = ArgInfosOfMember g vref
match argInfos with
| [argInfos] ->
List.lengthsEqAndForall2 (typeEquiv g) (List.map fst argInfos) argtys &&
membInfo.MemberFlags.IsOverrideOrExplicitImpl
| _ -> false)
member tycon.HasMember g nm argtys =
tycon.TypeContents.tcaug_adhoc
|> NameMultiMap.find nm
|> List.exists (fun vref ->
match vref.MemberInfo with
| None -> false
| _ -> let argInfos = ArgInfosOfMember g vref
argInfos.Length = 1 &&
List.lengthsEqAndForall2 (typeEquiv g) (List.map fst (List.head argInfos)) argtys)
match vref.MemberInfo with
| None -> false
| _ ->
let argInfos = ArgInfosOfMember g vref
match argInfos with
| [argInfos] -> List.lengthsEqAndForall2 (typeEquiv g) (List.map fst argInfos) argtys
| _ -> false)
type EntityRef with
......
......@@ -476,6 +476,11 @@ module List =
| [] -> true
| h::t -> t |> List.forall (fun h2 -> h = h2)
let isSingleton xs =
match xs with
| [_] -> true
| _ -> false
module ResizeArray =
/// Split a ResizeArray into an array of smaller chunks.
......
......@@ -208,6 +208,8 @@ module internal List =
val internal allEqual: xs:'T list -> bool when 'T: equality
val isSingleton: xs: 'T list -> bool
module internal ResizeArray =
/// Split a ResizeArray into an array of smaller chunks.
......
......@@ -2158,8 +2158,9 @@ type PropInfo =
| FSProp(g, _, Some vref, _) ->
// A getter has signature { OptionalObjectType } -> Unit -> PropertyType
// A getter indexer has signature { OptionalObjectType } -> TupledIndexerArguments -> PropertyType
let arginfos = ArgInfosOfMember g vref
arginfos.Length = 1 && arginfos.Head.Length >= 1
match ArgInfosOfMember g vref with
| [argInfos] -> not (List.isEmpty argInfos)
| _ -> false
| FSProp(g, _, _, Some vref) ->
// A setter has signature { OptionalObjectType } -> PropertyType -> Void
// A setter indexer has signature { OptionalObjectType } -> TupledIndexerArguments -> PropertyType -> Void
......
......@@ -517,7 +517,7 @@ module FSharpExprConvert =
// type. There is no witness for this case. This is due to the code
// let inline HashChar (x:char) = (# "or" (# "shl" x 16 : int #) x : int #)
// in FSharp.Core.
| ErrorResult _ when vref.LogicalName = "op_LeftShift" && tyargs.Length = 1 -> []
| ErrorResult _ when vref.LogicalName = "op_LeftShift" && List.isSingleton tyargs -> []
| res -> CommitOperationResult res
let env = { env with suppressWitnesses = true }
witnessExprs |> List.map (fun arg ->
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册