Skip to content

Commit a63a947

Browse files
authored
Merge branch 'main' into syntype-tuple-parameter-name
2 parents 33b4b2d + ec4f326 commit a63a947

File tree

31 files changed

+212
-360
lines changed

31 files changed

+212
-360
lines changed

src/Compiler/Driver/CompilerConfig.fs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,14 +1405,13 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
14051405
/// 'framework' reference set that is potentially shared across multiple compilations.
14061406
member tcConfig.IsSystemAssembly(fileName: string) =
14071407
try
1408+
let dirName = Path.GetDirectoryName fileName
1409+
let baseName = FileSystemUtils.fileNameWithoutExtension fileName
1410+
14081411
FileSystem.FileExistsShim fileName
1409-
&& ((tcConfig.GetTargetFrameworkDirectories()
1410-
|> List.exists (fun clrRoot -> clrRoot = Path.GetDirectoryName fileName))
1411-
|| (tcConfig
1412-
.FxResolver
1413-
.GetSystemAssemblies()
1414-
.Contains(FileSystemUtils.fileNameWithoutExtension fileName))
1415-
|| tcConfig.FxResolver.IsInReferenceAssemblyPackDirectory fileName)
1412+
&& ((tcConfig.GetTargetFrameworkDirectories() |> List.contains dirName)
1413+
|| FxResolver.GetSystemAssemblies().Contains baseName
1414+
|| FxResolver.IsReferenceAssemblyPackDirectoryApprox dirName)
14161415
with _ ->
14171416
false
14181417

src/Compiler/Driver/FxResolver.fs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ type internal FxResolver
611611
// A set of assemblies to always consider to be system assemblies. A common set of these can be used a shared
612612
// resources between projects in the compiler services. Also all assemblies where well-known system types exist
613613
// referenced from TcGlobals must be listed here.
614-
let systemAssemblies =
614+
static let systemAssemblies =
615615
HashSet
616616
[
617617
// NOTE: duplicates are ok in this list
@@ -789,17 +789,10 @@ type internal FxResolver
789789
"WindowsBase"
790790
]
791791

792-
member _.GetSystemAssemblies() = systemAssemblies
792+
static member GetSystemAssemblies() = systemAssemblies
793793

794-
member _.IsInReferenceAssemblyPackDirectory fileName =
795-
fxlock.AcquireLock(fun fxtok ->
796-
RequireFxResolverLock(fxtok, "assuming all member require lock")
797-
798-
match tryGetNetCoreRefsPackDirectoryRoot () |> replayWarnings with
799-
| _, Some root ->
800-
let path = Path.GetDirectoryName(fileName)
801-
path.StartsWith(root, StringComparison.OrdinalIgnoreCase)
802-
| _ -> false)
794+
static member IsReferenceAssemblyPackDirectoryApprox(dirName: string) =
795+
dirName.Contains "Microsoft.NETCore.App.Ref"
803796

