Skip to content

Commit

Permalink
Move property item creation back to CheckDeclarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Oct 12, 2023
1 parent 43b6ac8 commit 34fe1e4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
33 changes: 32 additions & 1 deletion src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,37 @@ module MutRecBindingChecking =
| definition ->
error(InternalError(sprintf "Unexpected definition %A" definition, m)))

// Report any desugared properties
if defnAs.Length > 1 then
for b1, b2 in List.pairwise defnAs do
match b1, b2 with
| TyconBindingPhase2A.Phase2AMember {
SyntacticBinding = NormalizedBinding(pat = SynPat.Named(ident = SynIdent(ident = getIdent)); valSynData = SynValData(memberFlags = Some mf))
RecBindingInfo = RecursiveBindingInfo(vspec = vGet)
},
TyconBindingPhase2A.Phase2AMember {
SyntacticBinding = NormalizedBinding(pat = SynPat.Named(ident = SynIdent(ident = setIdent)))
RecBindingInfo = RecursiveBindingInfo(vspec = vSet)
} when Range.equals getIdent.idRange setIdent.idRange ->
match vGet.ApparentEnclosingEntity with
| ParentNone -> ()
| Parent parentRef ->
let apparentEnclosingType = generalizedTyconRef g parentRef
let vGet, vSet = if mf.MemberKind = SynMemberKind.PropertyGet then vGet, vSet else vSet, vGet
let propertyName =
if vGet.Id.idText.StartsWith("get_", StringComparison.InvariantCulture) then
vGet.Id.idText.Replace("get_", "")
else
vGet.Id.idText
let item =
Item.Property(
propertyName,
[ PropInfo.FSProp(g, apparentEnclosingType, Some (mkLocalValRef vGet), Some (mkLocalValRef vSet)) ],
Some getIdent.idRange
)
CallNameResolutionSink cenv.tcSink (getIdent.idRange, envForTycon.NameEnv, item, emptyTyparInst, ItemOccurence.Binding, envForTycon.eAccessRights)
| _ -> ()

// If no constructor call, insert Phase2AIncrClassCtorJustAfterSuperInit at start
let defnAs =
match defnAs with
Expand Down Expand Up @@ -5592,7 +5623,7 @@ let CheckOneImplFile
(g, cenv.amap, reportErrors, cenv.infoReader,
env.eInternalsVisibleCompPaths, cenv.thisCcu, tcVal, envAtEnd.DisplayEnv,
implFileTy, implFileContents, extraAttribs, isLastCompiland,
isInternalTestSpanStackReferring, cenv.tcSink, envAtEnd.NameEnv, envAtEnd.AccessRights)
isInternalTestSpanStackReferring)

with exn ->
errorRecovery exn m
Expand Down
28 changes: 2 additions & 26 deletions src/Compiler/Checking/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,6 @@ type cenv =
isLastCompiland : bool*bool

isInternalTestSpanStackReferring: bool

tcSink: TcResultsSink

nameEnv: NameResolutionEnv

accessRights:AccessorDomain

// outputs
mutable usesQuotations: bool
Expand Down Expand Up @@ -2426,21 +2420,6 @@ let CheckEntityDefn cenv env (tycon: Entity) =
if not (typeEquivAux EraseNone cenv.amap.g ty1 ty2) then
errorR(Error(FSComp.SR.chkGetterAndSetterHaveSamePropertyType(pinfo.PropertyName, NicePrint.minimalStringOfType cenv.denv ty1, NicePrint.minimalStringOfType cenv.denv ty2), m))

if pinfo.HasGetter && pinfo.HasSetter then
match pinfo.GetterMethod, pinfo.SetterMethod with
| MethInfo.FSMeth(valRef = vGet), MethInfo.FSMeth(valRef = vSet) when (Range.equals vGet.Id.idRange vSet.Id.idRange) ->
match vGet.ApparentEnclosingEntity with
| ParentNone -> ()
| Parent parentRef ->
let item =
Item.Property(
vGet.Id.idText,
[ PropInfo.FSProp(g, generalizedTyconRef g parentRef, Some vGet, Some vSet) ],
Some vGet.Id.idRange
)
CallNameResolutionSink cenv.tcSink (vGet.Id.idRange, cenv.nameEnv, item, emptyTyparInst, ItemOccurence.Binding, cenv.accessRights)
| _ -> ()

hashOfImmediateProps[nm] <- pinfo :: others

if not (isInterfaceTy g ty) then
Expand Down Expand Up @@ -2619,7 +2598,7 @@ let CheckImplFileContents cenv env implFileTy implFileContents =
UpdatePrettyTyparNames.updateModuleOrNamespaceType implFileTy
CheckDefnInModule cenv env implFileContents

let CheckImplFile (g, amap, reportErrors, infoReader, internalsVisibleToPaths, viewCcu, tcValF, denv, implFileTy, implFileContents, extraAttribs, isLastCompiland: bool*bool, isInternalTestSpanStackReferring, tcSink, nameEnv, accessRights) =
let CheckImplFile (g, amap, reportErrors, infoReader, internalsVisibleToPaths, viewCcu, tcValF, denv, implFileTy, implFileContents, extraAttribs, isLastCompiland: bool*bool, isInternalTestSpanStackReferring) =
let cenv =
{ g = g
reportErrors = reportErrors
Expand All @@ -2637,10 +2616,7 @@ let CheckImplFile (g, amap, reportErrors, infoReader, internalsVisibleToPaths, v
isLastCompiland = isLastCompiland
isInternalTestSpanStackReferring = isInternalTestSpanStackReferring
tcVal = tcValF
entryPointGiven = false
tcSink = tcSink
nameEnv = nameEnv
accessRights = accessRights }
entryPointGiven = false }

// Certain type equality checks go faster if these TyconRefs are pre-resolved.
// This is because pre-resolving allows tycon equality to be determined by pointer equality on the entities.
Expand Down
5 changes: 1 addition & 4 deletions src/Compiler/Checking/PostInferenceChecks.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ val CheckImplFile:
implFileContents: ModuleOrNamespaceContents *
extraAttribs: Attribs *
(bool * bool) *
isInternalTestSpanStackReferring: bool *
tcSink: TcResultsSink *
nameEnv: NameResolutionEnv *
accessRights: AccessorDomain ->
isInternalTestSpanStackReferring: bool ->
bool * StampMap<AnonRecdTypeInfo>

/// It's unlikely you want to use this module except within
Expand Down

0 comments on commit 34fe1e4

Please sign in to comment.