Skip to content

Commit 056e45f

Browse files
authored
Merge pull request #15662 from dotnet/merges/main-to-release/dev17.8
Merge main to release/dev17.8
2 parents 0126135 + b391498 commit 056e45f

31 files changed

+626
-108
lines changed

eng/Version.Details.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
</Dependency>
3030
</ProductDependencies>
3131
<ToolsetDependencies>
32-
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="8.0.0-beta.23369.2">
32+
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="8.0.0-beta.23370.6">
3333
<Uri>https://github.com/dotnet/arcade</Uri>
34-
<Sha>9fba71ca242ef84c4b7696c380cc00efe734adb3</Sha>
34+
<Sha>a2d7c72df5b2e36b0f69bbe12ad4d7c52793c745</Sha>
3535
<SourceBuild RepoName="arcade" ManagedOnly="true" />
3636
</Dependency>
3737
<Dependency Name="Microsoft.SourceLink.GitHub" Version="8.0.0-beta.23361.2" CoherentParentDependency="Microsoft.DotNet.Arcade.Sdk">

eng/common/sdl/configure-sdl-tool.ps1

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ try {
9393
}
9494
'binskim' {
9595
if ($targetDirectory) {
96-
$tool.Args += "`"Target < $TargetDirectory\**`""
96+
# Binskim crashes due to specific PDBs. GitHub issue: https://github.com/microsoft/binskim/issues/924.
97+
# We are excluding all `_.pdb` files from the scan.
98+
$tool.Args += "`"Target < $TargetDirectory\**;-:file|$TargetDirectory\**\_.pdb`""
9799
}
98100
$tool.Args += $BinskimAdditionalRunConfigParams
99101
}

global.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"perl": "5.32.1.1"
1919
},
2020
"msbuild-sdks": {
21-
"Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.23369.2",
21+
"Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.23370.6",
2222
"Microsoft.DotNet.Helix.Sdk": "8.0.0-beta.23255.2"
2323
}
2424
}

src/Compiler/Checking/ConstraintSolver.fs

+3-34
Original file line numberDiff line numberDiff line change
@@ -397,53 +397,22 @@ let rec isNativeIntegerTy g ty =
397397
typeEquivAux EraseMeasures g g.unativeint_ty ty ||
398398
(isEnumTy g ty && isNativeIntegerTy g (underlyingTypeOfEnumTy g ty))
399399

400-
let isSignedIntegerTy g ty =
401-
typeEquivAux EraseMeasures g g.sbyte_ty ty ||
402-
typeEquivAux EraseMeasures g g.int16_ty ty ||
403-
typeEquivAux EraseMeasures g g.int32_ty ty ||
404-
typeEquivAux EraseMeasures g g.nativeint_ty ty ||
405-
typeEquivAux EraseMeasures g g.int64_ty ty
406-
407-
let isUnsignedIntegerTy g ty =
408-
typeEquivAux EraseMeasures g g.byte_ty ty ||
409-
typeEquivAux EraseMeasures g g.uint16_ty ty ||
410-
typeEquivAux EraseMeasures g g.uint32_ty ty ||
411-
typeEquivAux EraseMeasures g g.unativeint_ty ty ||
412-
typeEquivAux EraseMeasures g g.uint64_ty ty
413-
414400
let rec IsIntegerOrIntegerEnumTy g ty =
415401
isSignedIntegerTy g ty ||
416402
isUnsignedIntegerTy g ty ||
417403
(isEnumTy g ty && IsIntegerOrIntegerEnumTy g (underlyingTypeOfEnumTy g ty))
418404

419-
let isIntegerTy g ty =
420-
isSignedIntegerTy g ty ||
421-
isUnsignedIntegerTy g ty
422-
423405
let isStringTy g ty = typeEquiv g g.string_ty ty
424406

425407
let isCharTy g ty = typeEquiv g g.char_ty ty
426408

427409
let isBoolTy g ty = typeEquiv g g.bool_ty ty
428410

429-
/// float or float32 or float<_> or float32<_>
430-
let isFpTy g ty =
431-
typeEquivAux EraseMeasures g g.float_ty ty ||
432-
typeEquivAux EraseMeasures g g.float32_ty ty
433-
434-
/// decimal or decimal<_>
435-
let isDecimalTy g ty =
436-
typeEquivAux EraseMeasures g g.decimal_ty ty
437-
438411
let IsNonDecimalNumericOrIntegralEnumType g ty = IsIntegerOrIntegerEnumTy g ty || isFpTy g ty
439412

440413
let IsNumericOrIntegralEnumType g ty = IsNonDecimalNumericOrIntegralEnumType g ty || isDecimalTy g ty
441414

442-
let IsNonDecimalNumericType g ty = isIntegerTy g ty || isFpTy g ty
443-
444-
let IsNumericType g ty = IsNonDecimalNumericType g ty || isDecimalTy g ty
445-
446-
let IsRelationalType g ty = IsNumericType g ty || isStringTy g ty || isCharTy g ty || isBoolTy g ty
415+
let IsRelationalType g ty = isNumericType g ty || isStringTy g ty || isCharTy g ty || isBoolTy g ty
447416

448417
let IsCharOrStringType g ty = isCharTy g ty || isStringTy g ty
449418

@@ -1517,12 +1486,12 @@ and SolveMemberConstraint (csenv: ConstraintSolverEnv) ignoreUnresolvedOverload
15171486
// We pretend for uniformity that the numeric types have a static property called Zero and One
15181487
// As with constants, only zero is polymorphic in its units
15191488
| [], [ty], false, "get_Zero", []
1520-
when IsNumericType g ty || isCharTy g ty ->
1489+
when isNumericType g ty || isCharTy g ty ->
15211490
do! SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace retTy ty
15221491
return TTraitBuiltIn
15231492

15241493
| [], [ty], false, "get_One", []
1525-
when IsNumericType g ty || isCharTy g ty ->
1494+
when isNumericType g ty || isCharTy g ty ->
15261495
do! SolveDimensionlessNumericType csenv ndeep m2 trace ty
15271496
do! SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace retTy ty
15281497
return TTraitBuiltIn

src/Compiler/FSComp.txt

+1
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,7 @@ typeInfoFromFirst,"from %s"
962962
typeInfoFromNext,"also from %s"
963963
typeInfoGeneratedProperty,"generated property"
964964
typeInfoGeneratedType,"generated type"
965+
suggestedName,"(Suggested name)"
965966
1089,recursiveClassHierarchy,"Recursive class hierarchy in type '%s'"
966967
1090,InvalidRecursiveReferenceToAbstractSlot,"Invalid recursive reference to an abstract slot"
967968
1091,eventHasNonStandardType,"The event '%s' has a non-standard type. If this event is declared in another CLI language, you may need to access this event using the explicit %s and %s methods for the event. If this event is declared in F#, make the type of the event an instantiation of either 'IDelegateEvent<_>' or 'IEvent<_,_>'."

src/Compiler/Service/FSharpCheckerResults.fs

+127-8
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ open FSharp.Compiler.Text.Range
4949
open FSharp.Compiler.TypedTree
5050
open FSharp.Compiler.TypedTreeBasics
5151
open FSharp.Compiler.TypedTreeOps
52-
open FSharp.Compiler.AbstractIL
53-
open System.Reflection.PortableExecutable
54-
open FSharp.Compiler.CreateILModule
55-
open FSharp.Compiler.IlxGen
56-
open FSharp.Compiler.BuildGraph
5752

5853
open Internal.Utilities
5954
open Internal.Utilities.Collections
@@ -934,6 +929,85 @@ type internal TypeCheckInfo
934929

935930
let DefaultCompletionItem item = CompletionItem ValueNone ValueNone item
936931

