Skip to content

Commit 2de4045

Browse files
authored
SynLongIdent (#13057)
* Refactor LongIdentWithDots to LongIdentWithTrivia. * Start using IndentWithTrivia in SyntaxTree. * Address aesthetic feedback. * Refactored IdentWithTrivia and LongIdentWithTrivia to SynIdent and SynLongIdent. Restored SynExpr.Ident. * Capturing some additional IdentTrivia.OriginalNotation. * SurfaceArea 🎉 * Update operator ident nodes in ServiceUntypedParse.fs. * Fix remaining Visual Studio tests. * Change the Ident of SynPat.Named to SynIdent to capture active patterns without parameters. * Replace LongIdentWithDots function usage with SynLongIdent. * Correct notation of prefix operators.
1 parent 37b9738 commit 2de4045

26 files changed

+1192
-333
lines changed

src/fsharp/CheckComputationExpressions.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ let TcComputationExpression (cenv: cenv) env (overallTy: OverallTy) tpenv (mWhol
244244
| args -> SynExpr.Paren (SynExpr.Tuple (false, args, [], m), range0, None, m)
245245

246246
let builderVal = mkSynIdGet m builderValName
247-
mkSynApp1 (SynExpr.DotGet (builderVal, range0, LongIdentWithDots([mkSynId m nm], []), m)) args m
247+
mkSynApp1 (SynExpr.DotGet (builderVal, range0, SynLongIdent([mkSynId m nm], [], [None]), m)) args m
248248

249249
let hasMethInfo nm = TryFindIntrinsicOrExtensionMethInfo ResultCollectionSettings.AtMostOneResult cenv env mBuilderVal ad nm builderTy |> isNil |> not
250250

@@ -690,7 +690,7 @@ let TcComputationExpression (cenv: cenv) env (overallTy: OverallTy) tpenv (mWhol
690690
match patvs with
691691
| [] -> SynExpr.Const (SynConst.Unit, m)
692692
| [v] -> SynExpr.Ident v.Id
693-
| vs -> SynExpr.Tuple (false, (vs |> List.map (fun v -> SynExpr.Ident v.Id)), [], m)
693+
| vs -> SynExpr.Tuple (false, (vs |> List.map (fun v -> SynExpr.Ident(v.Id))), [], m)
694694

695695
let mkSimplePatForVarSpace m (patvs: Val list) =
696696
let spats =
@@ -1236,8 +1236,8 @@ let TcComputationExpression (cenv: cenv) env (overallTy: OverallTy) tpenv (mWhol
12361236
Some (transBind q varSpace mBind (addBindDebugPoint spBind) "Bind" [rhsExpr] pat innerComp translatedCtxt)
12371237

12381238
// 'use! pat = e1 in e2' --> build.Bind(e1, (function _argN -> match _argN with pat -> build.Using(x, (fun _argN -> match _argN with pat -> e2))))
1239-
| SynExpr.LetOrUseBang (bindDebugPoint=spBind; isUse=true; isFromSource=isFromSource; pat=SynPat.Named (ident=id; isThisVal=false) as pat; rhs=rhsExpr; andBangs=[]; body=innerComp)
1240-
| SynExpr.LetOrUseBang (bindDebugPoint=spBind; isUse=true; isFromSource=isFromSource; pat=SynPat.LongIdent (longDotId=LongIdentWithDots(id=[id])) as pat; rhs=rhsExpr; andBangs=[]; body=innerComp) ->
1239+
| SynExpr.LetOrUseBang (bindDebugPoint=spBind; isUse=true; isFromSource=isFromSource; pat=SynPat.Named (ident=SynIdent(id,_); isThisVal=false) as pat; rhs=rhsExpr; andBangs=[]; body=innerComp)
1240+
| SynExpr.LetOrUseBang (bindDebugPoint=spBind; isUse=true; isFromSource=isFromSource; pat=SynPat.LongIdent (longDotId=LongIdentWithDots([id], _)) as pat; rhs=rhsExpr; andBangs=[]; body=innerComp) ->
12411241

12421242
let mBind = match spBind with DebugPointAtBinding.Yes m -> m | _ -> rhsExpr.Range
12431243
if isQuery then error(Error(FSComp.SR.tcBindMayNotBeUsedInQueries(), mBind))
@@ -1249,7 +1249,7 @@ let TcComputationExpression (cenv: cenv) env (overallTy: OverallTy) tpenv (mWhol
12491249

12501250
let bindExpr =
12511251
let consumeExpr = SynExpr.MatchLambda(false, mBind, [SynMatchClause(pat, None, transNoQueryOps innerComp, innerComp.Range, DebugPointAtTarget.Yes, SynMatchClauseTrivia.Zero)], DebugPointAtBinding.NoneAtInvisible, mBind)
1252-
let consumeExpr = mkSynCall "Using" mBind [SynExpr.Ident(id); consumeExpr ]
1252+
let consumeExpr = mkSynCall "Using" mBind [SynExpr.Ident id; consumeExpr ]
12531253
let consumeExpr = SynExpr.MatchLambda(false, mBind, [SynMatchClause(pat, None, consumeExpr, id.idRange, DebugPointAtTarget.No, SynMatchClauseTrivia.Zero)], DebugPointAtBinding.NoneAtInvisible, mBind)
12541254
let rhsExpr = mkSourceExprConditional isFromSource rhsExpr
12551255
mkSynCall "Bind" mBind [rhsExpr; consumeExpr]

src/fsharp/CheckDeclarations.fs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ module TcRecdUnionAndEnumDeclarations =
476476
| _ ->
477477
seen.Add(f.LogicalName, sf))
478478

479-
let TcUnionCaseDecl (cenv: cenv) env parent thisTy thisTyInst tpenv (SynUnionCase(Attributes synAttrs, id, args, xmldoc, vis, m, _)) =
479+
let TcUnionCaseDecl (cenv: cenv) env parent thisTy thisTyInst tpenv (SynUnionCase(Attributes synAttrs, SynIdent(id, _), args, xmldoc, vis, m, _)) =
480480
let g = cenv.g
481481
let attrs = TcAttributes cenv env AttributeTargets.UnionCaseDecl synAttrs // the attributes of a union case decl get attached to the generated "static factory" method
482482
let vis, _ = ComputeAccessAndCompPath env None m vis None parent
@@ -527,7 +527,7 @@ module TcRecdUnionAndEnumDeclarations =
527527
let unionCasesR = unionCases |> List.map (TcUnionCaseDecl cenv env parent thisTy thisTyInst tpenv)
528528
unionCasesR |> CheckDuplicates (fun uc -> uc.Id) "union case"
529529

530-
let TcEnumDecl cenv env parent thisTy fieldTy (SynEnumCase(attributes=Attributes synAttrs; ident=id; value=v; xmlDoc=xmldoc; range=m)) =
530+
let TcEnumDecl cenv env parent thisTy fieldTy (SynEnumCase(attributes=Attributes synAttrs; ident= SynIdent(id,_); value=v; xmlDoc=xmldoc; range=m)) =
531531
let attrs = TcAttributes cenv env AttributeTargets.Field synAttrs
532532
match v with
533533
| SynConst.Bytes _
@@ -3001,7 +3001,7 @@ let CheckForDuplicateModule env nm m =
30013001
/// Check 'exception' declarations in implementations and signatures
30023002
module TcExceptionDeclarations =
30033003

3004-
let TcExnDefnCore_Phase1A cenv env parent (SynExceptionDefnRepr(Attributes synAttrs, SynUnionCase(ident=id), _, doc, vis, m)) =
3004+
let TcExnDefnCore_Phase1A cenv env parent (SynExceptionDefnRepr(Attributes synAttrs, SynUnionCase(ident= SynIdent(id,_)), _, doc, vis, m)) =
30053005
let attrs = TcAttributes cenv env AttributeTargets.ExnDecl synAttrs
30063006
if not (String.isLeadingIdentifierCharacterUpperCase id.idText) then errorR(NotUpperCaseConstructor m)
30073007
let vis, cpath = ComputeAccessAndCompPath env None m vis None parent
@@ -4831,7 +4831,7 @@ module TcDeclarations =
48314831
let attribs = attribs |> List.filter (fun a -> match a.Target with Some t when t.idText = "field" -> true | _ -> false)
48324832
let mLetPortion = synExpr.Range
48334833
let fldId = ident (CompilerGeneratedName id.idText, mLetPortion)
4834-
let headPat = SynPat.LongIdent (LongIdentWithDots([fldId], []), None, None, Some noInferredTypars, SynArgPats.Pats [], None, mLetPortion)
4834+
let headPat = SynPat.LongIdent (SynLongIdent([fldId], [], [None]), None, None, Some noInferredTypars, SynArgPats.Pats [], None, mLetPortion)
48354835
let retInfo = match tyOpt with None -> None | Some ty -> Some (SynReturnInfo((ty, SynInfo.unnamedRetVal), ty.Range))
48364836
let isMutable =
48374837
match propKind with
@@ -4859,7 +4859,7 @@ module TcDeclarations =
48594859
let attribs = attribs |> List.filter (fun a -> match a.Target with Some t when t.idText = "field" -> false | _ -> true)
48604860
let fldId = ident (CompilerGeneratedName id.idText, mMemberPortion)
48614861
let headPatIds = if isStatic then [id] else [ident ("__", mMemberPortion);id]
4862-
let headPat = SynPat.LongIdent (LongIdentWithDots(headPatIds, []), None, None, Some noInferredTypars, SynArgPats.Pats [], None, mMemberPortion)
4862+
let headPat = SynPat.LongIdent (SynLongIdent(headPatIds, [], List.replicate headPatIds.Length None), None, None, Some noInferredTypars, SynArgPats.Pats [], None, mMemberPortion)
48634863

48644864
match propKind, mGetSetOpt with
48654865
| SynMemberKind.PropertySet, Some m -> errorR(Error(FSComp.SR.parsMutableOnAutoPropertyShouldBeGetSetNotJustSet(), m))
@@ -4884,7 +4884,7 @@ module TcDeclarations =
48844884
| SynMemberKind.PropertyGetSet ->
48854885
let setter =
48864886
let vId = ident("v", mMemberPortion)
4887-
let headPat = SynPat.LongIdent (LongIdentWithDots(headPatIds, []), None, None, Some noInferredTypars, SynArgPats.Pats [mkSynPatVar None vId], None, mMemberPortion)
4887+
let headPat = SynPat.LongIdent (SynLongIdent(headPatIds, [], List.replicate headPatIds.Length None), None, None, Some noInferredTypars, SynArgPats.Pats [mkSynPatVar None vId], None, mMemberPortion)
48884888
let rhsExpr = mkSynAssign (SynExpr.Ident fldId) (SynExpr.Ident vId)
48894889
//let retInfo = match tyOpt with None -> None | Some ty -> Some (SynReturnInfo((ty, SynInfo.unnamedRetVal), ty.Range))
48904890
let binding = mkSynBinding (xmlDoc, headPat) (access, false, false, mMemberPortion, DebugPointAtBinding.NoneAtInvisible, None, rhsExpr, rhsExpr.Range, [], [], Some (memberFlags SynMemberKind.PropertySet), SynBindingTrivia.Zero)
@@ -5350,7 +5350,7 @@ and TcSignatureElementsMutRec cenv parent typeNames m mutRecNSInfo envInitial (d
53505350
decls, (openOk, moduleAbbrevOk)
53515351

53525352
| SynModuleSigDecl.Exception (exnSig=SynExceptionSig(exnRepr=exnRepr; withKeyword=withKeyword; members=members)) ->
5353-
let ( SynExceptionDefnRepr(synAttrs, SynUnionCase(ident=id), _, doc, vis, m)) = exnRepr
5353+
let ( SynExceptionDefnRepr(synAttrs, SynUnionCase(ident=SynIdent(id,_)), _, doc, vis, m)) = exnRepr
53545354
let compInfo = SynComponentInfo(synAttrs, None, [], [id], doc, false, vis, id.idRange)
53555355
let decls = [ MutRecShape.Tycon(SynTypeDefnSig.SynTypeDefnSig(compInfo, None, SynTypeDefnSigRepr.Exception exnRepr, withKeyword, members, m)) ]
53565356
decls, (false, false)
@@ -5688,7 +5688,7 @@ and TcModuleOrNamespaceElementsMutRec (cenv: cenv) parent typeNames m envInitial
56885688
decls, (openOk, moduleAbbrevOk, attrs)
56895689

56905690
| SynModuleDecl.Exception (SynExceptionDefn(repr, _, members, _), _m) ->
5691-
let (SynExceptionDefnRepr(synAttrs, SynUnionCase(ident=id), _repr, doc, vis, m)) = repr
5691+
let (SynExceptionDefnRepr(synAttrs, SynUnionCase(ident=SynIdent(id,_)), _repr, doc, vis, m)) = repr
56925692
let compInfo = SynComponentInfo(synAttrs, None, [], [id], doc, false, vis, id.idRange)
56935693
let decls = [ MutRecShape.Tycon(SynTypeDefn(compInfo, SynTypeDefnRepr.Exception repr, members, None, m, SynTypeDefnTrivia.Zero)) ]
56945694
decls, (false, false, attrs)

0 commit comments

Comments
 (0)