804797
member _.TryGetSdkDir() =
805798
fxlock.AcquireLock(fun fxtok ->

src/Compiler/Driver/FxResolver.fsi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ type internal FxResolver =
2828

2929
member GetFrameworkRefsPackDirectory: unit -> string option
3030

31-
member GetSystemAssemblies: unit -> HashSet<string>
31+
static member GetSystemAssemblies: unit -> HashSet<string>
3232

3333
/// Gets the selected target framework moniker, e.g netcore3.0, net472, and the running rid of the current machine
3434
member GetTfmAndRid: unit -> string * string
3535

36-
member IsInReferenceAssemblyPackDirectory: fileName: string -> bool
36+
/// Determines if an assembly is in the core set of assemblies with high likelihood of
37+
/// being shared amongst a set of common scripting references
38+
static member IsReferenceAssemblyPackDirectoryApprox: dirName: string -> bool
3739

3840
member TryGetDesiredDotNetSdkVersionForDirectory: unit -> Result<string, exn>
3941

src/Compiler/Service/ServiceParsedInputOps.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ module ParsedInput =
581581
|> Option.orElseWith (fun () -> ifPosInRange r (fun _ -> List.tryPick (walkSynModuleDecl isTopLevel) decls))
582582

583583
and walkAttribute (attr: SynAttribute) =
584-
if isPosInRange attr.Range then
584+
if isPosInRange attr.TypeName.Range then
585585
Some EntityKind.Attribute
586586
else
587587
None

src/Compiler/SyntaxTree/ParseHelpers.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ let mkSynMemberDefnGetSet
468468
{
469469
LetKeyword = None
470470
EqualsRange = mEquals
471+
ExternKeyword = None
471472
}
472473

473474
let binding =
@@ -542,6 +543,7 @@ let mkSynMemberDefnGetSet
542543
{
543544
LetKeyword = None
544545
EqualsRange = mEquals
546+
ExternKeyword = None
545547
}
546548

547549
let binding =
@@ -629,6 +631,7 @@ let mkSynMemberDefnGetSet
629631
{
630632
LetKeyword = None
631633
EqualsRange = mEquals
634+
ExternKeyword = None
632635
}
633636

634637
let bindingOuter =

src/Compiler/SyntaxTree/SyntaxTrivia.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,14 @@ type SynTypeDefnSigTrivia =
159159
type SynBindingTrivia =
160160
{
161161
LetKeyword: range option
162+
ExternKeyword: range option
162163
EqualsRange: range option
163164
}
164165

165166
static member Zero: SynBindingTrivia =
166167
{
167168
LetKeyword = None
169+
ExternKeyword = None
168170
EqualsRange = None
169171
}
170172

src/Compiler/SyntaxTree/SyntaxTrivia.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ type SynBindingTrivia =
246246
/// The syntax range of the `let` keyword.
247247
LetKeyword: range option
248248

249+
/// The syntax range of the `extern` keyword.
250+
ExternKeyword: range option
251+
249252
/// The syntax range of the `=` token.
250253
EqualsRange: range option
251254
}

src/Compiler/pars.fsy

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,18 +1561,23 @@ attributeListElements:
15611561
attribute:
15621562
/* A custom attribute */
15631563
| path opt_HIGH_PRECEDENCE_APP opt_atomicExprAfterType
1564-
{ let arg = match $3 with None -> mkSynUnit $1.Range | Some e -> e
1565-
({ TypeName=$1; ArgExpr=arg; Target=None; AppliesToGetterAndSetter=false; Range=$1.Range } : SynAttribute) }
1564+
{ let arg = match $3 with None -> mkSynUnit $1.Range | Some e -> e
1565+
let m = unionRanges $1.Range arg.Range
1566+
({ TypeName=$1; ArgExpr=arg; Target=None; AppliesToGetterAndSetter=false; Range=m } : SynAttribute) }
15661567

15671568
/* A custom attribute with an attribute target */
15681569
| attributeTarget path opt_HIGH_PRECEDENCE_APP opt_atomicExprAfterType
1569-
{ let arg = match $4 with None -> mkSynUnit $2.Range | Some e -> e
1570-
({ TypeName=$2; ArgExpr=arg; Target=$1; AppliesToGetterAndSetter=false; Range=$2.Range } : SynAttribute) }
1570+
{ let arg = match $4 with None -> mkSynUnit $2.Range | Some e -> e
1571+
let startRange = match $1 with Some (ident:Ident) -> ident.idRange | None -> $2.Range
1572+
let m = unionRanges startRange arg.Range
1573+
({ TypeName=$2; ArgExpr=arg; Target=$1; AppliesToGetterAndSetter=false; Range=m } : SynAttribute) }
15711574

15721575
/* A custom attribute with an attribute target */
15731576
| attributeTarget OBLOCKBEGIN path oblockend opt_HIGH_PRECEDENCE_APP opt_atomicExprAfterType
15741577
{ let arg = match $6 with None -> mkSynUnit $3.Range | Some e -> e
1575-
({ TypeName=$3; ArgExpr=arg; Target=$1; AppliesToGetterAndSetter=false; Range=$3.Range } : SynAttribute) }
1578+
let startRange = match $1 with Some ident -> ident.idRange | None -> $3.Range
1579+
let m = unionRanges startRange arg.Range
1580+
({ TypeName=$3; ArgExpr=arg; Target=$1; AppliesToGetterAndSetter=false; Range=m } : SynAttribute) }
15761581

15771582

