Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8dcfd9a

Browse files
author
dotnet-automerge-bot
authored
Merge pull requestdotnet#5650 from Microsoft/merges/master-to-dev16.0
Merge master to dev16.0
2 parents6b0f185 +5e8352b commit8dcfd9a

File tree

31 files changed

+337
-188
lines changed

31 files changed

+337
-188
lines changed

‎src/fsharp/NameResolution.fs‎

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,30 +3829,27 @@ let TryToResolveLongIdentAsType (ncenv: NameResolver) (nenv: NameResolutionEnv)
38293829
match List.tryLast plidwith
38303830
| Some id->
38313831
// Look for values called 'id' that accept the dot-notation
3832-
letty,isItemVal=
3833-
(match nenv.eUnqualifiedItems|> Map.tryFind idwith
3832+
letty=
3833+
match nenv.eUnqualifiedItems|> Map.tryFind idwith
38343834
// v.lookup : member of a value
3835-
| Some v->
3836-
match vwith
3837-
| Item.Value x->
3838-
letty= x.Type
3839-
letty=if x.BaseOrThisInfo= CtorThisVal&& isRefCellTy g tythen destRefCellTy g tyelse ty
3840-
Some ty,true
3841-
|_-> None,false
3842-
| None-> None,false)
3843-
3844-
if isItemValthen ty
3845-
else
3846-
(ty, LookupTypeNameInEnvNoArity OpenQualified id nenv)
3847-
||> List.fold(fun resTy tcref->
3848-
// type.lookup : lookup a static something in a type
3835+
| Some v->
3836+
match vwith
3837+
| Item.Value x->
3838+
letty= x.Type
3839+
letty=if x.BaseOrThisInfo= CtorThisVal&& isRefCellTy g tythen destRefCellTy g tyelse ty
3840+
Some ty
3841+
|_-> None
3842+
| None-> None
3843+
3844+
match tywith
3845+
| Some_-> ty
3846+
|_->
3847+
// type.lookup : lookup a static something in a type
3848+
LookupTypeNameInEnvNoArity OpenQualified id nenv
3849+
|> List.tryHead
3850+
|> Option.map(fun tcref->
38493851
lettcref= ResolveNestedTypeThroughAbbreviation ncenv tcref m
3850-
letty= FreshenTycon ncenv m tcref
3851-
letresTy=
3852-
match resTywith
3853-
| Some_-> resTy
3854-
| None-> Some ty
3855-
resTy)
3852+
FreshenTycon ncenv m tcref)
38563853
|_-> None
38573854

38583855
/// allowObsolete - specifies whether we should return obsolete types & modules

‎src/fsharp/Optimizer.fs‎

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,84 @@ let rec (|KnownValApp|_|) expr =
13821382
| Expr.App(KnownValApp(vref, typeArgs1, otherArgs1),_, typeArgs2, otherArgs2,_)-> Some(vref, typeArgs1@typeArgs2, otherArgs1@otherArgs2)
13831383
|_-> None
13841384

