Skip to content
Prev Previous commit
Next Next commit
Normalize occurrence kinds, tweak replacing strategy, update baselines
  • Loading branch information
auduchinok committed Jul 19, 2023
commit 5d7fd3688ddd38de0a114ef01e0ebe174ad79eba
2 changes: 1 addition & 1 deletion src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ module MutRecBindingChecking =

// Phase2B: typecheck the argument to an 'inherits' call and build the new object expr for the inherit-call
| Phase2AInherit (synBaseTy, arg, baseValOpt, m) ->
let baseTy, tpenv = TcType cenv NoNewTypars CheckCxs ItemOccurence.Use WarnOnIWSAM.Yes envInstance tpenv synBaseTy
let baseTy, tpenv = TcType cenv NoNewTypars CheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes envInstance tpenv synBaseTy
let baseTy = baseTy |> convertToTypeWithMetadataIfPossible g
let inheritsExpr, tpenv =
try
Expand Down
45 changes: 23 additions & 22 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ let MakeAndPublishSimpleValsForMergedScope (cenv: cenv) env m (names: NameMap<_>
member _.NotifyEnvWithScope(_, _, _) = () // ignore EnvWithScope reports

member _.NotifyNameResolution(pos, item, itemTyparInst, occurence, nenv, ad, m, replacing) =
notifyNameResolution (pos, item, item, itemTyparInst, occurence, nenv, ad, m, replacing)
notifyNameResolution (pos, item, item, itemTyparInst, occurence, nenv, ad, m, Option.isSome replacing)

member _.NotifyMethodGroupNameResolution(pos, item, itemGroup, itemTyparInst, occurence, nenv, ad, m, replacing) =
notifyNameResolution (pos, item, itemGroup, itemTyparInst, occurence, nenv, ad, m, replacing)
Expand Down Expand Up @@ -4908,7 +4908,7 @@ and TcTypeApp (cenv: cenv) newOk checkConstraints occ env tpenv mItem mWhole tcr
// Get the suffix of typars
let tpsForArgs = List.skip (tps.Length - synArgTysLength) tps
let kindsForArgs = tpsForArgs |> List.map (fun tp -> tp.Kind)
TcTypesOrMeasures (Some kindsForArgs) cenv newOk checkConstraints occ env tpenv synArgTys mWhole
TcTypesOrMeasures (Some kindsForArgs) cenv newOk checkConstraints ItemOccurence.UseInType env tpenv synArgTys mWhole

// Add the types of the enclosing class for a nested type
let actualArgTys = pathTypeArgs @ argTys
Expand All @@ -4921,7 +4921,7 @@ and TcTypeApp (cenv: cenv) newOk checkConstraints occ env tpenv mItem mWhole tcr

if not actualArgTys.IsEmpty then
let item = Item.Types(tcref.DisplayNameCore, [ty])
CallNameResolutionSinkReplacing cenv.tcSink (mItem, env.NameEnv, item, getInst ty, occ, env.eAccessRights)
CallNameResolutionSinkReplacing cenv.tcSink (function Item.Types _ -> true | _ -> false) (mItem, env.NameEnv, item, getInst ty, occ, env.eAccessRights)

ty, tpenv

Expand Down Expand Up @@ -5254,7 +5254,7 @@ and TcExprThen (cenv: cenv) overallTy env tpenv isArg synExpr delayed =
| Some {contents = SynSimplePatAlternativeIdInfo.Decided altId} ->
TcExprThen cenv overallTy env tpenv isArg (SynExpr.LongIdent (isOpt, SynLongIdent([altId], [], [None]), None, mLongId)) delayed
| _ ->
TcLongIdentThen cenv overallTy env tpenv longId delayed
TcLongIdentThen cenv overallTy ItemOccurence.Use env tpenv longId delayed

// f?x<-v
| SynExpr.Set(SynExpr.Dynamic(e1, _, e2, _) , rhsExpr, m) ->
Expand Down Expand Up @@ -5598,7 +5598,7 @@ and TcExprUndelayed (cenv: cenv) (overallTy: OverallTy) env tpenv (synExpr: SynE
TcExprArrayOrList cenv overallTy env tpenv (isArray, args, m)

| SynExpr.New (superInit, synObjTy, arg, mNewExpr) ->
let objTy, tpenv = TcType cenv NewTyparsOK CheckCxs ItemOccurence.Use WarnOnIWSAM.Yes env tpenv synObjTy
let objTy, tpenv = TcType cenv NewTyparsOK CheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv synObjTy

TcNonControlFlowExpr env <| fun env ->
TcPropagatingExprLeafThenConvert cenv overallTy objTy env (* true *) mNewExpr (fun () ->
Expand Down Expand Up @@ -6069,11 +6069,11 @@ and TcExprDotNamedIndexedPropertySet (cenv: cenv) overallTy env tpenv (synExpr1,
MakeDelayedSet(expr3, mStmt)]

and TcExprLongIdentSet (cenv: cenv) overallTy env tpenv (synLongId, synExpr2, m) =
TcLongIdentThen cenv overallTy env tpenv synLongId [ MakeDelayedSet(synExpr2, m) ]
TcLongIdentThen cenv overallTy ItemOccurence.Use env tpenv synLongId [ MakeDelayedSet(synExpr2, m) ]

// Type.Items(synExpr1) <- synExpr2
and TcExprNamedIndexPropertySet (cenv: cenv) overallTy env tpenv (synLongId, synExpr1, synExpr2, mStmt) =
TcLongIdentThen cenv overallTy env tpenv synLongId
TcLongIdentThen cenv overallTy ItemOccurence.Use env tpenv synLongId
[ DelayedApp(ExprAtomicFlag.Atomic, false, None, synExpr1, mStmt)
MakeDelayedSet(synExpr2, mStmt) ]

Expand Down Expand Up @@ -6218,8 +6218,9 @@ and TcTyparExprThen (cenv: cenv) overallTy env tpenv synTypar m delayed =
match rest with
| [] -> delayed2
| _ -> DelayedDotLookup (rest, m2) :: delayed2
CallNameResolutionSink cenv.tcSink (ident.idRange, env.NameEnv, item, emptyTyparInst, ItemOccurence.Use, env.AccessRights)
TcItemThen cenv overallTy env tpenv ([], item, mExprAndLongId, [], AfterResolution.DoNothing) (Some ty) delayed3
let occ = ItemOccurence.Use
CallNameResolutionSink cenv.tcSink (ident.idRange, env.NameEnv, item, emptyTyparInst, occ, env.AccessRights)
TcItemThen cenv overallTy occ env tpenv ([], item, mExprAndLongId, [], AfterResolution.DoNothing) (Some ty) delayed3
//TcLookupItemThen cenv overallTy env tpenv mObjExpr objExpr objExprTy delayed item mItem rest afterResolution
| _ ->
let (SynTypar(_, q, _)) = synTypar
Expand Down Expand Up @@ -8031,7 +8032,7 @@ and TcNameOfExpr (cenv: cenv) env tpenv (synArg: SynExpr) =
| Item.FakeInterfaceCtor _ -> false
| _ -> true) ->
let overallTy = match overallTyOpt with None -> MustEqual (NewInferenceType g) | Some t -> t
let _, _ = TcItemThen cenv overallTy env tpenv res None delayed
let _, _ = TcItemThen cenv overallTy ItemOccurence.Use env tpenv res None delayed
true
| _ ->
false
Expand Down Expand Up @@ -8232,29 +8233,29 @@ and GetLongIdentTypeNameInfo delayed =
| _ ->
TypeNameResolutionInfo.Default

and TcLongIdentThen (cenv: cenv) (overallTy: OverallTy) env tpenv (SynLongIdent(longId, _, _)) delayed =
and TcLongIdentThen (cenv: cenv) (overallTy: OverallTy) occ env tpenv (SynLongIdent(longId, _, _)) delayed =

let ad = env.eAccessRights
let typeNameResInfo = GetLongIdentTypeNameInfo delayed
let nameResolutionResult =
ResolveLongIdentAsExprAndComputeRange cenv.tcSink cenv.nameResolver (rangeOfLid longId) ad env.eNameResEnv typeNameResInfo longId
|> ForceRaise
TcItemThen cenv overallTy env tpenv nameResolutionResult None delayed
TcItemThen cenv overallTy occ env tpenv nameResolutionResult None delayed

//-------------------------------------------------------------------------
// Typecheck "item+projections"
//------------------------------------------------------------------------- *)

// mItem is the textual range covered by the long identifiers that make up the item
and TcItemThen (cenv: cenv) (overallTy: OverallTy) env tpenv (tinstEnclosing, item, mItem, rest, afterResolution) staticTyOpt delayed =
and TcItemThen (cenv: cenv) (overallTy: OverallTy) occ env tpenv (tinstEnclosing, item, mItem, rest, afterResolution) staticTyOpt delayed =
let delayed = delayRest rest mItem delayed
match item with
// x where x is a union case or active pattern result tag.
| Item.UnionCase _ | Item.ExnCase _ | Item.ActivePatternResult _ as item ->
TcUnionCaseOrExnCaseOrActivePatternResultItemThen cenv overallTy env item tpenv mItem delayed

| Item.Types(nm, ty :: _) ->
TcTypeItemThen cenv overallTy env nm ty tpenv mItem tinstEnclosing delayed
TcTypeItemThen cenv overallTy occ env nm ty tpenv mItem tinstEnclosing delayed

| Item.MethodGroup (methodName, minfos, _) ->
TcMethodItemThen cenv overallTy env item methodName minfos tpenv mItem afterResolution staticTyOpt delayed
Expand All @@ -8270,7 +8271,7 @@ and TcItemThen (cenv: cenv) (overallTy: OverallTy) env tpenv (tinstEnclosing, it
match ty with
| TType_app(tcref, _, _) -> tcref.DisplayNameCore
| _ -> NicePrint.minimalStringOfType env.DisplayEnv ty
TcTypeItemThen cenv overallTy env nm ty tpenv mItem tinstEnclosing delayed
TcTypeItemThen cenv overallTy occ env nm ty tpenv mItem tinstEnclosing delayed

| Item.ImplicitOp(id, sln) ->
TcImplicitOpItemThen cenv overallTy env id sln tpenv mItem delayed
Expand Down Expand Up @@ -8479,7 +8480,7 @@ and TcUnionCaseOrExnCaseOrActivePatternResultItemThen (cenv: cenv) overallTy env
let exprTy = tyOfExpr g expr
PropagateThenTcDelayed cenv overallTy env tpenv mItem (MakeApplicableExprNoFlex cenv expr) exprTy ExprAtomicFlag.Atomic delayed

and TcTypeItemThen (cenv: cenv) overallTy env nm ty tpenv mItem tinstEnclosing delayed =
and TcTypeItemThen (cenv: cenv) overallTy occ env nm ty tpenv mItem tinstEnclosing delayed =
let g = cenv.g
let ad = env.eAccessRights

Expand All @@ -8494,23 +8495,23 @@ and TcTypeItemThen (cenv: cenv) overallTy env nm ty tpenv mItem tinstEnclosing d

let reportTypeUsage ty =
let item = Item.Types(nm, [ty])
CallNameResolutionSinkReplacing cenv.tcSink (mItem, env.NameEnv, item, getInst ty, ItemOccurence.Use, env.eAccessRights)
CallNameResolutionSinkReplacing cenv.tcSink (function Item.Types _ -> true | _ -> false) (mItem, env.NameEnv, item, getInst ty, occ, env.eAccessRights)

match delayed with
| DelayedTypeApp(tyargs, _mTypeArgs, mExprAndTypeArgs) :: DelayedDotLookup (longId, mLongId) :: otherDelayed ->
// If Item.Types is returned then the ty will be of the form TType_app(tcref, genericTyargs) where tyargs
// is a fresh instantiation for tcref. TcNestedTypeApplication will chop off precisely #genericTyargs args
// and replace them by 'tyargs'
let ty, tpenv = TcNestedTypeApplication cenv NewTyparsOK CheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv mItem mExprAndTypeArgs ty tinstEnclosing tyargs
let ty, tpenv = TcNestedTypeApplication cenv NewTyparsOK CheckCxs occ WarnOnIWSAM.Yes env tpenv mItem mExprAndTypeArgs ty tinstEnclosing tyargs
let typeNameResInfo = GetLongIdentTypeNameInfo otherDelayed
let item, mItem, rest, afterResolution = ResolveExprDotLongIdentAndComputeRange cenv.tcSink cenv.nameResolver (unionRanges mExprAndTypeArgs mLongId) ad env.eNameResEnv ty longId typeNameResInfo IgnoreOverrides true
TcItemThen cenv overallTy env tpenv ((argsOfAppTy g ty), item, mItem, rest, afterResolution) None otherDelayed
TcItemThen cenv overallTy occ env tpenv ((argsOfAppTy g ty), item, mItem, rest, afterResolution) None otherDelayed

| DelayedTypeApp(tyargs, _mTypeArgs, mExprAndTypeArgs) :: _delayed' ->
reportTypeUsage ty

// A case where we have an incomplete name e.g. 'Foo<int>.' - we still want to report it to VS!
let ty, _ = TcNestedTypeApplication cenv NewTyparsOK CheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv mItem mExprAndTypeArgs ty tinstEnclosing tyargs
let ty, _ = TcNestedTypeApplication cenv NewTyparsOK CheckCxs occ WarnOnIWSAM.Yes env tpenv mItem mExprAndTypeArgs ty tinstEnclosing tyargs
reportWrongTypeUsageError ty mItem mExprAndTypeArgs

| _ ->
Expand All @@ -8533,7 +8534,7 @@ and TcMethodItemThen (cenv: cenv) overallTy env item methodName minfos tpenv mIt

// Replace the resolution including the static parameters, plus the extra information about the original method info
let item = Item.MethodGroup(methodName, [minfoAfterStaticArguments], Some minfos[0])
CallNameResolutionSinkReplacing cenv.tcSink (mItem, env.NameEnv, item, [], ItemOccurence.Use, env.eAccessRights)
CallNameResolutionSinkReplacing cenv.tcSink (fun _ -> true) (mItem, env.NameEnv, item, [], ItemOccurence.Use, env.eAccessRights)

match otherDelayed with
| DelayedApp(atomicFlag, _, _, arg, mExprAndArg) :: otherDelayed ->
Expand Down Expand Up @@ -9089,7 +9090,7 @@ and TcLookupItemThen cenv overallTy env tpenv mObjExpr objExpr objExprTy delayed
| Some minfoAfterStaticArguments ->
// Replace the resolution including the static parameters, plus the extra information about the original method info
let item = Item.MethodGroup(methodName, [minfoAfterStaticArguments], Some minfos[0])
CallNameResolutionSinkReplacing cenv.tcSink (mExprAndItem, env.NameEnv, item, [], ItemOccurence.Use, env.eAccessRights)
CallNameResolutionSinkReplacing cenv.tcSink (fun _ -> true) (mExprAndItem, env.NameEnv, item, [], ItemOccurence.Use, env.eAccessRights)

TcMethodApplicationThen cenv env overallTy None tpenv None objArgs mExprAndItem mItem methodName ad mutates false [(minfoAfterStaticArguments, None)] afterResolution NormalValUse args atomicFlag None delayed
| None ->
Expand Down
16 changes: 9 additions & 7 deletions src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ type ITypecheckResultsSink =

abstract NotifyExprHasType: TType * NameResolutionEnv * AccessorDomain * range -> unit

abstract NotifyNameResolution: pos * item: Item * TyparInstantiation * ItemOccurence * NameResolutionEnv * AccessorDomain * range * replace: bool -> unit
abstract NotifyNameResolution: pos * item: Item * TyparInstantiation * ItemOccurence * NameResolutionEnv * AccessorDomain * range * replace: (Item -> bool) option -> unit

abstract NotifyMethodGroupNameResolution : pos * item: Item * itemMethodGroup: Item * TyparInstantiation * ItemOccurence * NameResolutionEnv * AccessorDomain * range * replace: bool -> unit

Expand Down Expand Up @@ -2144,7 +2144,9 @@ type TcResultsSinkImpl(tcGlobals, ?sourceText: ISourceText) =
if isAlreadyDone endPos item m || not (allowedRange m) then () else

let replaced =
if not replace then false else
match replace with
| None -> false
| Some f ->

match item with
| Item.MethodGroup _ ->
Expand All @@ -2154,10 +2156,10 @@ type TcResultsSinkImpl(tcGlobals, ?sourceText: ISourceText) =
| _ -> ()

match capturedNameResolutions.FindLastIndex(fun cnr -> equals cnr.Range m) with
| -1 -> false
| i ->
| i when i >= 0 && f capturedNameResolutions[i].Item ->
capturedNameResolutions[i] <- CapturedNameResolution(item, tpinst, occurenceType, nenv, ad, m)
true
| _ -> false

if not replaced then
capturedNameResolutions.Add(CapturedNameResolution(item, tpinst, occurenceType, nenv, ad, m))
Expand Down Expand Up @@ -2211,17 +2213,17 @@ let CallEnvSink (sink: TcResultsSink) (scopem, nenv, ad) =
let CallNameResolutionSink (sink: TcResultsSink) (m: range, nenv, item, tpinst, occurenceType, ad) =
match sink.CurrentSink with
| None -> ()
| Some sink -> sink.NotifyNameResolution(m.End, item, tpinst, occurenceType, nenv, ad, m, false)
| Some sink -> sink.NotifyNameResolution(m.End, item, tpinst, occurenceType, nenv, ad, m, None)

let CallMethodGroupNameResolutionSink (sink: TcResultsSink) (m: range, nenv, item, itemMethodGroup, tpinst, occurenceType, ad) =
match sink.CurrentSink with
| None -> ()
| Some sink -> sink.NotifyMethodGroupNameResolution(m.End, item, itemMethodGroup, tpinst, occurenceType, nenv, ad, m, false)

let CallNameResolutionSinkReplacing (sink: TcResultsSink) (m: range, nenv, item, tpinst, occurenceType, ad) =
let CallNameResolutionSinkReplacing (sink: TcResultsSink) f (m: range, nenv, item, tpinst, occurenceType, ad) =
match sink.CurrentSink with
| None -> ()
| Some sink -> sink.NotifyNameResolution(m.End, item, tpinst, occurenceType, nenv, ad, m, true)
| Some sink -> sink.NotifyNameResolution(m.End, item, tpinst, occurenceType, nenv, ad, m, Some f)

/// Report a specific expression typing at a source range
let CallExprHasTypeSink (sink: TcResultsSink) (m: range, nenv, ty, ad) =
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Checking/NameResolution.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ type ITypecheckResultsSink =

/// Record that a name resolution occurred at a specific location in the source
abstract NotifyNameResolution:
pos * Item * TyparInstantiation * ItemOccurence * NameResolutionEnv * AccessorDomain * range * bool -> unit
pos * Item * TyparInstantiation * ItemOccurence * NameResolutionEnv * AccessorDomain * range * (Item -> bool) option -> unit

/// Record that a method group name resolution occurred at a specific location in the source
abstract NotifyMethodGroupNameResolution:
Expand Down Expand Up @@ -619,7 +619,7 @@ val internal CallMethodGroupNameResolutionSink:

/// Report a specific name resolution at a source range, replacing any previous resolutions
val internal CallNameResolutionSinkReplacing:
TcResultsSink -> range * NameResolutionEnv * Item * TyparInstantiation * ItemOccurence * AccessorDomain -> unit
TcResultsSink -> (Item -> bool) -> range * NameResolutionEnv * Item * TyparInstantiation * ItemOccurence * AccessorDomain -> unit

/// Report a specific name resolution at a source range
val internal CallExprHasTypeSink: TcResultsSink -> range * NameResolutionEnv * TType * AccessorDomain -> unit
Expand Down
Loading