Skip to content

Commit

Permalink
Remove getting needless list length
Browse files Browse the repository at this point in the history
  • Loading branch information
auduchinok committed Apr 15, 2022
1 parent 14a3b17 commit c465043
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 41 deletions.
20 changes: 16 additions & 4 deletions src/fsharp/AugmentWithHashCompare.fs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ let mkUnionCompare g tcref (tycon: Tycon) =
mbuilder.Close(dtree, m, g.int_ty)

let expr =
if ucases.Length = 1 then expr else
match ucases with
| [_] -> expr
| _ ->

let tagsEqTested =
mkCond DebugPointAtBinding.NoneAtSticky m g.int_ty
(mkILAsmCeq g m thistage thattage)
Expand Down Expand Up @@ -438,7 +441,10 @@ let mkUnionCompareWithComparer g tcref (tycon: Tycon) (_thisv, thise) (_thatobjv
mbuilder.Close(dtree, m, g.int_ty)

let expr =
if ucases.Length = 1 then expr else
match ucases with
| [_] -> expr
| _ ->

let tagsEqTested =
mkCond DebugPointAtBinding.NoneAtSticky m g.int_ty
(mkILAsmCeq g m thistage thattage)
Expand Down Expand Up @@ -498,7 +504,10 @@ let mkUnionEquality g tcref (tycon: Tycon) =
mbuilder.Close(dtree, m, g.bool_ty)

let expr =
if ucases.Length = 1 then expr else
match ucases with
| [_] -> expr
| _ ->

let tagsEqTested =
mkCond DebugPointAtBinding.NoneAtSticky m g.bool_ty
(mkILAsmCeq g m thistage thattage)
Expand Down Expand Up @@ -560,7 +569,10 @@ let mkUnionEqualityWithComparer g tcref (tycon: Tycon) (_thisv, thise) thatobje
mbuilder.Close(dtree, m, g.bool_ty)

let expr =
if ucases.Length = 1 then expr else
match ucases with
| [_] -> expr
| _ ->

let tagsEqTested =
mkCond DebugPointAtBinding.NoneAtSticky m g.bool_ty
(mkILAsmCeq g m thistage thattage)
Expand Down
16 changes: 11 additions & 5 deletions src/fsharp/CheckComputationExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions src/fsharp/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4655,13 +4655,14 @@ module TcDeclarations =

| _ ->
let resInfo = TypeNameResolutionStaticArgsInfo.FromTyArgs synTypars.Length
let res = ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.Binding OpenQualified envForDecls.NameEnv ad longPath resInfo PermitDirectReferenceToGeneratedType.No
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 ->
match res, inSig, longPath with
| Result res, _, _ -> res
| res, true, [_] ->
errorR(Deprecated(FSComp.SR.tcReservedSyntaxForAugmentation(), m))
ForceRaise res
| res -> ForceRaise res
| res, _, _ -> ForceRaise res
tcref

let isInterfaceOrDelegateOrEnum =
Expand Down
5 changes: 3 additions & 2 deletions src/fsharp/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/fsharp/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1699,11 +1699,13 @@ and SolveMemberConstraint (csenv: ConstraintSolverEnv) ignoreUnresolvedOverload
| "?>=" | "?>" | "?<=" | "?<" | "?=" | "?<>"
| ">=?" | ">?" | "<=?" | "<?" | "=?" | "<>?"
| "?>=?" | "?>?" | "?<=?" | "?<?" | "?=?" | "?<>?" ->
if tys.Length = 1 then FSComp.SR.csTypeDoesNotSupportOperatorNullable(tyString, opName)
else FSComp.SR.csTypesDoNotSupportOperatorNullable(tyString, opName)
match tys with
| [_] -> FSComp.SR.csTypeDoesNotSupportOperatorNullable(tyString, opName)
| _ -> FSComp.SR.csTypesDoNotSupportOperatorNullable(tyString, opName)
| _ ->
if tys.Length = 1 then FSComp.SR.csTypeDoesNotSupportOperator(tyString, opName)
else FSComp.SR.csTypesDoNotSupportOperator(tyString, opName)
match tys with
| [_] -> FSComp.SR.csTypeDoesNotSupportOperator(tyString, opName)
| _ -> FSComp.SR.csTypesDoNotSupportOperator(tyString, opName)
return! ErrorD(ConstraintSolverError(err, m, m2))

| _ ->
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/MethodOverrides.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = match vs, argInfos with | [_], [] -> [] | _ -> vs
let implKind =
if isInterfaceTy g implty then
CanImplementAnyInterfaceSlot
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (match newExprs with [_] -> true | _ -> false)); List.head newExprs)

match strip f0 with
| [f], remake ->
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/QuotationTranslator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
32 changes: 19 additions & 13 deletions src/fsharp/TypedTreeOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2851,7 +2851,7 @@ module SimplifyTypes =
simplify &&
isTTyparCoercesToType tpc &&
Zset.contains tp singletons &&
tp.Constraints.Length = 1)
match tp.Constraints with [_] -> true | _ -> false)
let inplace = inplace |> List.map (function tp, TyparConstraint.CoercesTo(ty, _) -> tp, ty | _ -> failwith "not isTTyparCoercesToType")

{ singletons = singletons
Expand Down Expand Up @@ -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
| [argInfo] ->
List.lengthsEqAndForall2 (typeEquiv g) (List.map fst argInfo) 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
| [argInfo] -> List.lengthsEqAndForall2 (typeEquiv g) (List.map fst argInfo) argtys
| _ -> false)


type EntityRef with
Expand Down
5 changes: 3 additions & 2 deletions src/fsharp/infos.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
| [_ :: _] -> true
| _ -> false
| FSProp(g, _, _, Some vref) ->
// A setter has signature { OptionalObjectType } -> PropertyType -> Void
// A setter indexer has signature { OptionalObjectType } -> TupledIndexerArguments -> PropertyType -> Void
Expand Down
6 changes: 3 additions & 3 deletions src/fsharp/symbols/Exprs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,13 @@ module FSharpExprConvert =
let g = cenv.g
if g.langVersion.SupportsFeature(Features.LanguageFeature.WitnessPassing) && not env.suppressWitnesses then
let witnessExprs =
match ConstraintSolver.CodegenWitnessesForTyparInst cenv.tcValF g cenv.amap m tps tyargs with
match ConstraintSolver.CodegenWitnessesForTyparInst cenv.tcValF g cenv.amap m tps tyargs, tyargs with
// There is a case where optimized code makes expressions that do a shift-left on the 'char'
// 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 -> []
| res -> CommitOperationResult res
| ErrorResult _, [_] when vref.LogicalName = "op_LeftShift" -> []
| res, _ -> CommitOperationResult res
let env = { env with suppressWitnesses = true }
witnessExprs |> List.map (fun arg ->
match arg with
Expand Down

0 comments on commit c465043

Please sign in to comment.