1385+
/// Matches boolean decision tree:
1386+
/// check single case with bool const.
1387+
let(|TDBoolSwitch|_|)dtree=
1388+
match dtreewith
1389+
| TDSwitch( expr,[TCase(DecisionTreeTest.Const(Const.Bool testBool), caseTree)], Some defaultTree, range)->
1390+
Some(expr, testBool, caseTree, defaultTree, range)
1391+
|_->
1392+
None
1393+
1394+
/// Check target that have a constant bool value
1395+
let(|ConstantBoolTarget|_|)target=
1396+
match targetwith
1397+
| TTarget([], Expr.Const(Const.Bool b,_,_),_)-> Some b
1398+
|_-> None
1399+
1400+
/// Is this a tree, where each decision is a two-way switch (to prevent later duplication of trees), and each branch returns or true/false,
1401+
/// apart from one branch which defers to another expression
1402+
let recCountBoolLogicTree((targets:DecisionTreeTarget[],costOuterCaseTree,costOuterDefaultTree,testBool)as data)tree=
1403+
match treewith
1404+
| TDSwitch(_expr,[case], Some defaultTree,_range)->
1405+
lettc1,ec1= CountBoolLogicTree data case.CaseTree
1406+
lettc2,ec2= CountBoolLogicTree data defaultTree
1407+
tc1+ tc2, ec1+ ec2
1408+
| TDSuccess([], idx)->
1409+
match targets.[idx]with
1410+
| ConstantBoolTarget result->(if result= testBoolthen costOuterCaseTreeelse costOuterDefaultTree),0
1411+
| TTarget([],_exp,_)-> costOuterCaseTree+ costOuterDefaultTree,10
1412+
|_->100,100
1413+
|_->100,100
1414+
1415+
/// Rewrite a decision tree for which CountBoolLogicTree returned a low number (see below). Produce a new decision
1416+
/// tree where at each ConstantBoolSuccessTree tip we replace with either outerCaseTree or outerDefaultTree
1417+
/// depending on whether the target result was true/false
1418+
let recRewriteBoolLogicTree((targets:DecisionTreeTarget[],outerCaseTree,outerDefaultTree,testBool)as data)tree=
1419+
match treewith
1420+
| TDSwitch(expr, cases, defaultTree, range)->
1421+
letcases2= cases|> List.map(RewriteBoolLogicCase data)
1422+
letdefaultTree2= defaultTree|> Option.map(RewriteBoolLogicTree data)
1423+
TDSwitch(expr, cases2, defaultTree2, range)
1424+
| TDSuccess([], idx)->
1425+
match targets.[idx]with
1426+
| ConstantBoolTarget result->if result= testBoolthen outerCaseTreeelse outerDefaultTree
1427+
| TTarget([], exp,_)-> mkBoolSwitch exp.Range exp(if testBoolthen outerCaseTreeelse outerDefaultTree)(if testBoolthen outerDefaultTreeelse outerCaseTree)
1428+
|_-> failwith"CountBoolLogicTree should exclude this case"
1429+
|_-> failwith"CountBoolLogicTree should exclude this case"
1430+
1431+
andRewriteBoolLogicCase data(TCase(test,tree))=
1432+
TCase(test, RewriteBoolLogicTree data tree)
1433+
1434+
/// Repeatedly combine switch-over-match decision trees, see https://github.com/Microsoft/visualfsharp/issues/635.
1435+
/// The outer decision tree is doing a swithc over a boolean result, the inner match is producing only
1436+
/// constant boolean results in its targets.
1437+
let recCombineBoolLogic expr=
1438+
1439+
// try to find nested boolean switch
1440+
match exprwith
1441+
| Expr.Match(outerSP, outerMatchRange,
1442+
TDBoolSwitch(Expr.Match(_innerSP,_innerMatchRange, innerTree, innerTargets,_innerDefaultRange,_innerMatchTy),
1443+
outerTestBool, outerCaseTree, outerDefaultTree,_outerSwitchRange),
1444+
outerTargets, outerDefaultRange, outerMatchTy)->
1445+
1446+
letcostOuterCaseTree=match outerCaseTreewith TDSuccess_->0|_->1
1447+
letcostOuterDefaultTree=match outerDefaultTreewith TDSuccess_->0|_->1
1448+
lettc,ec= CountBoolLogicTree(innerTargets, costOuterCaseTree, costOuterDefaultTree, outerTestBool) innerTree
1449+
// At most one expression, no overall duplication of TSwitch nodes
1450+
if tc<= costOuterCaseTree+ costOuterDefaultTree&& ec<=10then
1451+
letnewExpr=
1452+
Expr.Match(outerSP, outerMatchRange,
1453+
RewriteBoolLogicTree(innerTargets, outerCaseTree, outerDefaultTree, outerTestBool) innerTree,
1454+
outerTargets, outerDefaultRange, outerMatchTy)
1455+
1456+
CombineBoolLogic newExpr
1457+
else
1458+
expr
1459+
|_->
1460+
expr
1461+
1462+
13851463
//-------------------------------------------------------------------------
13861464
// ExpandStructuralBinding
13871465
//
@@ -2814,7 +2892,9 @@ and OptimizeMatch cenv env (spMatch, exprm, dtree, targets, m, ty) =
28142892
// REVIEW: consider collecting, merging and using information flowing through each line of the decision tree to each target
28152893
letdtree',dinfo= OptimizeDecisionTree cenv env m dtree
28162894
lettargets',tinfos= OptimizeDecisionTreeTargets cenv env m targets
2817-
RebuildOptimizedMatch(spMatch, exprm, m, ty, dtree', targets', dinfo, tinfos)
2895+
letnewExpr,newInfo= RebuildOptimizedMatch(spMatch, exprm, m, ty, dtree', targets', dinfo, tinfos)
2896+
letnewExpr2=ifnot(cenv.settings.localOpt())then newExprelse CombineBoolLogic newExpr
2897+
newExpr2, newInfo
28182898