15781583
/* The target of a custom attribute */
@@ -1863,7 +1868,7 @@ memberCore:
18631868
let xmlDoc = grabXmlDocAtRangeStart(parseState, attrs, rangeStart)
18641869
let memberFlags = Some (memFlagsBuilder SynMemberKind.Member)
18651870
let mWholeBindLhs = (mBindLhs, attrs) ||> unionRangeWithListBy (fun (a: SynAttributeList) -> a.Range)
1866-
let trivia: SynBindingTrivia = { LetKeyword = None; EqualsRange = Some mEquals }
1871+
let trivia: SynBindingTrivia = { LetKeyword = None; EqualsRange = Some mEquals; ExternKeyword = None }
18671872
let binding = mkSynBinding (xmlDoc, bindingPat) (vis, $1, false, mWholeBindLhs, DebugPointAtBinding.NoneAtInvisible, optReturnType, $5, mRhs, [], attrs, memberFlags, trivia)
18681873
let memberRange = unionRanges rangeStart mRhs |> unionRangeWithXmlDoc xmlDoc
18691874
[ SynMemberDefn.Member (binding, memberRange) ]) }
@@ -1980,7 +1985,7 @@ classDefnMember:
19801985
let declPat = SynPat.LongIdent (SynLongIdent([mkSynId (rhs parseState 3) "new"], [], [None]), None, Some noInferredTypars, SynArgPats.Pats [$4], vis, rhs parseState 3)
19811986
// Check that 'SynPatForConstructorDecl' matches this correctly
19821987
assert (match declPat with SynPatForConstructorDecl _ -> true | _ -> false)
1983-
let synBindingTrivia: SynBindingTrivia = { LetKeyword = None; EqualsRange = Some mEquals }
1988+
let synBindingTrivia: SynBindingTrivia = { LetKeyword = None; EqualsRange = Some mEquals; ExternKeyword = None }
19841989
[ SynMemberDefn.Member(SynBinding (None, SynBindingKind.Normal, false, false, $1, xmlDoc, valSynData, declPat, None, expr, mWholeBindLhs, DebugPointAtBinding.NoneAtInvisible, synBindingTrivia), m) ] }
19851990

19861991
| opt_attributes opt_declVisibility STATIC typeKeyword tyconDefn
@@ -2738,7 +2743,8 @@ hardwhiteDefnBindingsTerminator:
27382743
/* An 'extern' DllImport function definition in C-style syntax */
27392744
cPrototype:
27402745
| EXTERN cRetType opt_access ident opt_HIGH_PRECEDENCE_APP LPAREN externArgs rparen
2741-
{ let rty, vis, nm, args = $2, $3, $4, $7
2746+
{ let mExtern = rhs parseState 1
2747+
let rty, vis, nm, args = $2, $3, $4, $7
27422748
let nmm = rhs parseState 3
27432749
let argsm = rhs parseState 6
27442750
let mBindLhs = lhs parseState
@@ -2755,10 +2761,11 @@ cPrototype:
27552761
let bindingPat = SynPat.LongIdent (SynLongIdent([nm], [], [None]), None, Some noInferredTypars, SynArgPats.Pats [SynPat.Tuple(false, args, argsm)], vis, nmm)
27562762
let mWholeBindLhs = (mBindLhs, attrs) ||> unionRangeWithListBy (fun (a: SynAttributeList) -> a.Range)
27572763
let xmlDoc = grabXmlDoc(parseState, attrs, 1)
2764+
let trivia = { LetKeyword = None; ExternKeyword = Some mExtern; EqualsRange = None }
27582765
let binding =
27592766
mkSynBinding
27602767
(xmlDoc, bindingPat)
2761-
(vis, false, false, mWholeBindLhs, DebugPointAtBinding.NoneAtInvisible, Some rty, rhsExpr, mRhs, [], attrs, None, SynBindingTrivia.Zero)
2768+
(vis, false, false, mWholeBindLhs, DebugPointAtBinding.NoneAtInvisible, Some rty, rhsExpr, mRhs, [], attrs, None, trivia)
27622769
[], [binding]) }
27632770