932+
let CompletionItemSuggestedName displayName =
933+
{
934+
ItemWithInst = ItemWithNoInst(Item.NewDef(Ident(displayName, range0)))
935+
MinorPriority = 0
936+
Type = None
937+
Kind = CompletionItemKind.SuggestedName
938+
IsOwnMember = false
939+
Unresolved = None
940+
}
941+
942+
/// Checks whether the suggested name is unused.
943+
/// In the future we could use an increasing numeric suffix for conflict resolution
944+
let CreateCompletionItemForSuggestedPatternName (pos: pos) name =
945+
if String.IsNullOrWhiteSpace name then
946+
None
947+
else
948+
let name = String.lowerCaseFirstChar name
949+
950+
let unused =
951+
sResolutions.CapturedNameResolutions
952+
|> ResizeArray.forall (fun r ->
953+
match r.Item with
954+
| Item.Value vref when r.Pos.Line = pos.Line -> vref.DisplayName <> name
955+
| _ -> true)
956+
957+
if unused then
958+
Some(CompletionItemSuggestedName name)
959+
else
960+
None
961+
962+
/// Suggest name based on type
963+
let SuggestNameBasedOnType g pos ty =
964+
if isNumericType g ty then
965+
CreateCompletionItemForSuggestedPatternName pos "num"
966+
else
967+
match tryTcrefOfAppTy g ty with
968+
| ValueSome tcref when not (tyconRefEq g g.system_Object_tcref tcref) ->
969+
CreateCompletionItemForSuggestedPatternName pos tcref.DisplayName
970+
| _ -> None
971+
972+
/// Suggest names based on field name and type, add them to the list
973+
let SuggestNameForUnionCaseFieldPattern g caseIdPos fieldPatternPos (uci: UnionCaseInfo) indexOrName completions =
974+
let field =
975+
match indexOrName with
976+
| Choice1Of2 index ->
977+
// Index is None when parentheses were not used, i.e. "| Some v ->" - suggest a name only when the case has a single field
978+
match uci.UnionCase.RecdFieldsArray, index with
979+
| [| field |], None -> Some field
980+
| [| _ |], Some _
981+
| _, None -> None
982+
| arr, Some index -> arr |> Array.tryItem index
983+
| Choice2Of2 name -> uci.UnionCase.RecdFieldsArray |> Array.tryFind (fun x -> x.DisplayName = name)
984+
985+
field
986+
|> Option.map (fun field ->
987+
let ty =
988+
// If the field type is generic, suggest a name based on the solution
989+
if isTyparTy g field.FormalType then
990+
sResolutions.CapturedNameResolutions
991+
|> ResizeArray.tryPick (fun r ->
992+
match r.Item with
993+
| Item.Value vref when r.Pos = fieldPatternPos -> Some(stripTyparEqns vref.Type)
994+
| _ -> None)
995+
|> Option.defaultValue field.FormalType
996+
else
997+
field.FormalType
998+
999+
let fieldName =
1000+
// If the field has not been given an explicit name, do not suggest the generated one
1001+
if field.rfield_name_generated then
1002+
""
1003+
else
1004+
field.DisplayName
1005+
1006+
completions
1007+
|> List.prependIfSome (SuggestNameBasedOnType g caseIdPos ty)
1008+
|> List.prependIfSome (CreateCompletionItemForSuggestedPatternName caseIdPos fieldName))
1009+
|> Option.defaultValue completions
1010+
9371011
let getItem (x: ItemWithInst) = x.Item
9381012

9391013
let GetDeclaredItems
@@ -1182,10 +1256,10 @@ type internal TypeCheckInfo
11821256
| atStart when atStart = 0 -> 0
11831257
| otherwise -> otherwise - 1
11841258

1259+
let pos = mkPos line colAtEndOfNamesAndResidue
1260+
11851261
// Look for a "special" completion context
11861262
let completionContext =
1187-
let pos = mkPos line colAtEndOfNamesAndResidue
1188-
11891263
// If the completion context we have computed higher up the stack is for the same position,
11901264
// reuse it, otherwise recompute
11911265
match completionContextAtPos with
@@ -1400,7 +1474,7 @@ type internal TypeCheckInfo
14001474
m)
14011475

