Skip to content

Commit

Permalink
Merge main to release/net8 (#15312)
Browse files Browse the repository at this point in the history
* add review comment to sb files (#15288)

* add review comment to sb files

* add CODEOWNERS entry for source-build

* Don't show inline hint for arguments with same names as the parameters in DU (#15305)

* Signature of nested type with generic type parameter (#15259)

* Proof of concept

* Add generic parameter names to ModuleOrType.

* Revert ModuleOrType change

* Process ticks in demangledPath of TType_app.

* Only apply new logic when includeStaticParametersInTypeNames is active.

* Use FactForNETCOREAPP

* Fix build

---------

Co-authored-by: Tomas Grosup <tomasgrosup@microsoft.com>

* Improve implied lambda and delegate argument names (#15277)

* Improve implied lambda and delegate argument names

* Fix

* Add tests

* Revert non-preview tests

* Sigh

* Re-revert

* Fix test

* Add testx

---------

Co-authored-by: Oleksandr Didyk <106967057+oleksandr-didyk@users.noreply.github.com>
Co-authored-by: Sudqi <sudqiomar@gmail.com>
Co-authored-by: Florian Verdonck <florian.verdonck@outlook.com>
Co-authored-by: Tomas Grosup <tomasgrosup@microsoft.com>
Co-authored-by: kerams <kerams@users.noreply.github.com>
  • Loading branch information
6 people committed Jun 6, 2023
1 parent b265c68 commit 9b2f911
Show file tree
Hide file tree
Showing 30 changed files with 545 additions and 34 deletions.
44 changes: 33 additions & 11 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8445,7 +8445,19 @@ and TcUnionCaseOrExnCaseOrActivePatternResultItemThen (cenv: cenv) overallTy env
// This is where the constructor expects arguments but is not applied to arguments, hence build a lambda
numArgTys,
(fun () ->
let vs, args = argTys |> List.mapi (fun i ty -> mkCompGenLocal mItem ("arg" + string i) ty) |> List.unzip
let argNamesIfFeatureEnabled =
if g.langVersion.SupportsFeature LanguageFeature.ImprovedImpliedArgumentNames then
argNames
else
[]

let vs, args =
argTys
|> List.mapi (fun i ty ->
let argName = argNamesIfFeatureEnabled |> List.tryItem i |> Option.map (fun x -> x.idText) |> Option.defaultWith (fun () -> "arg" + string i)
mkCompGenLocal mItem argName ty)
|> List.unzip

let constrApp = mkConstrApp mItem args
let lam = mkMultiLambda mItem vs (constrApp, tyOfExpr g constrApp)
lam)
Expand Down Expand Up @@ -9535,7 +9547,13 @@ and TcMethodApplication_CheckArguments
let denv = env.DisplayEnv
match curriedCallerArgsOpt with
| None ->
let curriedArgTys, returnTy =
let curriedArgTys, curriedArgNamesIfFeatureEnabled, returnTy =
let paramNamesIfFeatureEnabled (g: TcGlobals) (meth: MethInfo) =
if g.langVersion.SupportsFeature LanguageFeature.ImprovedImpliedArgumentNames then
meth.GetParamNames()
else
[]

match candidates with
// "single named item" rule. This is where we have a single accessible method
// member x.M(arg1, ..., argN)
Expand All @@ -9547,19 +9565,23 @@ and TcMethodApplication_CheckArguments
// to their default values (for optionals) and be part of the return tuple (for out args).
| [calledMeth] ->
let curriedArgTys, returnTy = UnifyMatchingSimpleArgumentTypes cenv env exprTy.Commit calledMeth mMethExpr mItem
curriedArgTys, MustEqual returnTy
curriedArgTys, paramNamesIfFeatureEnabled g calledMeth, MustEqual returnTy
| _ ->
let domainTy, returnTy = UnifyFunctionType None cenv denv mMethExpr exprTy.Commit
let argTys = if isUnitTy g domainTy then [] else tryDestRefTupleTy g domainTy
// Only apply this rule if a candidate method exists with this number of arguments
let argTys =
if candidates |> List.exists (CalledMethHasSingleArgumentGroupOfThisLength argTys.Length) then
argTys
else
[domainTy]
[argTys], MustEqual returnTy

let lambdaVarsAndExprs = curriedArgTys |> List.mapiSquared (fun i j ty -> mkCompGenLocal mMethExpr ("arg"+string i+string j) ty)
let argTys, argNames =
match candidates |> List.tryFind (CalledMethHasSingleArgumentGroupOfThisLength argTys.Length) with
| Some meth -> argTys, paramNamesIfFeatureEnabled g meth
| None -> [domainTy], [[None]]
[argTys], argNames, MustEqual returnTy

let lambdaVarsAndExprs =
curriedArgTys
|> List.mapiSquared (fun i j ty ->
let argName = curriedArgNamesIfFeatureEnabled |> List.tryItem i |> Option.bind (List.tryItem j) |> Option.flatten |> Option.defaultWith (fun () -> "arg" + string i + string j)
mkCompGenLocal mMethExpr argName ty)

let unnamedCurriedCallerArgs = lambdaVarsAndExprs |> List.mapSquared (fun (_, e) -> CallerArg(tyOfExpr g e, e.Range, false, e))
let namedCurriedCallerArgs = lambdaVarsAndExprs |> List.map (fun _ -> [])
let lambdaVars = List.mapSquared fst lambdaVarsAndExprs
Expand Down
17 changes: 16 additions & 1 deletion src/Compiler/Checking/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,23 @@ let BuildNewDelegateExpr (eventInfoOpt: EventInfo option, g, amap, delegateTy, d
if List.exists (isByrefTy g) delArgTys then
error(Error(FSComp.SR.tcFunctionRequiresExplicitLambda(delArgTys.Length), m))

let delFuncArgNamesIfFeatureEnabled =
match delFuncExpr with
| Expr.Val (valRef = vref) when g.langVersion.SupportsFeature LanguageFeature.ImprovedImpliedArgumentNames ->
match vref.ValReprInfo with
| Some repr when repr.ArgNames.Length = delArgTys.Length -> Some repr.ArgNames
| _ -> None
| _ -> None

let delArgVals =
delArgTys |> List.mapi (fun i argTy -> fst (mkCompGenLocal m ("delegateArg" + string i) argTy))
delArgTys
|> List.mapi (fun i argTy ->
let argName =
match delFuncArgNamesIfFeatureEnabled with
| Some argNames -> argNames[i]
| None -> "delegateArg" + string i

fst (mkCompGenLocal m argName argTy))

let expr =
let args =
Expand Down
65 changes: 55 additions & 10 deletions src/Compiler/Checking/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,19 @@ module internal PrintUtilities =
| GenericParameterStyle.Prefix -> true
| GenericParameterStyle.Suffix -> false

let layoutTyconRefImpl isAttribute (denv: DisplayEnv) (tcref: TyconRef) =
/// <summary>
/// Creates a layout for TyconRef.
/// </summary>
/// <param name="isAttribute"></param>
/// <param name="denv"></param>
/// <param name="tcref"></param>
/// <param name="demangledPath">
/// Used in the case the TyconRef is a nested type from another assembly which has generic type parameters in the path.
/// For example: System.Collections.Immutable.ImmutableArray&gt;'T&lt;.Builder
/// Lead to access path: System.Collections.Immutable.ImmutableArray`1
/// ImmutableArray`1 will be transformed to ImmutableArray&gt;'t&lt;
/// </param>
let layoutTyconRefImpl isAttribute (denv: DisplayEnv) (tcref: TyconRef) (demangledPath: string list option) =

let prefix = usePrefix denv tcref
let isArray = not prefix && isArrayTyconRef denv.g tcref
Expand Down Expand Up @@ -201,21 +213,22 @@ module internal PrintUtilities =
if denv.shortTypeNames then
tyconTextL
else
let path = tcref.CompilationPath.DemangledPath
let path =
if denv.includeStaticParametersInTypeNames then
path
Option.defaultValue tcref.CompilationPath.DemangledPath demangledPath
else
path |> List.map (fun s ->
tcref.CompilationPath.DemangledPath
|> List.map (fun s ->
let i = s.IndexOf(',')
if i <> -1 then s.Substring(0, i)+"<...>" // apparently has static params, shorten
else s)

let pathText = trimPathByDisplayEnv denv path
if pathText = "" then tyconTextL else leftL (tagUnknownEntity pathText) ^^ tyconTextL

let layoutBuiltinAttribute (denv: DisplayEnv) (attrib: BuiltinAttribInfo) =
let tcref = attrib.TyconRef
squareAngleL (layoutTyconRefImpl true denv tcref)
squareAngleL (layoutTyconRefImpl true denv tcref None)

/// layout the xml docs immediately before another block
let layoutXmlDoc (denv: DisplayEnv) alwaysAddEmptyLine (xml: XmlDoc) restL =
Expand Down Expand Up @@ -499,7 +512,7 @@ module PrintTypes =
layoutAccessibilityCore denv accessibility ++ itemL

/// Layout a reference to a type
let layoutTyconRef denv tcref = layoutTyconRefImpl false denv tcref
let layoutTyconRef denv tcref = layoutTyconRefImpl false denv tcref None

/// Layout the flags of a member
let layoutMemberFlags (memFlags: SynMemberFlags) =
Expand Down Expand Up @@ -571,7 +584,7 @@ module PrintTypes =

/// Layout an attribute 'Type(arg1, ..., argN)'
and layoutAttrib denv (Attrib(tcref, _, args, props, _, _, _)) =
let tcrefL = layoutTyconRefImpl true denv tcref
let tcrefL = layoutTyconRefImpl true denv tcref None
let argsL = bracketL (layoutAttribArgs denv args props)
if List.isEmpty args && List.isEmpty props then
tcrefL
Expand Down Expand Up @@ -900,7 +913,39 @@ module PrintTypes =
| TType_ucase (UnionCaseRef(tc, _), args)
| TType_app (tc, args, _) ->
let prefix = usePrefix denv tc
layoutTypeAppWithInfoAndPrec denv env (layoutTyconRef denv tc) prec prefix args
let demangledCompilationPathOpt, args =
if not denv.includeStaticParametersInTypeNames then
None, args
else
let regex = System.Text.RegularExpressions.Regex(@"\`\d+")
let path, skip =
(0, tc.CompilationPath.DemangledPath)
||> List.mapFold (fun skip path ->
// Verify the path does not contain a generic parameter count.
// For example Foo`3 indicates that there are three parameters in args that belong to this path.
let m = regex.Match(path)
if not m.Success then
path, skip
else
let take = m.Value.Replace("`", "") |> int
let genericArgs =
List.skip skip args
|> List.take take
|> List.map (layoutTypeWithInfoAndPrec denv env prec >> showL)
|> String.concat ","
|> sprintf "<%s>"
String.Concat(path.Substring(0, m.Index), genericArgs), (skip + take)
)

Some path, List.skip skip args

layoutTypeAppWithInfoAndPrec
denv
env
(layoutTyconRefImpl false denv tc demangledCompilationPathOpt)
prec
prefix
args

// Layout a tuple type
| TType_anon (anonInfo, tys) ->
Expand Down Expand Up @@ -1621,7 +1666,7 @@ module TastDefinitionPrinting =
let layoutExtensionMember denv infoReader (vref: ValRef) =
let (@@*) = if denv.printVerboseSignatures then (@@----) else (@@--)
let tycon = vref.MemberApparentEntity.Deref
let nameL = layoutTyconRefImpl false denv vref.MemberApparentEntity
let nameL = layoutTyconRefImpl false denv vref.MemberApparentEntity None
let nameL = layoutAccessibility denv tycon.Accessibility nameL // "type-accessibility"
let tps =
match PartitionValTyparsForApparentEnclosingType denv.g vref.Deref with
Expand Down Expand Up @@ -2615,7 +2660,7 @@ let stringOfFSAttrib denv x = x |> PrintTypes.layoutAttrib denv |> squareAngleL

let stringOfILAttrib denv x = x |> PrintTypes.layoutILAttrib denv |> squareAngleL |> showL

let fqnOfEntityRef g x = x |> layoutTyconRefImpl false (DisplayEnv.Empty g) |> showL
let fqnOfEntityRef g x = layoutTyconRefImpl false (DisplayEnv.Empty g) x None |> showL

let layoutImpliedSignatureOfModuleOrNamespace showHeader denv infoReader ad m contents =
InferredSigPrinting.layoutImpliedSignatureOfModuleOrNamespace showHeader denv infoReader ad m contents
Expand Down
15 changes: 15 additions & 0 deletions src/Compiler/Checking/infos.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,21 @@ type MethInfo =
member x.GetFSharpReturnType(amap, m, minst) =
x.GetCompiledReturnType(amap, m, minst) |> GetFSharpViewOfReturnType amap.g

member x.GetParamNames() =
match x with
| FSMeth (g, _, vref, _) ->
ParamNameAndType.FromMember x.IsCSharpStyleExtensionMember g vref |> List.mapSquared (fun (ParamNameAndType (name, _)) -> name |> Option.map (fun x -> x.idText))
| ILMeth (ilMethInfo = ilminfo) ->
// A single group of tupled arguments
[ ilminfo.ParamMetadata |> List.map (fun x -> x.Name) ]
#if !NO_TYPEPROVIDERS
| ProvidedMeth (_, mi, _, m) ->
// A single group of tupled arguments
[ [ for p in mi.PApplyArray((fun mi -> mi.GetParameters()), "GetParameters", m) do
yield p.PUntaint((fun p -> Some p.Name), m) ] ]
#endif
| _ -> []

/// Get the parameter types of a method info
member x.GetParamTypes(amap, m, minst) =
match x with
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Checking/infos.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ type MethInfo =
/// Get the ParamData objects for the parameters of a MethInfo
member GetParamDatas: amap: ImportMap * m: range * minst: TType list -> ParamData list list

/// Get the parameter names of a MethInfo
member GetParamNames: unit -> string option list list

/// Get the parameter types of a method info
member GetParamTypes: amap: ImportMap * m: range * minst: TType list -> TType list list

Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ featureNonInlineLiteralsAsPrintfFormat,"String values marked as literals and IL
featureNestedCopyAndUpdate,"Nested record field copy-and-update"
featureExtendedStringInterpolation,"Extended string interpolation similar to C# raw string literals."
featureWarningWhenMultipleRecdTypeChoice,"Raises warnings when multiple record type matches were found during name resolution because of overlapping field names."
featureImprovedImpliedArgumentNames,"Improved implied argument names"
3353,fsiInvalidDirective,"Invalid directive '#%s %s'"
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type LanguageFeature =
| NestedCopyAndUpdate
| ExtendedStringInterpolation
| WarningWhenMultipleRecdTypeChoice
| ImprovedImpliedArgumentNames

/// LanguageVersion management
type LanguageVersion(versionText) =
Expand Down Expand Up @@ -159,6 +160,7 @@ type LanguageVersion(versionText) =
LanguageFeature.NestedCopyAndUpdate, previewVersion
LanguageFeature.ExtendedStringInterpolation, previewVersion
LanguageFeature.WarningWhenMultipleRecdTypeChoice, previewVersion
LanguageFeature.ImprovedImpliedArgumentNames, previewVersion

]

Expand Down Expand Up @@ -282,6 +284,7 @@ type LanguageVersion(versionText) =
| LanguageFeature.NestedCopyAndUpdate -> FSComp.SR.featureNestedCopyAndUpdate ()
| LanguageFeature.ExtendedStringInterpolation -> FSComp.SR.featureExtendedStringInterpolation ()
| LanguageFeature.WarningWhenMultipleRecdTypeChoice -> FSComp.SR.featureWarningWhenMultipleRecdTypeChoice ()
| LanguageFeature.ImprovedImpliedArgumentNames -> FSComp.SR.featureImprovedImpliedArgumentNames ()

/// Get a version string associated with the given feature.
static member GetFeatureVersionString feature =
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Facilities/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type LanguageFeature =
| NestedCopyAndUpdate
| ExtendedStringInterpolation
| WarningWhenMultipleRecdTypeChoice
| ImprovedImpliedArgumentNames

/// LanguageVersion management
type LanguageVersion =
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/TypedTree/TypedTreeOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3117,7 +3117,8 @@ type DisplayEnv =
suppressInlineKeyword = false
showDocumentation = true
shrinkOverloads = false
escapeKeywordNames = true }
escapeKeywordNames = true
includeStaticParametersInTypeNames = true }
denv.SetOpenPaths
[ FSharpLib.RootPath
FSharpLib.CorePath
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@
<target state="translated">implicitní yield</target>
<note />
</trans-unit>
<trans-unit id="featureImprovedImpliedArgumentNames">
<source>Improved implied argument names</source>
<target state="new">Improved implied argument names</target>
<note />
</trans-unit>
<trans-unit id="featureIndexerNotationWithoutDot">
<source>expr[idx] notation for indexing and slicing</source>
<target state="translated">Notace expr[idx] pro indexování a vytváření řezů</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@
<target state="translated">implizite yield-Anweisung</target>
<note />
</trans-unit>
<trans-unit id="featureImprovedImpliedArgumentNames">
<source>Improved implied argument names</source>
<target state="new">Improved implied argument names</target>
<note />
</trans-unit>
<trans-unit id="featureIndexerNotationWithoutDot">
<source>expr[idx] notation for indexing and slicing</source>
<target state="translated">expr[idx]-Notation zum Indizieren und Aufteilen</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@
<target state="translated">elemento yield implícito</target>
<note />
</trans-unit>
<trans-unit id="featureImprovedImpliedArgumentNames">
<source>Improved implied argument names</source>
<target state="new">Improved implied argument names</target>
<note />
</trans-unit>
<trans-unit id="featureIndexerNotationWithoutDot">
<source>expr[idx] notation for indexing and slicing</source>
<target state="translated">Notación para indexación y segmentación expr[idx]</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@
<target state="translated">yield implicite</target>
<note />
</trans-unit>
<trans-unit id="featureImprovedImpliedArgumentNames">
<source>Improved implied argument names</source>
<target state="new">Improved implied argument names</target>
<note />
</trans-unit>
<trans-unit id="featureIndexerNotationWithoutDot">
<source>expr[idx] notation for indexing and slicing</source>
<target state="translated">Notation expr[idx] pour l’indexation et le découpage</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@
<target state="translated">istruzione yield implicita</target>
<note />
</trans-unit>
<trans-unit id="featureImprovedImpliedArgumentNames">
<source>Improved implied argument names</source>
<target state="new">Improved implied argument names</target>
<note />
</trans-unit>
<trans-unit id="featureIndexerNotationWithoutDot">
<source>expr[idx] notation for indexing and slicing</source>
<target state="translated">Notazione expr[idx] per l'indicizzazione e il sezionamento</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@
<target state="translated">暗黙的な yield</target>
<note />
</trans-unit>
<trans-unit id="featureImprovedImpliedArgumentNames">
<source>Improved implied argument names</source>
<target state="new">Improved implied argument names</target>
<note />
</trans-unit>
<trans-unit id="featureIndexerNotationWithoutDot">
<source>expr[idx] notation for indexing and slicing</source>
<target state="translated">インデックス作成とスライス用の expr[idx] 表記</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@
<target state="translated">암시적 yield</target>
<note />
</trans-unit>
<trans-unit id="featureImprovedImpliedArgumentNames">
<source>Improved implied argument names</source>
<target state="new">Improved implied argument names</target>
<note />
</trans-unit>
<trans-unit id="featureIndexerNotationWithoutDot">
<source>expr[idx] notation for indexing and slicing</source>
<target state="translated">인덱싱 및 슬라이싱을 위한 expr[idx] 표기법</target>
Expand Down

0 comments on commit 9b2f911

Please sign in to comment.