27642771
/* A list of arguments in an 'extern' DllImport function definition */
@@ -2877,7 +2884,7 @@ localBinding:
28772884
let mWhole = (unionRanges mLetKwd mRhs, attrs) ||> unionRangeWithListBy (fun (a: SynAttributeList) -> a.Range)
28782885
let spBind = if IsDebugPointBinding bindingPat expr then DebugPointAtBinding.Yes mWhole else DebugPointAtBinding.NoneAtLet
28792886
let mWholeBindLhs = (mBindLhs, attrs) ||> unionRangeWithListBy (fun (a: SynAttributeList) -> a.Range)
2880-
let trivia: SynBindingTrivia = { LetKeyword = Some mLetKwd; EqualsRange = Some mEquals }
2887+
let trivia: SynBindingTrivia = { LetKeyword = Some mLetKwd; EqualsRange = Some mEquals; ExternKeyword = None }
28812888
mkSynBinding (xmlDoc, bindingPat) (vis, $1, $2, mWholeBindLhs, spBind, optReturnType, expr, mRhs, opts, attrs, None, trivia))
28822889
localBindingRange, localBindingBuilder }
28832890

@@ -2892,7 +2899,7 @@ localBinding:
28922899
let zeroWidthAtEnd = mEquals.EndRange
28932900
let rhsExpr = arbExpr("localBinding1", zeroWidthAtEnd)
28942901
let spBind = if IsDebugPointBinding bindingPat rhsExpr then DebugPointAtBinding.Yes mWhole else DebugPointAtBinding.NoneAtLet
2895-
let trivia: SynBindingTrivia = { LetKeyword = Some mLetKwd; EqualsRange = Some mEquals }
2902+
let trivia: SynBindingTrivia = { LetKeyword = Some mLetKwd; EqualsRange = Some mEquals; ExternKeyword = None }
28962903
mkSynBinding (xmlDoc, bindingPat) (vis, $1, $2, mBindLhs, spBind, optReturnType, rhsExpr, mRhs, [], attrs, None, trivia))
28972904
mWhole, localBindingBuilder }
28982905

@@ -2905,7 +2912,7 @@ localBinding:
29052912
let localBindingBuilder =
29062913
(fun xmlDoc attrs vis mLetKwd ->
29072914
let spBind = DebugPointAtBinding.Yes (unionRanges mLetKwd mRhs)
2908-
let trivia = { LetKeyword = Some mLetKwd; EqualsRange = None }
2915+
let trivia = { LetKeyword = Some mLetKwd; EqualsRange = None; ExternKeyword = None }
29092916
let rhsExpr = arbExpr("localBinding2", mRhs)
29102917
mkSynBinding (xmlDoc, bindingPat) (vis, $1, $2, mBindLhs, spBind, optReturnType, rhsExpr, mRhs, [], attrs, None, trivia))
29112918
mWhole, localBindingBuilder }

tests/FSharp.Compiler.ComponentTests/Conformance/BasicTypeAndModuleDefinitions/GeneratedEqualityHashingComparison/Attributes/Diags/Diags.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Diags =
1717
|> compile
1818
|> shouldFail
1919
|> withDiagnostics [
20-
(Error 501, Line 7, Col 3, Line 7, Col 23, "The object constructor 'StructuralComparisonAttribute' takes 0 argument(s) but is here given 1. The required signature is 'new: unit -> StructuralComparisonAttribute'.")
20+
(Error 501, Line 7, Col 3, Line 7, Col 30, "The object constructor 'StructuralComparisonAttribute' takes 0 argument(s) but is here given 1. The required signature is 'new: unit -> StructuralComparisonAttribute'.")
2121
]
2222

2323
// SOURCE=E_AdjustUses01b.fs SCFLAGS=--test:ErrorRanges # E_AdjustUses01b.fs
@@ -28,6 +28,6 @@ module Diags =
2828
|> compile
2929
|> shouldFail
3030
|> withDiagnostics [
31-
(Error 501, Line 7, Col 3, Line 7, Col 23, "The object constructor 'StructuralComparisonAttribute' takes 0 argument(s) but is here given 1. The required signature is 'new: unit -> StructuralComparisonAttribute'.")
31+
(Error 501, Line 7, Col 3, Line 7, Col 30, "The object constructor 'StructuralComparisonAttribute' takes 0 argument(s) but is here given 1. The required signature is 'new: unit -> StructuralComparisonAttribute'.")
3232
]
3333

0 commit comments

Comments
 (0)