Skip to content

Commit e353fd0

Browse files
authored
use xml doc from signature if non present in impl (#14920)
* use xml doc from signature if non present in impl for DU and DU case * Implement the docs fallback for RecdField * format * implement Modules * clean up tests
1 parent ea212a9 commit e353fd0

File tree

5 files changed

+308
-38
lines changed

5 files changed

+308
-38
lines changed

src/Compiler/Checking/SignatureConformance.fs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
166166
and checkTypeDef (aenv: TypeEquivEnv) (infoReader: InfoReader) (implTycon: Tycon) (sigTycon: Tycon) =
167167
let m = implTycon.Range
168168

169+
implTycon.SetOtherXmlDoc(sigTycon.XmlDoc)
170+
169171
// Propagate defn location information from implementation to signature .
170172
sigTycon.SetOtherRange (implTycon.Range, true)
171173
implTycon.SetOtherRange (sigTycon.Range, false)
@@ -365,7 +367,9 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
365367
| _ ->
366368
(errorR (err FSComp.SR.ExceptionDefsNotCompatibleExceptionDeclarationsDiffer); false)
367369

368-
and checkUnionCase aenv infoReader (enclosingTycon: Tycon) implUnionCase sigUnionCase =
370+
and checkUnionCase aenv infoReader (enclosingTycon: Tycon) (implUnionCase: UnionCase) (sigUnionCase: UnionCase) =
371+
implUnionCase.SetOtherXmlDoc(sigUnionCase.XmlDoc)
372+
369373
let err f = errorR(UnionCaseNotContained(denv, infoReader, enclosingTycon, implUnionCase, sigUnionCase, f));false
370374
sigUnionCase.OtherRangeOpt <- Some (implUnionCase.Range, true)
371375
implUnionCase.OtherRangeOpt <- Some (sigUnionCase.Range, false)
@@ -376,6 +380,8 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
376380
else checkAttribs aenv implUnionCase.Attribs sigUnionCase.Attribs (fun attribs -> implUnionCase.Attribs <- attribs)
377381

378382
and checkField aenv infoReader (enclosingTycon: Tycon) implField sigField =
383+
implField.SetOtherXmlDoc(sigField.XmlDoc)
384+
379385
let err f = errorR(FieldNotContained(denv, infoReader, enclosingTycon, implField, sigField, f)); false
380386
sigField.rfield_other_range <- Some (implField.Range, true)
381387
implField.rfield_other_range <- Some (sigField.Range, false)
@@ -646,7 +652,8 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
646652
allPairsOk && not someNotOk)
647653

648654

649-
and checkModuleOrNamespace aenv (infoReader: InfoReader) implModRef sigModRef =
655+
and checkModuleOrNamespace aenv (infoReader: InfoReader) implModRef sigModRef =
656+
implModRef.SetOtherXmlDoc(sigModRef.XmlDoc)
650657
// Propagate defn location information from implementation to signature .
651658
sigModRef.SetOtherRange (implModRef.Range, true)
652659
implModRef.Deref.SetOtherRange (sigModRef.Range, false)

src/Compiler/TypedTree/TypedTree.fs

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ type EntityOptionalData =
563563
// MUTABILITY: only for unpickle linkage
564564
mutable entity_xmldoc: XmlDoc
565565

566+
/// the signature xml doc for an item in an implementation file.
567+
mutable entity_other_xmldoc : XmlDoc option
568+
566569
/// The XML document signature for this entity
567570
mutable entity_xmldocsig: string
568571