28192899
andCombineMatchInfos dinfo tinfo=
28202900
{ TotalSize= dinfo.TotalSize+ tinfo.TotalSize

‎src/fsharp/TastOps.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ let argsOfAppTy g ty = ty |> stripTyEqns g |> (function TType_app(_, tinst) ->
805805
lettryDestTyparTy g ty= ty|> stripTyEqns g|>(function TType_var v-> Some v|_-> None)
806806
lettryDestFunTy g ty= ty|> stripTyEqns g|>(function TType_fun(tyv, tau)-> Some(tyv, tau)|_-> None)
807807
lettryDestAppTy g ty= ty|> stripTyEqns g|>(function TType_app(tcref,_)-> Some tcref|_-> None)
808+
808809
lettryAnyParTy g ty= ty|> stripTyEqns g|>(function TType_var v-> Some v| TType_measure untwhen isUnitParMeasure g unt-> Some(destUnitParMeasure g unt)|_-> None)
809810
let(|AppTy|_|)g ty= ty|> stripTyEqns g|>(function TType_app(tcref, tinst)-> Some(tcref, tinst)|_-> None)
810811
let(|RefTupleTy|_|)g ty= ty|> stripTyEqns g|>(function TType_tuple(tupInfo, tys)whennot(evalTupInfoIsStruct tupInfo)-> Some tys|_-> None)
@@ -1729,7 +1730,7 @@ let isStructTy g ty =
17291730
| Some tcref->
17301731
lettycon= tcref.Deref
17311732
tycon.IsStructRecordOrUnionTycon|| tycon.IsStructOrEnumTycon
1732-
|_->false
1733+
|_->isStructTupleTy g ty
17331734

17341735
letisRefTy g ty=
17351736
not(isStructOrEnumTyconTy g ty)&&

‎src/fsharp/tast.fs‎

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ type ValFlags(flags:int64) =
261261
(flags&&&~~~0b0011001100000000000L)
262262

263263
/// Represents the kind of a type parameter
264-
[<RequireQualifiedAccess; StructuredFormatDisplay("{DebugText}")>]
264+
[<RequireQualifiedAccess(*; StructuredFormatDisplay("{DebugText}")*)>]
265265
typeTyparKind=
266266

267267
| Type
@@ -273,10 +273,10 @@ type TyparKind =
273273
| TyparKind.Type-> None
274274
| TyparKind.Measure-> Some"Measure"
275275

276-
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
277-
memberx.DebugText= x.ToString()
276+
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
277+
//member x.DebugText = x.ToString()
278278

279-
overridex.ToString()=
279+
overridex.ToString()=
280280
match xwith
281281
| TyparKind.Type->"type"
282282
| TyparKind.Measure->"measure"
@@ -1349,7 +1349,7 @@ and
13491349
overridex.ToString()="TyconAugmentation(...)"
13501350

13511351
and
1352-
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
1352+
[<NoEquality; NoComparison(*; StructuredFormatDisplay("{DebugText}")*)>]
13531353
/// The information for the contents of a type. Also used for a provided namespace.
13541354
TyconRepresentation=
13551355

@@ -1393,10 +1393,10 @@ and
13931393
/// The information for exception definitions should be folded into here.
13941394
| TNoRepr
13951395

1396-
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
1397-
memberx.DebugText= x.ToString()
1396+
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
1397+
//member x.DebugText = x.ToString()
13981398

1399-
overridex.ToString()="TyconRepresentation(...)"
1399+
overridex.ToString()=sprintf"%+A" x
14001400

14011401
and
14021402
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
@@ -1751,7 +1751,7 @@ and
17511751
overridex.ToString()= x.Name
17521752

17531753
and
1754-
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
1754+
[<NoEquality; NoComparison(*; StructuredFormatDisplay("{DebugText}")*)>]
17551755
ExceptionInfo=
17561756
/// Indicates that an exception is an abbreviation for the given exception
17571757
| TExnAbbrevReprofTyconRef
@@ -1765,10 +1765,11 @@ and
17651765
/// Indicates that an exception is abstract, i.e. is in a signature file, and we do not know the representation
17661766
| TExnNone
17671767

1768-
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
1769-
memberx.DebugText= x.ToString()
1768+
// %+A formatting is used, so this is not needed
1769+
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
1770+
//member x.DebugText = x.ToString()
17701771

1771-
overridex.ToString()="ExceptionInfo(...)"
1772+
overridex.ToString()=sprintf"%+A" x
17721773

17731774
and [<Sealed; StructuredFormatDisplay("{DebugText}")>]
17741775
ModuleOrNamespaceType(kind:ModuleOrNamespaceKind,vals:QueueList<Val>,entities:QueueList<Entity>)=
@@ -2340,11 +2341,11 @@ and
23402341
/// Indicates a constraint that a type is .NET unmanaged type
23412342
| IsUnmanagedofrange
23422343

2343-
//Prefer the default formatting of thisunion type
2344+
//%+A formatting is used, so thisis not needed
23442345
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
23452346
//member x.DebugText = x.ToString()
2346-
//
2347-
//override x.ToString() ="TyparConstraint(...)"
2347+
2348+
overridex.ToString()=sprintf"%+A" x
23482349

23492350
/// The specification of a member constraint that must be solved
23502351
and
@@ -2374,7 +2375,7 @@ and
23742375
overridex.ToString()="TTrait("+ x.MemberName+")"
23752376

23762377
and
2377-
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
2378+
[<NoEquality; NoComparison(*; StructuredFormatDisplay("{DebugText}")*)>]
23782379
/// Indicates the solution of a member constraint during inference.
23792380
TraitConstraintSln=
23802381

@@ -2411,10 +2412,11 @@ and
24112412
/// Indicates a trait is solved by a 'fake' instance of an operator, like '+' on integers
24122413
| BuiltInSln
24132414

2414-
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
2415-
memberx.DebugText= x.ToString()
2415+
// %+A formatting is used, so this is not needed
2416+
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
2417+
//member x.DebugText = x.ToString()
24162418

2417-
overridex.ToString()="TraitConstraintSln(...)"
2419+
overridex.ToString()=sprintf"%+A" x
24182420

24192421
/// The partial information used to index the methods of all those in a ModuleOrNamespace.
24202422
and [<RequireQualifiedAccess; StructuredFormatDisplay("{DebugText}")>]
@@ -3996,11 +3998,11 @@ and
39963998
/// Raising a measure to a rational power
39973999
| RationalPowerofMeasure*Rational
39984000

3999-
//Prefer the default formatting of thisunion type
4001+
//%+A formatting is used, so thisis not needed
40004002
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
40014003
//member x.DebugText = x.ToString()
4002-
//
4003-
//override x.ToString() ="Measure(...)"
4004+
4005+
overridex.ToString()=sprintf"%+A" x
40044006

40054007
and
40064008
[<NoEquality; NoComparison; RequireQualifiedAccess; StructuredFormatDisplay("{DebugText}")>]
@@ -4249,7 +4251,7 @@ and
42494251
andAttribs= Attrib list
42504252

42514253
and
4252-
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
4254+
[<NoEquality; NoComparison(*; StructuredFormatDisplay("{DebugText}")*)>]
42534255
AttribKind=
42544256

42554257
/// Indicates an attribute refers to a type defined in an imported .NET assembly
@@ -4258,10 +4260,11 @@ and
42584260
/// Indicates an attribute refers to a type defined in an imported F# assembly
42594261
| FSAttribofValRef
42604262

4261-
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
4262-
memberx.DebugText= x.ToString()
4263+
// %+A formatting is used, so this is not needed
4264+
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
4265+
//member x.DebugText = x.ToString()
42634266

4264-
overridex.ToString()= sprintf"AttribKind(...)"
4267+
overridex.ToString()= sprintf"%+A" x
42654268

42664269
/// Attrib(kind,unnamedArgs,propVal,appliedToAGetterOrSetter,targetsOpt,range)
42674270
and
@@ -4325,10 +4328,11 @@ and [<RequireQualifiedAccess>]
43254328

43264329
/// Decision trees. Pattern matching has been compiled down to
43274330
/// a decision tree by this point. The right-hand-sides (actions) of
4331+
/// a decision tree by this point. The right-hand-sides (actions) of
43284332
/// the decision tree are labelled by integers that are unique for that
43294333
/// particular tree.
43304334
and
4331-
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
4335+
[<NoEquality; NoComparison(*; StructuredFormatDisplay("{DebugText}")*)>]
43324336
DecisionTree=
43334337

43344338
/// TDSwitch(input, cases, default, range)
@@ -4357,10 +4361,11 @@ and
43574361
/// body -- the rest of the decision tree
43584362
| TDBindofBinding*DecisionTree
43594363

4360-
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
4361-
memberx.DebugText= x.ToString()
4364+
// %+A formatting is used, so this is not needed
4365+
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
4366+
//member x.DebugText = x.ToString()
43624367

4363-
overridex.ToString()= sprintf"DecisionTree(...)"
4368+
overridex.ToString()= sprintf"%+A" x
43644369

43654370
/// Represents a test and a subsequent decision tree
43664371
and
@@ -4380,7 +4385,7 @@ and
43804385
overridex.ToString()= sprintf"DecisionTreeCase(...)"
43814386

43824387
and
4383-
[<NoEquality; NoComparison; RequireQualifiedAccess; StructuredFormatDisplay("{DebugText}")>]
4388+
[<NoEquality; NoComparison; RequireQualifiedAccess(*; StructuredFormatDisplay("{DebugText}")*)>]
43844389
DecisionTreeTest=
43854390
/// Test if the input to a decision tree matches the given union case
43864391
| UnionCaseofUnionCaseRef*TypeInst
@@ -4410,10 +4415,11 @@ and
44104415
/// activePatternInfo -- The extracted info for the active pattern.
44114416
| ActivePatternCaseofExpr*TTypes*(ValRef*TypeInst)option*int*ActivePatternInfo
44124417

4413-
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
4414-
memberx.DebugText= x.ToString()
4418+
// %+A formatting is used, so this is not needed
4419+
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
4420+
//member x.DebugText = x.ToString()
44154421

4416-
overridex.ToString()= sprintf"DecisionTreeTest(...)"
4422+
overridex.ToString()= sprintf"%+A" x
44174423

44184424
/// A target of a decision tree. Can be thought of as a little function, though is compiled as a local block.
44194425
and
@@ -4907,7 +4913,7 @@ and
49074913

49084914
/// The contents of a module-or-namespace-fragment definition
49094915
and
4910-
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
4916+
[<NoEquality; NoComparison(*; StructuredFormatDisplay("{DebugText}")*)>]
49114917
ModuleOrNamespaceExpr=
49124918
/// Indicates the module is a module with a signature
49134919
| TMAbstractofModuleOrNamespaceExprWithSig
@@ -4924,10 +4930,11 @@ and
49244930
/// Indicates the module fragment is a 'rec' or 'non-rec' definition of types and modules
49254931
| TMDefRecofisRec:bool*Tyconlist*ModuleOrNamespaceBindinglist*range
49264932

4927-
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
4933+
// %+A formatting is used, so this is not needed
4934+
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
49284935
memberx.DebugText= x.ToString()
49294936

4930-
overridex.ToString()="ModuleOrNamespaceExpr(...)"
4937+
overridex.ToString()=sprintf"%+A" x
49314938

49324939
/// A named module-or-namespace-fragment definition
49334940
and

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp