Skip to content

Commit

Permalink
Don't lose attributes of method parameters (#12)
Browse files Browse the repository at this point in the history
Temporary fix, remove when upstream dotnet#13786 is fixed.
  • Loading branch information
alfonsogarciacaro authored and ncave committed Nov 15, 2024
1 parent 43c1bfd commit 3724334
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ let tryGetArgAttribsForCustomOperator ceenv (nm: Ident) =
_joinConditionWord,
methInfo) ->
match methInfo.GetParamAttribs(ceenv.cenv.amap, ceenv.mWhole) with
| [ curriedArgInfo ] -> Some curriedArgInfo // one for the actual argument group
| [ curriedArgInfo ] -> Some (List.map fst curriedArgInfo) // one for the actual argument group
| _ -> None)
|> Some
| _ -> None
Expand Down
7 changes: 4 additions & 3 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4188,7 +4188,7 @@ and TcPseudoMemberSpec cenv newOk env synTypes tpenv synMemberSig m =
let logicalCompiledName = ComputeLogicalName id memberFlags
for argInfos in curriedArgInfos do
for argInfo in argInfos do
let info = CrackParamAttribsInfo g argInfo
let info, _ = CrackParamAttribsInfo g argInfo
let (ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)) = info
if isParamArrayArg || isInArg || isOutArg || optArgInfo.IsOptional || callerInfo <> CallerInfo.NoCallerInfo || reflArgInfo <> ReflectedArgInfo.None then
if g.langVersion.SupportsFeature(LanguageFeature.InterfacesWithAbstractStaticMembers) then
Expand Down Expand Up @@ -9779,6 +9779,7 @@ and GenerateMatchingSimpleArgumentTypes (cenv: cenv) (calledMeth: MethInfo) mIte
let g = cenv.g
let curriedMethodArgAttribs = calledMeth.GetParamAttribs(cenv.amap, mItem)
curriedMethodArgAttribs
|> List.map (List.map fst)
|> List.map (List.filter isSimpleFormalArg >> NewInferenceTypes g)