14021476
// Completion at '(x: ...)"
1403-
| Some CompletionContext.PatternType
1477+
| Some CompletionContext.Type
14041478
// Completion at '| Case1 of ...'
14051479
| Some CompletionContext.UnionCaseFieldsDeclaration
14061480
// Completion at 'type Long = int6...' or 'type SomeUnion = Abc...'
@@ -1434,6 +1508,51 @@ type internal TypeCheckInfo
14341508
denv,
14351509
m)
14361510

1511+
| Some (CompletionContext.Pattern patternContext) ->
1512+
let declaredItems =
1513+
GetDeclaredItems(
1514+
parseResultsOpt,
1515+
lineStr,
1516+
origLongIdentOpt,
1517+
colAtEndOfNamesAndResidue,
1518+
residueOpt,
1519+
lastDotPos,
1520+
line,
1521+
loc,
1522+
filterCtors,
1523+
resolveOverloads,
1524+
false,
1525+
getAllSymbols
1526+
)
1527+
|> Option.map (fun (items, denv, range) ->
1528+
let filtered =
1529+
items
1530+
|> List.filter (fun item ->
1531+
match item.Item with
1532+
| Item.Value v -> v.LiteralValue.IsSome
1533+
| _ -> true)
1534+
1535+
filtered, denv, range)
1536+
1537+
let indexOrName, caseIdRange =
1538+
match patternContext with
1539+
| PatternContext.PositionalUnionCaseField (index, m) -> Choice1Of2 index, m
1540+
| PatternContext.NamedUnionCaseField (name, m) -> Choice2Of2 name, m
1541+
| PatternContext.Other -> Choice1Of2 None, range0
1542+
1543+
// No special handling for PatternContext.Other other than filtering out non-literal values
1544+
if equals caseIdRange range0 then
1545+
declaredItems
1546+
else
1547+
GetCapturedNameResolutions caseIdRange.End ResolveOverloads.Yes
1548+
|> ResizeArray.tryPick (fun r ->
1549+
match r.Item with
1550+
| Item.UnionCase (uci, _) ->
1551+
let list = declaredItems |> Option.map p13 |> Option.defaultValue []
1552+
Some(SuggestNameForUnionCaseFieldPattern g caseIdRange.End pos uci indexOrName list, r.DisplayEnv, r.Range)
1553+
| _ -> None)
1554+
|> Option.orElse declaredItems
1555+
14371556
// Other completions
14381557
| cc ->
14391558
match residueOpt |> Option.bind Seq.tryHead with

src/Compiler/Service/ServiceDeclarationLists.fs

+6-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type ToolTipText =
6666

6767
[<RequireQualifiedAccess>]
6868
type CompletionItemKind =
69+
| SuggestedName
6970
| Field
7071
| Property
7172
| Method of isExtension : bool
@@ -1035,10 +1036,12 @@ type DeclarationListItem(textInDeclList: string, textInCode: string, fullName: s
10351036
member _.NameInCode = textInCode
10361037

10371038
member _.Description =
1038-
match info with
1039-
| Choice1Of2 (items: CompletionItem list, infoReader, ad, m, denv) ->
1039+
match kind, info with
1040+
| CompletionItemKind.SuggestedName, _ ->
1041+
ToolTipText [ ToolTipElement.Single ([| tagText (FSComp.SR.suggestedName()) |], FSharpXmlDoc.None) ]
1042+
| _, Choice1Of2 (items: CompletionItem list, infoReader, ad, m, denv) ->
10401043
ToolTipText(items |> List.map (fun x -> FormatStructuredDescriptionOfItem true infoReader ad m denv x.ItemWithInst None None))
1041-
| Choice2Of2 result ->
1044+
| _, Choice2Of2 result ->
10421045
result
10431046

10441047
member _.Glyph = glyph

src/Compiler/Service/ServiceDeclarationLists.fsi

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type public ToolTipText =
6060

6161
[<RequireQualifiedAccess>]
6262
type public CompletionItemKind =
63+
| SuggestedName
6364
| Field
6465
| Property
6566
| Method of isExtension: bool

0 commit comments

Comments
 (0)