@@ -651,7 +654,8 @@ type Entity =
651654
{ entity_compiled_name = None
652655
entity_other_range = None
653656
entity_kind = TyparKind.Type
654-
entity_xmldoc = XmlDoc.Empty
657+
entity_xmldoc = XmlDoc.Empty
658+
entity_other_xmldoc = None
655659
entity_xmldocsig = ""
656660
entity_tycon_abbrev = None
657661
entity_tycon_repr_accessibility = TAccess []
@@ -764,6 +768,11 @@ type Entity =
764768
match x.entity_opt_data with
765769
| Some optData -> optData.entity_other_range <- Some m
766770
| _ -> x.entity_opt_data <- Some { Entity.NewEmptyEntityOptData() with entity_other_range = Some m }
771+
772+
member x.SetOtherXmlDoc xmlDoc =
773+
match x.entity_opt_data with
774+
| Some optData -> optData.entity_other_xmldoc <- Some xmlDoc
775+
| _ -> x.entity_opt_data <- Some { Entity.NewEmptyEntityOptData() with entity_other_xmldoc = Some xmlDoc }
767776

768777
/// A unique stamp for this module, namespace or type definition within the context of this compilation.
769778
/// Note that because of signatures, there are situations where in a single compilation the "same"
@@ -787,7 +796,13 @@ type Entity =
787796
| _ ->
788797
#endif
789798
match x.entity_opt_data with
790-
| Some optData -> optData.entity_xmldoc
799+
| Some optData ->
800+
if not optData.entity_xmldoc.IsEmpty then
801+
optData.entity_xmldoc
802+
else
803+
match optData.entity_other_xmldoc with
804+
| Some xmlDoc -> xmlDoc
805+
| None -> XmlDoc.Empty
791806
| _ -> XmlDoc.Empty
792807

793808
/// The XML documentation sig-string of the entity, if any, to use to lookup an .xml doc file. This also acts
@@ -1046,6 +1061,7 @@ type Entity =
10461061
entity_kind = tg.entity_kind
10471062
entity_xmldoc = tg.entity_xmldoc
10481063
entity_xmldocsig = tg.entity_xmldocsig
1064+
entity_other_xmldoc = tg.entity_other_xmldoc
10491065
entity_tycon_abbrev = tg.entity_tycon_abbrev
10501066
entity_tycon_repr_accessibility = tg.entity_tycon_repr_accessibility
10511067
entity_accessibility = tg.entity_accessibility
@@ -1659,7 +1675,10 @@ type UnionCase =
16591675
ReturnType: TType
16601676

16611677
/// Documentation for the case
1662-
XmlDoc: XmlDoc
1678+
OwnXmlDoc: XmlDoc
1679+
1680+
/// Documentation for the case from signature file
1681+
mutable OtherXmlDoc: XmlDoc
16631682

16641683
/// XML documentation signature for the case
16651684
mutable XmlDocSig: string
@@ -1679,7 +1698,14 @@ type UnionCase =
16791698
// MUTABILITY: used when propagating signature attributes into the implementation.
16801699
mutable Attribs: Attribs
16811700
}
1682-
1701+
1702+
/// Documentation for the case
1703+
member uc.XmlDoc: XmlDoc =
1704+
if not uc.OwnXmlDoc.IsEmpty then
1705+
uc.OwnXmlDoc
1706+
else
1707+
uc.OtherXmlDoc
1708+
16831709
/// Get the declaration location of the union case
16841710
member uc.Range = uc.Id.idRange
16851711

@@ -1695,6 +1721,9 @@ type UnionCase =
16951721
| Some (m, false) -> m
16961722
| _ -> uc.Range
16971723

1724+
member x.SetOtherXmlDoc xmlDoc =
1725+
x.OtherXmlDoc <- xmlDoc
1726+
16981727
/// Get the logical name of the union case
16991728
member uc.LogicalName = uc.Id.idText
17001729

@@ -1751,6 +1780,9 @@ type RecdField =
17511780

17521781
/// Documentation for the field
17531782
rfield_xmldoc: XmlDoc
1783+
1784+
/// Documentation for the field from signature file
1785+
mutable rfield_otherxmldoc: XmlDoc
17541786

17551787
/// XML Documentation signature for the field
17561788
mutable rfield_xmldocsig: string
@@ -1843,7 +1875,14 @@ type RecdField =
18431875
member v.FormalType = v.rfield_type
18441876

18451877
/// XML Documentation signature for the field
1846-
member v.XmlDoc = v.rfield_xmldoc
1878+
member v.XmlDoc =
1879+
if not v.rfield_xmldoc.IsEmpty then
1880+
v.rfield_xmldoc
1881+
else
1882+
v.rfield_otherxmldoc
1883+
1884+
member v.SetOtherXmlDoc (xmlDoc: XmlDoc) =
1885+
v.rfield_otherxmldoc <- xmlDoc
18471886

18481887
/// Get or set the XML documentation signature for the field
18491888
member v.XmlDocSig
@@ -3491,7 +3530,15 @@ type EntityRef =
34913530
/// then this _does_ include this documentation. If the entity is backed by Abstract IL metadata
34923531
/// or comes from another F# assembly then it does not (because the documentation will get read from
34933532
/// an XML file).
3494-
member x.XmlDoc = x.Deref.XmlDoc
3533+
member x.XmlDoc =
3534+
if not (x.Deref.XmlDoc.IsEmpty) then
3535+
x.Deref.XmlDoc
3536+
else
3537+
x.Deref.entity_opt_data
3538+
|> Option.bind (fun d -> d.entity_other_xmldoc)
3539+
|> Option.defaultValue XmlDoc.Empty
3540+
3541+
member x.SetOtherXmlDoc (xmlDoc: XmlDoc) = x.Deref.SetOtherXmlDoc(xmlDoc)
34953542