and UnifyMatchingSimpleArgumentTypes (cenv: cenv) (env: TcEnv) exprTy (calledMeth: MethInfo) mMethExpr mItem =
Expand Down Expand Up @@ -9832,7 +9833,7 @@ and TcMethodApplication_SplitSynArguments
let singleMethodCurriedArgs =
match candidates with
| [calledMeth] when List.forall isNil namedCurriedCallerArgs ->
let curriedCalledArgs = calledMeth.GetParamAttribs(cenv.amap, mItem)
let curriedCalledArgs = calledMeth.GetParamAttribs(cenv.amap, mItem) |> List.map (List.map fst)
match curriedCalledArgs with
| [arg :: _] when isSimpleFormalArg arg -> Some(curriedCalledArgs)
| _ -> None
Expand Down Expand Up @@ -10077,7 +10078,7 @@ and TcAdhocChecksOnLibraryMethods (cenv: cenv) (env: TcEnv) isInstance (finalCal
if HasHeadType g g.tcref_System_Collections_Generic_Dictionary finalCalledMethInfo.ApparentEnclosingType &&
finalCalledMethInfo.IsConstructor &&
not (finalCalledMethInfo.GetParamDatas(cenv.amap, mItem, finalCalledMeth.CalledTyArgs)
|> List.existsSquared (fun (ParamData(_, _, _, _, _, _, _, ty)) ->
|> List.existsSquared (fun (ParamData(_, _, _, _, _, _, _, ty), _) ->
HasHeadType g g.tcref_System_Collections_Generic_IEqualityComparer ty)) then

match argsOfAppTy g finalCalledMethInfo.ApparentEnclosingType with
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ type CalledMethArgSet<'T> =
let MakeCalledArgs amap m (minfo: MethInfo) minst =
// Mark up the arguments with their position, so we can sort them back into order later
let paramDatas = minfo.GetParamDatas(amap, m, minst)
paramDatas |> List.mapiSquared (fun i j (ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfoFlags, nmOpt, reflArgInfo, calledArgTy)) ->
paramDatas |> List.mapiSquared (fun i j (ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfoFlags, nmOpt, reflArgInfo, calledArgTy), _) ->
{ Position=(i,j)
IsParamArray=isParamArrayArg
OptArgInfo=optArgInfo
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Checking/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ module InfoMemberPrinting =
let layout = layoutXmlDocOfMethInfo denv infoReader minfo layout

let paramsL =
let paramDatas = minfo.GetParamDatas(amap, m, minst)
let paramDatas = minfo.GetParamDatas(amap, m, minst) |> List.map (List.map fst)
if List.forall isNil paramDatas then
WordL.structUnit
else
Expand Down Expand Up @@ -1704,6 +1704,7 @@ module InfoMemberPrinting =
| _ ->
layout,
minfo.GetParamDatas (amap, m, minst)
|> List.map (List.map fst)
|> List.concat
|> List.map (layoutParamData denv)

Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Checking/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2393,13 +2393,13 @@ let CheckEntityDefn cenv env (tycon: Entity) =

if numCurriedArgSets > 1 &&
(minfo.GetParamDatas(cenv.amap, m, minfo.FormalMethodInst)
|> List.existsSquared (fun (ParamData(isParamArrayArg, _isInArg, isOutArg, optArgInfo, callerInfo, _, reflArgInfo, ty)) ->
|> List.existsSquared (fun (ParamData(isParamArrayArg, _isInArg, isOutArg, optArgInfo, callerInfo, _, reflArgInfo, ty), _) ->
isParamArrayArg || isOutArg || reflArgInfo.AutoQuote || optArgInfo.IsOptional || callerInfo <> NoCallerInfo || isByrefLikeTy g m ty)) then
errorR(Error(FSComp.SR.chkCurriedMethodsCantHaveOutParams(), m))

if numCurriedArgSets = 1 then
minfo.GetParamDatas(cenv.amap, m, minfo.FormalMethodInst)
|> List.iterSquared (fun (ParamData(_, isInArg, _, optArgInfo, callerInfo, _, _, ty)) ->
|> List.iterSquared (fun (ParamData(_, isInArg, _, optArgInfo, callerInfo, _, _, ty), _) ->
ignore isInArg
match (optArgInfo, callerInfo) with
| _, NoCallerInfo -> ()
Expand Down
14 changes: 7 additions & 7 deletions src/Compiler/Checking/infos.fs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ let CrackParamAttribsInfo g (ty: TType, argInfo: ArgReprInfo) =
| ValueSome optTy when typeEquiv g g.int32_ty optTy -> CallerFilePath
| _ -> CallerLineNumber

ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo), argInfo.Attribs

#if !NO_TYPEPROVIDERS

Expand Down Expand Up @@ -1293,7 +1293,7 @@ type MethInfo =
if p.Type.TypeRef.FullName = "System.Int32" then CallerFilePath
else CallerLineNumber

ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo) ] ]
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo), [] ] ]

| FSMeth(g, _, vref, _) ->
GetArgInfosOfMember x.IsCSharpStyleExtensionMember g vref
Expand All @@ -1315,7 +1315,7 @@ type MethInfo =
| None -> ReflectedArgInfo.None
let isOutArg = p.PUntaint((fun p -> p.IsOut && not p.IsIn), m)
let isInArg = p.PUntaint((fun p -> p.IsIn && not p.IsOut), m)
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, NoCallerInfo, reflArgInfo)] ]
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, NoCallerInfo, reflArgInfo), [] ] ]
#endif

/// Get the signature of an abstract method slot.
Expand Down Expand Up @@ -1426,13 +1426,13 @@ type MethInfo =
#endif

let paramAttribs = x.GetParamAttribs(amap, m)
(paramAttribs, paramNamesAndTypes) ||> List.map2 (List.map2 (fun info (ParamNameAndType(nmOpt, pty)) ->
let (ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)) = info
ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, nmOpt, reflArgInfo, pty)))
(paramAttribs, paramNamesAndTypes) ||> List.map2 (List.map2 (fun (info, attribs) (ParamNameAndType(nmOpt, pty)) ->
let (ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)) = info
ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, nmOpt, reflArgInfo, pty), attribs))

