Skip to content

Commit 8f550ae

Browse files
authored
Merge branch 'main' into cache-2
2 parents bd7c24d + c4001e5 commit 8f550ae

20 files changed

+263
-186
lines changed

docs/release-notes/.FSharp.Compiler.Service/10.0.100.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* TypeMismatchDiagnosticExtendedData: fix expected and actual types calculation. ([Issue ](https://github.com/dotnet/fsharp/pull/18851))
2929
* Format top-level generic types using a prefix style in inherit/interface declarations and flexible type annotations. ([PR #18897](https://github.com/dotnet/fsharp/pull/18897))
3030
* Parser: fix range for computed binding expressions ([PR #18903](https://github.com/dotnet/fsharp/pull/18903))
31+
* Tests: set test source for range debug printing ([PR #18879](https://github.com/dotnet/fsharp/pull/18879))
32+
* Checker: fix declaring type for abbreviated types extensions ([PR #18909](https://github.com/dotnet/fsharp/pull/18909))
3133

3234
### Changed
3335
* Use `errorR` instead of `error` in `CheckDeclarations.fs` when possible. ([PR #18645](https://github.com/dotnet/fsharp/pull/18645))

eng/Version.Details.props

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ This file should be imported by eng/Versions.props
2020
<!-- dotnet/arcade dependencies -->
2121
<MicrosoftDotNetArcadeSdkPackageVersion>10.0.0-beta.25426.3</MicrosoftDotNetArcadeSdkPackageVersion>
2222
<!-- _git/dotnet-optimization dependencies -->
23-
<optimizationlinuxarm64MIBCRuntimePackageVersion>1.0.0-prerelease.25458.1</optimizationlinuxarm64MIBCRuntimePackageVersion>
24-
<optimizationlinuxx64MIBCRuntimePackageVersion>1.0.0-prerelease.25458.1</optimizationlinuxx64MIBCRuntimePackageVersion>
25-
<optimizationwindows_ntarm64MIBCRuntimePackageVersion>1.0.0-prerelease.25458.1</optimizationwindows_ntarm64MIBCRuntimePackageVersion>
26-
<optimizationwindows_ntx64MIBCRuntimePackageVersion>1.0.0-prerelease.25458.1</optimizationwindows_ntx64MIBCRuntimePackageVersion>
27-
<optimizationwindows_ntx86MIBCRuntimePackageVersion>1.0.0-prerelease.25458.1</optimizationwindows_ntx86MIBCRuntimePackageVersion>
23+
<optimizationlinuxarm64MIBCRuntimePackageVersion>1.0.0-prerelease.25467.1</optimizationlinuxarm64MIBCRuntimePackageVersion>
24+
<optimizationlinuxx64MIBCRuntimePackageVersion>1.0.0-prerelease.25467.1</optimizationlinuxx64MIBCRuntimePackageVersion>
25+
<optimizationwindows_ntarm64MIBCRuntimePackageVersion>1.0.0-prerelease.25467.1</optimizationwindows_ntarm64MIBCRuntimePackageVersion>
26+
<optimizationwindows_ntx64MIBCRuntimePackageVersion>1.0.0-prerelease.25467.1</optimizationwindows_ntx64MIBCRuntimePackageVersion>
27+
<optimizationwindows_ntx86MIBCRuntimePackageVersion>1.0.0-prerelease.25467.1</optimizationwindows_ntx86MIBCRuntimePackageVersion>
2828
</PropertyGroup>
2929
<!--Property group for alternate package version names-->
3030
<PropertyGroup>

eng/Version.Details.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Dependencies>
3-
<Source Uri="https://github.com/dotnet/dotnet" Mapping="fsharp" Sha="8ea69c337be69385ff7eb44b2a54db78010110d8" BarId="282240" />
3+
<Source Uri="https://github.com/dotnet/dotnet" Mapping="fsharp" Sha="e533cfad385ba4f0ec96e35ad3d485dc13581906" BarId="283666" />
44
<ProductDependencies>
55
<Dependency Name="Microsoft.Build" Version="18.0.0-preview-25465-08">
66
<Uri>https://github.com/dotnet/msbuild</Uri>
@@ -48,25 +48,25 @@
4848
<Uri>https://github.com/dotnet/arcade</Uri>
4949
<Sha>5db998e02282e63bc375948a237bcdfef534a5c5</Sha>
5050
</Dependency>
51-
<Dependency Name="optimization.windows_nt-x64.MIBC.Runtime" Version="1.0.0-prerelease.25458.1">
51+
<Dependency Name="optimization.windows_nt-x64.MIBC.Runtime" Version="1.0.0-prerelease.25467.1">
5252
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
53-
<Sha>373ed5bf1a64c212e655063e58967eb62f9187ef</Sha>
53+
<Sha>59dc6a9bf1b3e3ab71c73d94160c2049fb104cd1</Sha>
5454
</Dependency>
55-
<Dependency Name="optimization.windows_nt-x86.MIBC.Runtime" Version="1.0.0-prerelease.25458.1">
55+
<Dependency Name="optimization.windows_nt-x86.MIBC.Runtime" Version="1.0.0-prerelease.25467.1">
5656
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
57-
<Sha>373ed5bf1a64c212e655063e58967eb62f9187ef</Sha>
57+
<Sha>59dc6a9bf1b3e3ab71c73d94160c2049fb104cd1</Sha>
5858
</Dependency>
59-
<Dependency Name="optimization.linux-x64.MIBC.Runtime" Version="1.0.0-prerelease.25458.1">
59+
<Dependency Name="optimization.linux-x64.MIBC.Runtime" Version="1.0.0-prerelease.25467.1">
6060
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
61-
<Sha>373ed5bf1a64c212e655063e58967eb62f9187ef</Sha>
61+
<Sha>59dc6a9bf1b3e3ab71c73d94160c2049fb104cd1</Sha>
6262
</Dependency>
63-
<Dependency Name="optimization.windows_nt-arm64.MIBC.Runtime" Version="1.0.0-prerelease.25458.1">
63+
<Dependency Name="optimization.windows_nt-arm64.MIBC.Runtime" Version="1.0.0-prerelease.25467.1">
6464
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
65-
<Sha>373ed5bf1a64c212e655063e58967eb62f9187ef</Sha>
65+
<Sha>59dc6a9bf1b3e3ab71c73d94160c2049fb104cd1</Sha>
6666
</Dependency>
67-
<Dependency Name="optimization.linux-arm64.MIBC.Runtime" Version="1.0.0-prerelease.25458.1">
67+
<Dependency Name="optimization.linux-arm64.MIBC.Runtime" Version="1.0.0-prerelease.25467.1">
6868
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
69-
<Sha>373ed5bf1a64c212e655063e58967eb62f9187ef</Sha>
69+
<Sha>59dc6a9bf1b3e3ab71c73d94160c2049fb104cd1</Sha>
7070
</Dependency>
7171
</ToolsetDependencies>
7272
</Dependencies>

src/Compiler/Checking/CheckDeclarations.fs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,11 +4250,9 @@ module TcDeclarations =
42504250
// a) For interfaces, only if it is in the original defn.
42514251
// Augmentations to interfaces via partial type defns will always be extensions, e.g. extension members on interfaces.
42524252
// b) For other types, if the type is isInSameModuleOrNamespace
4253-
let declKind, typars =
4254-
if isAtOriginalTyconDefn then
4255-
ModuleOrMemberBinding, reqTypars
4256-
4257-
else
4253+
if isAtOriginalTyconDefn then
4254+
ModuleOrMemberBinding, tcref, reqTypars
4255+
else
42584256
let isInSameModuleOrNamespace =
42594257
match envForDecls.eModuleOrNamespaceTypeAccumulator.Value.TypesByMangledName.TryGetValue tcref.LogicalName with
42604258
| true, tycon -> tyconOrder.Compare(tcref.Deref, tycon) = 0
@@ -4270,25 +4268,24 @@ module TcDeclarations =
42704268
let _tpenv = TcTyparConstraints cenv NoNewTypars CheckCxs ItemOccurrence.UseInType envForTycon emptyUnscopedTyparEnv synTyparCxs
42714269
declaredTypars |> List.iter (SetTyparRigid envForDecls.DisplayEnv m)
42724270

4273-
if isInSameModuleOrNamespace && not isInterfaceOrDelegateOrEnum then
4271+
if tcref.TypeAbbrev.IsSome then
4272+
ExtrinsicExtensionBinding, tcref, declaredTypars
4273+
elif isInSameModuleOrNamespace && not isInterfaceOrDelegateOrEnum then
42744274
// For historical reasons we only give a warning for incorrect type parameters on intrinsic extensions
42754275
if nReqTypars <> synTypars.Length then
42764276
errorR(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))
42774277
if not (typarsAEquiv g (TypeEquivEnv.EmptyWithNullChecks g) reqTypars declaredTypars) then
42784278
warning(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))
42794279
// Note we return 'reqTypars' for intrinsic extensions since we may only have given warnings
4280-
IntrinsicExtensionBinding, reqTypars
4280+
IntrinsicExtensionBinding, tcref, reqTypars
42814281
else
42824282
if isInSameModuleOrNamespace && isDelegateOrEnum then
42834283
errorR(Error(FSComp.SR.tcMembersThatExtendInterfaceMustBePlacedInSeparateModule(), tcref.Range))
42844284
if nReqTypars <> synTypars.Length then
42854285
error(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))
42864286
if not (typarsAEquiv g (TypeEquivEnv.EmptyWithNullChecks g) reqTypars declaredTypars) then
42874287
errorR(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))
4288-
ExtrinsicExtensionBinding, declaredTypars
4289-
4290-
4291-
declKind, tcref, typars
4288+
ExtrinsicExtensionBinding, tcref, declaredTypars
42924289

42934290

42944291
let private isAugmentationTyconDefnRepr = function SynTypeDefnSimpleRepr.General(kind=SynTypeDefnKind.Augmentation _) -> true | _ -> false

src/Compiler/Utilities/range.fs

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open System
77
open System.IO
88
open System.Collections.Concurrent
99
open System.Collections.Generic
10+
open System.Text
1011
open Microsoft.FSharp.Core.Printf
1112
open Internal.Utilities.Library
1213
open Internal.Utilities.Library.Extras.Bits
@@ -261,6 +262,9 @@ module FileIndex =
261262
let startupFileName = "startup"
262263
let commandLineArgsFileName = "commandLineArgs"
263264

265+
let mutable testSources: ConcurrentDictionary<string, string> =
266+
ConcurrentDictionary()
267+
264268
[<RequireQualifiedAccess>]
265269
module internal LineDirectives =
266270

@@ -329,6 +333,9 @@ type Range(code1: int64, code2: int64) =
329333

330334
member m.FileName = fileOfFileIndex m.FileIndex
331335

336+
member internal m.ShortFileName =
337+
Path.GetFileName(fileOfFileIndex m.FileIndex) |> nonNull
338+
332339
member m.ApplyLineDirectives() =
333340
match LineDirectives.store.TryFind m.FileIndex with
334341
| None -> m
@@ -376,32 +383,42 @@ type Range(code1: int64, code2: int64) =
376383
member _.Code2 = code2
377384

378385
member m.DebugCode =
379-
let name = m.FileName
386+
let getRangeSubstring (m: range) (stream: Stream) =
387+
let endCol = m.EndColumn - 1
388+
let startCol = m.StartColumn - 1
389+
390+
stream.ReadLines()
391+
|> Seq.skip (m.StartLine - 1)
392+
|> Seq.take (m.EndLine - m.StartLine + 1)
393+
|> String.concat "\n"
394+
|> fun s -> s.Substring(startCol + 1, s.LastIndexOf("\n", StringComparison.Ordinal) + 1 - startCol + endCol)
395+
396+
match testSources.TryGetValue(m.FileName) with
397+
| true, source ->
398+
use stream = new MemoryStream(Encoding.UTF8.GetBytes(source + "\n"))
399+
getRangeSubstring m stream
400+
| _ ->
380401

381-
if
382-
name = unknownFileName
383-
|| name = startupFileName
384-
|| name = commandLineArgsFileName
385-
then
386-
name
387-
else
402+
let name = m.FileName
388403

389-
try
390-
let endCol = m.EndColumn - 1
391-
let startCol = m.StartColumn - 1
404+
if
405+
name = unknownFileName
406+
|| name = startupFileName
407+
|| name = commandLineArgsFileName
408+
then
409+
name
410+
else
392411

393-
if FileSystem.IsInvalidPathShim m.FileName then
394-
"path invalid: " + m.FileName
395-
elif not (FileSystem.FileExistsShim m.FileName) then
396-
"nonexistent file: " + m.FileName
397-
else
398-
FileSystem.OpenFileForReadShim(m.FileName).ReadLines()
399-
|> Seq.skip (m.StartLine - 1)
400-
|> Seq.take (m.EndLine - m.StartLine + 1)
401-
|> String.concat "\n"
402-
|> fun s -> s.Substring(startCol + 1, s.LastIndexOf("\n", StringComparison.Ordinal) + 1 - startCol + endCol)
403-
with e ->
404-
e.ToString()
412+
try
413+
if FileSystem.IsInvalidPathShim m.FileName then
414+
"path invalid: " + m.FileName
415+
elif not (FileSystem.FileExistsShim m.FileName) then
416+
"nonexistent file: " + m.FileName
417+
else
418+
use stream = FileSystem.OpenFileForReadShim(m.FileName)
419+
getRangeSubstring m stream
420+
with e ->
421+
e.ToString()
405422

406423
member _.Equals(m2: range) =
407424
let code2 = code2 &&& ~~~(debugPointKindMask ||| isSyntheticMask)
@@ -613,3 +630,6 @@ module Range =
613630
| None -> mkRange file (mkPos 1 0) (mkPos 1 80)
614631
with _ ->
615632
mkRange file (mkPos 1 0) (mkPos 1 80)
633+
634+
let internal setTestSource path (source: string) =
635+
testSources.GetOrAdd(path, source) |> ignore

src/Compiler/Utilities/range.fsi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ type Range =
100100
/// The file index for the range
101101
member internal FileIndex: int
102102

103+
member internal DebugCode: string
104+
103105
/// The file name for the file of the range
104106
member FileName: string
105-
107+
108+
member internal ShortFileName: string
109+
106110
/// Apply the line directives to the range.
107111
member ApplyLineDirectives: unit -> range
108112

@@ -272,6 +276,8 @@ module Range =
272276
/// Equality comparer for range.
273277
val comparer: IEqualityComparer<range>
274278

279+
val internal setTestSource: path: string -> source: string -> unit
280+
275281
/// Functions related to converting between lines indexed at 0 and 1
276282
module Line =
277283

tests/AheadOfTime/Trimming/check.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ CheckTrim -root "SelfContained_Trimming_Test" -tfm "net9.0" -outputfile "FSharp.
5858
CheckTrim -root "StaticLinkedFSharpCore_Trimming_Test" -tfm "net9.0" -outputfile "StaticLinkedFSharpCore_Trimming_Test.dll" -expected_len 9154048
5959

6060
# Check net9.0 trimmed assemblies with F# metadata resources removed
61-
CheckTrim -root "FSharpMetadataResource_Trimming_Test" -tfm "net9.0" -outputfile "FSharpMetadataResource_Trimming_Test.dll" -expected_len 7607296
61+
CheckTrim -root "FSharpMetadataResource_Trimming_Test" -tfm "net9.0" -outputfile "FSharpMetadataResource_Trimming_Test.dll" -expected_len 7607296
6262

tests/FSharp.Compiler.ComponentTests/ErrorMessages/AbbreviationTests.fs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ type FloatAlias with
5454
(Error 909, Line 6, Col 15, Line 6, Col 34, "All implemented interfaces should be declared on the initial declaration of the type")
5555
]
5656

57+
[<Fact>]
58+
let ``Members 04 - Error in expr`` () =
59+
Fsx """
60+
type StringAlias = string
61+
62+
type StringAlias with
63+
member x.Length = x.Length + ""
64+
"""
65+
|> typecheck
66+
|> shouldFail
67+
|> withDiagnostics [
68+
(Error 964, Line 4, Col 6, Line 4, Col 17, "Type abbreviations cannot have augmentations")
69+
(Error 895, Line 5, Col 5, Line 5, Col 36, "Type abbreviations cannot have members")
70+
(Error 1, Line 5, Col 34, Line 5, Col 36, "The type 'string' does not match the type 'int'")
71+
(Error 43, Line 5, Col 32, Line 5, Col 33, "The type 'string' does not match the type 'int'")
72+
]
73+
5774
[<Fact>]
5875
let ``Multiple types 01`` () =
5976
Fsx """

tests/FSharp.Compiler.Service.Tests/Common.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,14 @@ let mkTestFileAndOptions additionalArgs =
141141
fileName, options
142142

143143
let parseAndCheckFile fileName source options =
144+
Range.setTestSource fileName source
145+
144146
match checker.ParseAndCheckFileInProject(fileName, 0, SourceText.ofString source, options) |> Async.RunImmediate with
145147
| parseResults, FSharpCheckFileAnswer.Succeeded(checkResults) -> parseResults, checkResults
146148
| _ -> failwithf "Parsing aborted unexpectedly..."
147149

148150
let parseAndCheckScriptWithOptions (file:string, input, opts) =
151+
Range.setTestSource file input
149152

150153
#if NETCOREAPP
151154
let projectOptions =
@@ -194,6 +197,7 @@ let parseSourceCode (name: string, code: string) =
194197
let args = mkProjectCommandLineArgs(dllPath, [filePath])
195198
let options, _errors = checker.GetParsingOptionsFromCommandLineArgs(List.ofArray args)
196199
let parseResults = checker.ParseFile(filePath, SourceText.ofString code, options) |> Async.RunImmediate
200+
Range.setTestSource filePath code
197201
parseResults.ParseTree
198202

199203
let matchBraces (name: string, code: string) =

tests/FSharp.Test.Utilities/Compiler.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ module rec Compiler =
368368
let loadSourceFromFile path = getSource(TestType.Path path)
369369

370370
let fsFromString (source: SourceCodeFileKind): FSharpCompilationSource =
371+
source.GetSourceText |> Option.iter (Range.setTestSource source.GetSourceFileName)
372+
371373
{
372374
Source = source
373375
AdditionalSources = []
@@ -1308,7 +1310,7 @@ Actual:
13081310
/// After compile, rebuild and print FSharpDiagnostic[] exactly as before,
13091311
/// then diff against your existing .err.bsl files (few lines will shift).
13101312
let verifyBaseline (cResult: CompilationResult) : CompilationResult =
1311-
// 1) Grab the ErrorInfo list from the compile result…
1313+
// 1) Grab the ErrorInfo list from the compilation result
13121314
let errorInfos =
13131315
match cResult with
13141316
| CompilationResult.Success o

0 commit comments

Comments
 (0)