34963543
/// The XML documentation sig-string of the entity, if any, to use to lookup an .xml doc file. This also acts
34973544
/// as a cache for this sig-string computation.
@@ -5844,7 +5891,8 @@ type Construct() =
58445891
/// Create a new union case node
58455892
static member NewUnionCase id tys retTy attribs docOption access: UnionCase =
58465893
{ Id = id
5847-
XmlDoc = docOption
5894+
OwnXmlDoc = docOption
5895+
OtherXmlDoc = XmlDoc.Empty
58485896
XmlDocSig = ""
58495897
Accessibility = access
58505898
FieldTable = Construct.MakeRecdFieldsTable tys
@@ -5883,7 +5931,8 @@ type Construct() =
58835931
rfield_const = konst
58845932
rfield_access = access
58855933
rfield_secret = secret
5886-
rfield_xmldoc = docOption
5934+
rfield_xmldoc = docOption
5935+
rfield_otherxmldoc = XmlDoc.Empty
58875936
rfield_xmldocsig = ""
58885937
rfield_id = id
58895938
rfield_name_generated = nameGenerated

src/Compiler/TypedTree/TypedTree.fsi

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ type EntityOptionalData =
353353
/// The declared documentation for the type or module
354354
mutable entity_xmldoc: XmlDoc
355355

356+
/// the signature xml doc for an item in an implementation file.
357+
mutable entity_other_xmldoc: XmlDoc option
358+
356359
/// The XML document signature for this entity
357360
mutable entity_xmldocsig: string
358361

@@ -460,6 +463,8 @@ type Entity =
460463

461464
member SetOtherRange: m: (range * bool) -> unit
462465

466+
member SetOtherXmlDoc: xmlDoc: XmlDoc -> unit
467+
463468
member SetTypeAbbrev: tycon_abbrev: TType option -> unit
464469

465470
member SetTypeOrMeasureKind: kind: TyparKind -> unit
@@ -1114,7 +1119,10 @@ type UnionCase =
11141119
ReturnType: TType
11151120

11161121
/// Documentation for the case
1117-
XmlDoc: XmlDoc
1122+
OwnXmlDoc: XmlDoc
1123+
1124+
/// Documentation for the case from signature file
1125+
mutable OtherXmlDoc: XmlDoc
11181126

11191127
/// XML documentation signature for the case
11201128
mutable XmlDocSig: string
@@ -1133,6 +1141,8 @@ type UnionCase =
11331141
mutable Attribs: Attribs
11341142
}
11351143

1144+
member XmlDoc: XmlDoc
1145+
11361146
/// Get a field of the union case by position
11371147
member GetFieldByIndex: n: int -> RecdField
11381148

@@ -1184,6 +1194,8 @@ type UnionCase =
11841194
/// Get the signature location of the union case
11851195
member SigRange: range
11861196

1197+
member SetOtherXmlDoc: xmlDoc: XmlDoc -> unit
1198+
11871199
/// Represents a class, struct, record or exception field in an F# type, exception or union-case definition.
11881200
/// This may represent a "field" in either a struct, class, record or union.
11891201
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
@@ -1196,6 +1208,9 @@ type RecdField =
11961208
/// Documentation for the field
11971209
rfield_xmldoc: XmlDoc
11981210

1211+
/// Documentation for the field from signature file
1212+
mutable rfield_otherxmldoc: XmlDoc
1213+
11991214
/// XML Documentation signature for the field
12001215
mutable rfield_xmldocsig: string
12011216

@@ -1294,6 +1309,8 @@ type RecdField =
12941309
/// Get or set the XML documentation signature for the field
12951310
member XmlDocSig: string with get, set
12961311

1312+
member SetOtherXmlDoc: xmlDoc: XmlDoc -> unit
1313+
12971314
/// Represents the implementation of an F# exception definition.
12981315
[<NoEquality; NoComparison>]
12991316
type ExceptionInfo =
@@ -2640,6 +2657,8 @@ type EntityRef =
26402657
/// an XML file).
26412658
member XmlDoc: XmlDoc
26422659

2660+
member SetOtherXmlDoc: XmlDoc -> unit
2661+
26432662
/// The XML documentation sig-string of the entity, if any, to use to lookup an .xml doc file. This also acts
26442663
/// as a cache for this sig-string computation.
26452664
member XmlDocSig: string

src/Compiler/TypedTree/TypedTreePickle.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,8 @@ and u_unioncase_spec st =
20462046
ReturnType=b
20472047
Id=d
20482048
Attribs=e
2049-
XmlDoc= defaultArg xmldoc XmlDoc.Empty
2049+
OwnXmlDoc= defaultArg xmldoc XmlDoc.Empty
2050+
OtherXmlDoc = XmlDoc.Empty
20502051
XmlDocSig=f
20512052
Accessibility=i
20522053
OtherRangeOpt=None }
@@ -2088,6 +2089,7 @@ and u_recdfield_spec st =
20882089
rfield_pattribs=e1
20892090
rfield_fattribs=e2
20902091
rfield_xmldoc= defaultArg xmldoc XmlDoc.Empty
2092+
rfield_otherxmldoc = XmlDoc.Empty
20912093
rfield_xmldocsig=f
20922094
rfield_access=g
20932095
rfield_name_generated = d.idRange.IsSynthetic

0 commit comments

Comments
 (0)