/// Get the ParamData objects for the parameters of a MethInfo
member x.HasParamArrayArg(amap, m, minst) =
x.GetParamDatas(amap, m, minst) |> List.existsSquared (fun (ParamData(isParamArrayArg, _, _, _, _, _, _, _)) -> isParamArrayArg)
x.GetParamDatas(amap, m, minst) |> List.existsSquared (fun (ParamData(isParamArrayArg, _, _, _, _, _, _, _), _) -> isParamArrayArg)

/// Select all the type parameters of the declaring type of a method.
///
Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/Checking/infos.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ type ParamAttribs =
callerInfo: CallerInfo *
reflArgInfo: ReflectedArgInfo

val CrackParamAttribsInfo: TcGlobals -> ty: TType * argInfo: ArgReprInfo -> ParamAttribs
val CrackParamAttribsInfo: TcGlobals -> ty: TType * argInfo: ArgReprInfo -> ParamAttribs * Attribs

/// Describes an F# use of an IL type, including the type instantiation associated with the type at a particular usage point.
[<NoComparison; NoEquality>]
Expand Down Expand Up @@ -524,10 +524,10 @@ type MethInfo =
member GetCustomAttrs: unit -> ILAttributes

/// Get the parameter attributes of a method info, which get combined with the parameter names and types
member GetParamAttribs: amap: ImportMap * m: range -> ParamAttribs list list
member GetParamAttribs: amap: ImportMap * m: range -> (ParamAttribs * Attribs) list list

/// Get the ParamData objects for the parameters of a MethInfo
member GetParamDatas: amap: ImportMap * m: range * minst: TType list -> ParamData list list
member GetParamDatas: amap: ImportMap * m: range * minst: TType list -> (ParamData * Attribs) list list

/// Get the parameter names of a MethInfo
member GetParamNames: unit -> string option list list
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ type internal TypeCheckInfo
match meth.GetParamDatas(amap, m, meth.FormalMethodInst) with
| x :: _ ->
x
|> List.choose (fun (ParamData(_isParamArray, _isInArg, _isOutArg, _optArgInfo, _callerInfo, name, _, ty)) ->
|> List.choose (fun (ParamData(_isParamArray, _isInArg, _isOutArg, _optArgInfo, _callerInfo, name, _, ty), _) ->
match name with
| Some id -> Some(Item.OtherName(Some id, ty, None, Some(ArgumentContainer.Method meth), id.idRange))
| None -> None)
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Service/ServiceDeclarationLists.fs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ module internal DescriptionListsImpl =

| Item.CtorGroup(_, minfo :: _)
| Item.MethodGroup(_, minfo :: _, _) ->
let paramDatas = minfo.GetParamDatas(amap, m, minfo.FormalMethodInst) |> List.head
let paramDatas = minfo.GetParamDatas(amap, m, minfo.FormalMethodInst) |> List.head |> List.map fst
let retTy = minfo.GetFSharpReturnType(amap, m, minfo.FormalMethodInst)
let _prettyTyparInst, prettyParams, prettyRetTyL, _prettyConstraintsL = PrettyParamsOfParamDatas g denv item.TyparInstantiation paramDatas retTy
// FUTURE: prettyTyparInst is the pretty version of the known instantiations of type parameters in the output. It could be returned
Expand Down
6 changes: 2 additions & 4 deletions src/Compiler/Symbols/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2120,10 +2120,8 @@ type FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) =
| M m | C m ->
[ for argTys in m.GetParamDatas(cenv.amap, range0, m.FormalMethodInst) do
yield
[ for ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, _callerInfo, nmOpt, _reflArgInfo, pty) in argTys do
// INCOMPLETENESS: Attribs is empty here, so we can't look at attributes for
// either .NET or F# parameters
let argInfo: ArgReprInfo = { Name=nmOpt; Attribs=[]; OtherRange=None }
[ for ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, _callerInfo, nmOpt, _reflArgInfo, pty), attribs in argTys do
let argInfo: ArgReprInfo = { Name=nmOpt; Attribs=attribs; OtherRange=None }
let m =
match nmOpt with
| Some v -> v.idRange
Expand Down

0 comments on commit 3724334

Please sign in to comment.