Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main to feature/nullness #16866

Merged
merged 7 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions FSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{4E4F41D9-8
docs\optimizations.md = docs\optimizations.md
docs\optimizations-equality.md = docs\optimizations-equality.md
docs\overview.md = docs\overview.md
docs\builder-caches.md = docs\builder-caches.md
docs\changing-the-ast.md = docs\changing-the-ast.md
docs\names.md = docs\names.md
docs\perf-discussions-archive.md = docs\perf-discussions-archive.md
docs\project-builds.md = docs\project-builds.md
docs\representations.md = docs\representations.md
docs\running-documentation-locally.md = docs\running-documentation-locally.md
docs\tooling-features.md = docs\tooling-features.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fcs", "fcs", "{B86EBFF1-E03E-4FAE-89BF-60A4CAE2BC78}"
Expand All @@ -79,6 +87,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fcs", "fcs", "{B86EBFF1-E03
docs\fcs\tokenizer.fsx = docs\fcs\tokenizer.fsx
docs\fcs\typedtree.fsx = docs\fcs\typedtree.fsx
docs\fcs\untypedtree.fsx = docs\fcs\untypedtree.fsx
docs\fcs\untypedtree-apis.fsx = docs\fcs\untypedtree-apis.fsx
EndProjectSection
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "fsc", "src\fsc\fscProject\fsc.fsproj", "{10D15DBB-EFF0-428C-BA83-41600A93EEC4}"
Expand All @@ -105,6 +114,56 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Benchmarks.Common", "tests\benchmarks\FSharp.Benchmarks.Common\FSharp.Benchmarks.Common.fsproj", "{7D482560-DF6F-46A5-B50C-20ECF7C38759}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{10F0D468-FD52-4658-811E-7ED6A8318449}"
ProjectSection(SolutionItems) = preProject
docs\content\fsdocs-theme.css = docs\content\fsdocs-theme.css
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "img", "img", "{99773BD6-F1D7-48E2-AD72-AC48DA6BB293}"
ProjectSection(SolutionItems) = preProject
docs\img\favicon.ico = docs\img\favicon.ico
docs\img\logo.png = docs\img\logo.png
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "release-notes", "release-notes", "{C28ABF2D-6B43-4B0F-A12B-38570C5D9A81}"
ProjectSection(SolutionItems) = preProject
docs\release-notes\About.md = docs\release-notes\About.md
docs\release-notes\FSharp.Compiler.Service.fsx = docs\release-notes\FSharp.Compiler.Service.fsx
docs\release-notes\FSharp.Core.fsx = docs\release-notes\FSharp.Core.fsx
docs\release-notes\Language.fsx = docs\release-notes\Language.fsx
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".aux", ".aux", "{F1DADFB8-F320-40B6-B430-0ED5C37D3BAC}"
ProjectSection(SolutionItems) = preProject
docs\release-notes\.aux\Common.fsx = docs\release-notes\.aux\Common.fsx
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".FSharp.Compiler.Service", ".FSharp.Compiler.Service", "{01C43145-5289-47BF-A19B-B9F0FB66254D}"
ProjectSection(SolutionItems) = preProject
docs\release-notes\.FSharp.Compiler.Service\8.0.100.md = docs\release-notes\.FSharp.Compiler.Service\8.0.100.md
docs\release-notes\.FSharp.Compiler.Service\8.0.200.md = docs\release-notes\.FSharp.Compiler.Service\8.0.200.md
docs\release-notes\.FSharp.Compiler.Service\8.0.202.md = docs\release-notes\.FSharp.Compiler.Service\8.0.202.md
docs\release-notes\.FSharp.Compiler.Service\8.0.300.md = docs\release-notes\.FSharp.Compiler.Service\8.0.300.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".FSharp.Core", ".FSharp.Core", "{23798638-A1E9-4DAE-9C9C-F5D87499ADD6}"
ProjectSection(SolutionItems) = preProject
docs\release-notes\.FSharp.Core\8.0.200.md = docs\release-notes\.FSharp.Core\8.0.200.md
docs\release-notes\.FSharp.Core\8.0.300.md = docs\release-notes\.FSharp.Core\8.0.300.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Language", ".Language", "{1478B841-73BD-4E68-8F23-413ABB0B991F}"
ProjectSection(SolutionItems) = preProject
docs\release-notes\.Language\8.0.md = docs\release-notes\.Language\8.0.md
docs\release-notes\.Language\preview.md = docs\release-notes\.Language\preview.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".VisualStudio", ".VisualStudio", "{AF70EC5A-8E7C-4FDA-857D-AF08082CFC64}"
ProjectSection(SolutionItems) = preProject
docs\release-notes\.VisualStudio\17.9.md = docs\release-notes\.VisualStudio\17.9.md
docs\release-notes\.VisualStudio\17.10.md = docs\release-notes\.VisualStudio\17.10.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -433,6 +492,14 @@ Global
{BEC6E796-7E53-4888-AAFC-B8FD55C425DF} = {CE70D631-C5DC-417E-9CDA-B16097BEF1AC}
{9C7523BA-7AB2-4604-A5FD-653E82C2BAD1} = {CE70D631-C5DC-417E-9CDA-B16097BEF1AC}
{7D482560-DF6F-46A5-B50C-20ECF7C38759} = {CE70D631-C5DC-417E-9CDA-B16097BEF1AC}
{10F0D468-FD52-4658-811E-7ED6A8318449} = {4E4F41D9-86A7-4F5D-B735-1A0744AB68AC}
{99773BD6-F1D7-48E2-AD72-AC48DA6BB293} = {4E4F41D9-86A7-4F5D-B735-1A0744AB68AC}
{C28ABF2D-6B43-4B0F-A12B-38570C5D9A81} = {4E4F41D9-86A7-4F5D-B735-1A0744AB68AC}
{F1DADFB8-F320-40B6-B430-0ED5C37D3BAC} = {C28ABF2D-6B43-4B0F-A12B-38570C5D9A81}
{01C43145-5289-47BF-A19B-B9F0FB66254D} = {C28ABF2D-6B43-4B0F-A12B-38570C5D9A81}
{23798638-A1E9-4DAE-9C9C-F5D87499ADD6} = {C28ABF2D-6B43-4B0F-A12B-38570C5D9A81}
{1478B841-73BD-4E68-8F23-413ABB0B991F} = {C28ABF2D-6B43-4B0F-A12B-38570C5D9A81}
{AF70EC5A-8E7C-4FDA-857D-AF08082CFC64} = {C28ABF2D-6B43-4B0F-A12B-38570C5D9A81}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BD5177C7-1380-40E7-94D2-7768E1A8B1B8}
Expand Down
3 changes: 3 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Enforce AttributeTargets on let values and functions. ([PR #16692](https://github.com/dotnet/fsharp/pull/16692))
* Enforce AttributeTargets on union case declarations. ([PR #16764](https://github.com/dotnet/fsharp/pull/16764))
* Disallow using base to invoke an abstract base method. ([Issue #13926](https://github.com/dotnet/fsharp/issues/13926), [PR #16773](https://github.com/dotnet/fsharp/pull/16773))
* Parser: fix pattern range for idents with trivia ([PR #16824](https://github.com/dotnet/fsharp/pull/16824))
* Fix broken code completion after a record type declaration ([PR #16813](https://github.com/dotnet/fsharp/pull/16813))

### Added

Expand All @@ -27,6 +29,7 @@
* Add switch to generate types and members with IL visibility that accurately represents their F# visibility. ([PR #15484](https://github.com/dotnet/fsharp/pull/15484)
* Allow returning bool instead of unit option for partial active patterns. ([Language suggestion #1041](https://github.com/fsharp/fslang-suggestions/issues/1041), [PR #16473](https://github.com/dotnet/fsharp/pull/16473))
* Symbols: Add GenericArguments to FSharpEntity ([PR #16470](https://github.com/dotnet/fsharp/pull/16470))
* Add extended data for `DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer` (FS0318). ([PR #16811](https://github.com/dotnet/fsharp/pull/16811)))

### Changed

Expand Down
11 changes: 9 additions & 2 deletions src/Compiler/Checking/SignatureConformance.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ exception InterfaceNotRevealed of DisplayEnv * TType * range

exception ArgumentsInSigAndImplMismatch of sigArg: Ident * implArg: Ident

exception DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer of
denv: DisplayEnv *
implTycon:Tycon *
sigTycon:Tycon *
implTypeAbbrev:TType *
sigTypeAbbrev:TType *
range: range

// Use a type to capture the constant, common parameters
type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =

Expand Down Expand Up @@ -589,8 +597,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
match implTycon.TypeAbbrev, sigTycon.TypeAbbrev with
| Some ty1, Some ty2 ->
if not (typeAEquiv g aenv ty1 ty2) then
let s1, s2, _ = NicePrint.minimalStringsOfTwoTypes denv ty1 ty2
errorR (Error (FSComp.SR.DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer(implTycon.TypeOrMeasureKind.ToString(), implTycon.DisplayName, s1, s2), m))
errorR (DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer(denv, implTycon, sigTycon, ty1, ty2, m))
false
else
true
Expand Down
8 changes: 8 additions & 0 deletions src/Compiler/Checking/SignatureConformance.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ exception InterfaceNotRevealed of DisplayEnv * TType * range

exception ArgumentsInSigAndImplMismatch of sigArg: Ident * implArg: Ident

exception DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer of
denv: DisplayEnv *
implTycon: Tycon *
sigTycon: Tycon *
implTypeAbbrev: TType *
sigTypeAbbrev: TType *
range: range

type Checker =

new:
Expand Down
21 changes: 19 additions & 2 deletions src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Exception with

member exn.DiagnosticRange =
match exn with
| DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer(range = m) -> Some m
| ArgumentsInSigAndImplMismatch(_, implArg) -> Some implArg.idRange
| ErrorFromAddingConstraint(_, exn2, _) -> exn2.DiagnosticRange
#if !NO_TYPEPROVIDERS
Expand Down Expand Up @@ -324,22 +325,24 @@ type Exception with
| BadEventTransformation _ -> 91
| HashLoadedScriptConsideredSource _ -> 92
| UnresolvedConversionOperator _ -> 93
| ArgumentsInSigAndImplMismatch _ -> 3218

// avoid 94-100 for safety
| ObsoleteError _ -> 101
#if !NO_TYPEPROVIDERS
| TypeProviders.ProvidedTypeResolutionNoRange _
| TypeProviders.ProvidedTypeResolution _ -> 103
#endif
| PatternMatchCompilation.EnumMatchIncomplete _ -> 104
| Failure _ -> 192
| DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer _ -> 318
| ArgumentsInSigAndImplMismatch _ -> 3218

// Strip TargetInvocationException wrappers
| :? TargetInvocationException as e -> e.InnerException.DiagnosticNumber
| WrappedError(e, _) -> e.DiagnosticNumber
| DiagnosticWithText(n, _, _) -> n
| DiagnosticWithSuggestions(n, _, _, _, _) -> n
| DiagnosticEnabledWithLanguageFeature(n, _, _, _) -> n
| Failure _ -> 192
| IllegalFileNameChar(fileName, invalidChar) -> fst (FSComp.SR.buildUnexpectedFileNameCharacter (fileName, string invalidChar))
#if !NO_TYPEPROVIDERS
| :? TypeProviderError as e -> e.Number
Expand Down Expand Up @@ -618,6 +621,9 @@ module OldStyleMessages =
let TargetInvocationExceptionWrapperE () = Message("TargetInvocationExceptionWrapper", "%s")
let ArgumentsInSigAndImplMismatchE () = Message("ArgumentsInSigAndImplMismatch", "%s%s")

let DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferE () =
Message("DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer", "%s%s%s%s")

#if DEBUG
let mutable showParserStackOnParseError = false
#endif
Expand Down Expand Up @@ -1921,6 +1927,17 @@ type Exception with
| ArgumentsInSigAndImplMismatch(sigArg, implArg) ->
os.AppendString(ArgumentsInSigAndImplMismatchE().Format sigArg.idText implArg.idText)

| DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer(denv, implTycon, _sigTycon, implTypeAbbrev, sigTypeAbbrev, _m) ->
let s1, s2, _ = NicePrint.minimalStringsOfTwoTypes denv implTypeAbbrev sigTypeAbbrev

os.AppendString(
DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferE().Format
(implTycon.TypeOrMeasureKind.ToString())
implTycon.DisplayName
s1
s2
)

// Strip TargetInvocationException wrappers
| :? TargetInvocationException as exn -> exn.InnerException.Output(os, suggestNames)

Expand Down
1 change: 0 additions & 1 deletion src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ ValueNotContainedMutabilityInstanceButStatic,"Module '%s' contains\n %s \n
315,DefinitionsInSigAndImplNotCompatibleAbstractMemberMissingInImpl,"The %s definitions for type '%s' in the signature and implementation are not compatible because the abstract member '%s' was required by the signature but was not specified by the implementation"
316,DefinitionsInSigAndImplNotCompatibleAbstractMemberMissingInSig,"The %s definitions for type '%s' in the signature and implementation are not compatible because the abstract member '%s' was present in the implementation but not in the signature"
317,DefinitionsInSigAndImplNotCompatibleSignatureDeclaresDiffer,"The %s definitions for type '%s' in the signature and implementation are not compatible because the signature declares a %s while the implementation declares a %s"
318,DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer,"The %s definitions for type '%s' in the signature and implementation are not compatible because the abbreviations differ: %s versus %s"
319,DefinitionsInSigAndImplNotCompatibleAbbreviationHiddenBySig,"The %s definitions for type '%s' in the signature and implementation are not compatible because an abbreviation is being hidden by a signature. The abbreviation must be visible to other CLI languages. Consider making the abbreviation visible in the signature."
320,DefinitionsInSigAndImplNotCompatibleSigHasAbbreviation,"The %s definitions for type '%s' in the signature and implementation are not compatible because the signature has an abbreviation while the implementation does not"
ModuleContainsConstructorButNamesDiffer,"The module contains the constructor\n %s \nbut its signature specifies\n %s \nThe names differ"
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/FSStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,9 @@
<data name="ArgumentsInSigAndImplMismatch" xml:space="preserve">
<value>The argument names in the signature '{0}' and implementation '{1}' do not match. The argument name from the signature file will be used. This may cause problems when debugging or profiling.</value>
</data>
<data name="DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer" xml:space="preserve">
<value>The {0} definitions for type '{1}' in the signature and implementation are not compatible because the abbreviations differ:\n {2}\nversus\n {3}</value>
</data>
<data name="Parser.TOKEN.WHILE.BANG" xml:space="preserve">
<value>keyword 'while!'</value>
</data>
Expand Down
8 changes: 6 additions & 2 deletions src/Compiler/Service/ServiceParsedInputOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ module ParsedInput =
| SynType.LongIdent _ when rangeContainsPos ty.Range pos -> Some CompletionContext.Type
| _ -> defaultTraverse ty

member _.VisitRecordDefn(_, fields, _) =
member _.VisitRecordDefn(_, fields, range) =
fields
|> List.tryPick (fun (SynField(idOpt = idOpt; range = fieldRange)) ->
match idOpt with
Expand All @@ -1656,7 +1656,11 @@ module ParsedInput =
| _ when rangeContainsPos fieldRange pos -> Some(CompletionContext.RecordField(RecordContext.Declaration false))
| _ -> None)
// No completions in a record outside of all fields, except in attributes, which is established earlier in VisitAttributeApplication
|> Option.orElse (Some CompletionContext.Invalid)
|> Option.orElseWith (fun _ ->
if rangeContainsPos range pos then
Some CompletionContext.Invalid
else
None)

member _.VisitUnionDefn(_, cases, _) =
cases
Expand Down
10 changes: 10 additions & 0 deletions src/Compiler/Symbols/FSharpDiagnostic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ module ExtendedData =
member x.ImplementationName = implArg.idText
member x.SignatureRange = sigArg.idRange
member x.ImplementationRange = implArg.idRange

[<Class; Experimental("This FCS API is experimental and subject to change.")>]
type DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferExtendedData
internal(signatureType: Tycon, implementationType: Tycon) =
interface IFSharpDiagnosticExtendedData
member x.SignatureRange: range = signatureType.Range
member x.ImplementationRange: range = implementationType.Range

open ExtendedData

Expand Down Expand Up @@ -191,6 +198,9 @@ type FSharpDiagnostic(m: range, severity: FSharpDiagnosticSeverity, message: str
| ArgumentsInSigAndImplMismatch(sigArg, implArg) ->
Some(ArgumentsInSigAndImplMismatchExtendedData(sigArg, implArg))

| DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer(implTycon = implTycon; sigTycon = sigTycon) ->
Some(DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferExtendedData(sigTycon, implTycon))

| _ -> None

let msg =
Expand Down
8 changes: 8 additions & 0 deletions src/Compiler/Symbols/FSharpDiagnostic.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ module public ExtendedData =
/// Argument identifier range within implementation file
member ImplementationRange: range

[<Class; Experimental("This FCS API is experimental and subject to change.")>]
type DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferExtendedData =
interface IFSharpDiagnosticExtendedData
/// Range of the signature type identifier.
member SignatureRange: range
/// Range of the implementation type identifier.
member ImplementationRange: range

open ExtendedData

/// Represents a diagnostic produced by the F# compiler
Expand Down
14 changes: 13 additions & 1 deletion src/Compiler/SyntaxTree/SyntaxTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ type Ident(text: string, range: range) =
member _.idRange = range
override _.ToString() = text

type SynIdent = SynIdent of ident: Ident * trivia: IdentTrivia option
type SynIdent =
| SynIdent of ident: Ident * trivia: IdentTrivia option

member this.Range =
match this with
| SynIdent(ident, trivia) ->
match trivia with
| Some value ->
match value with
| IdentTrivia.OriginalNotationWithParen(leftParen, _, rightParen)
| IdentTrivia.HasParenthesis(leftParen, rightParen) -> unionRanges leftParen rightParen
| _ -> ident.idRange
| None -> ident.idRange

type LongIdent = Ident list

Expand Down
5 changes: 4 additions & 1 deletion src/Compiler/SyntaxTree/SyntaxTree.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ type Ident =
member idRange: range

/// Represents an identifier with potentially additional trivia information.
type SynIdent = SynIdent of ident: Ident * trivia: IdentTrivia option
type SynIdent =
| SynIdent of ident: Ident * trivia: IdentTrivia option

member Range: range

/// Represents a long identifier e.g. 'A.B.C'
type LongIdent = Ident list
Expand Down
3 changes: 1 addition & 2 deletions src/Compiler/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -3638,8 +3638,7 @@ atomicPattern:
mkSynPatMaybeVar lidwd vis (lhs parseState)
else
let synIdent = List.head lidwd.IdentsWithTrivia
let (SynIdent(id, _)) = synIdent
SynPat.Named(synIdent, false, vis, id.idRange) }
SynPat.Named(synIdent, false, vis, synIdent.Range) }

| constant
{ SynPat.Const(fst $1, snd $1) }
Expand Down
5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading