Skip to content

Commit

Permalink
Merge pull request #17617 from dotnet/merges/main-to-release/dev17.12
Browse files Browse the repository at this point in the history
  • Loading branch information
vzarytovskii authored Aug 27, 2024
2 parents 2b02b7d + 309b42c commit a5feb41
Show file tree
Hide file tree
Showing 22 changed files with 331 additions and 30 deletions.
8 changes: 6 additions & 2 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Because this repository uses squash/rebase merges, commits added to a branch
# referencing earlier commits in the same branch and squash/rebased merged as part of a PR
# will need to be rewritten in a subsequent PR to the corresponding squashed/rebased commit SHAs.

# Format src/Compiler/Checking/CheckComputationExpressions.fs, https://github.com/dotnet/fsharp/pull/16512
603a310cdfd9902ec1d29b399377dcc9ac56235b
0318afd91f38533879cc89d598e0431c312ad57e

# Spelling, https://github.com/dotnet/fsharp/pull/16212
823d5e99fdd13f696ea8fe572d502e5fa68f6fd1
23e91e1322363a7e9c34baaeabbf0391c4b7eafd
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<RepoRoot Condition="'$(RepoRoot)' == ''">$(MSBuildThisFileDirectory)</RepoRoot>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<FSharpNetCoreProductDefaultTargetFramework>net9.0</FSharpNetCoreProductDefaultTargetFramework>
<IgnoreMibc Condition="'$(IgnoreMibc)' == ''">$(DotNetBuildFromSource)</IgnoreMibc>
</PropertyGroup>

<!--
Expand Down
15 changes: 15 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,19 @@
</KnownCrossgen2Pack>
</ItemGroup>

<!-- We want to restore ALL the MIBCs when we build anything, since in the future it will contain different profiles, not only the FSC one we got from building Giraffe -->
<Import Project="$(MSBuildThisFileDirectory)\eng\restore\optimizationData.targets"/>
<ItemGroup>
<PackageReference Include="@(MIBCPackage)" />
</ItemGroup>

<Target Name="CopyMIBCWrapper" AfterTargets="Restore" BeforeTargets="Build;Pack">
<MSBuild
Projects="$(MSBuildThisFileDirectory)eng\restore\optimizationData.targets"
Properties="ArtifactsDir=$(MSBuildThisFileDirectory)artifacts\;NuGetPackageRoot=$(NuGetPackageRoot);MibcFiles=$(MibcFiles);optimizationwindows_ntx86MIBCRuntimeVersion=$(optimizationwindows_ntx86MIBCRuntimeVersion);optimizationwindows_ntx64MIBCRuntimeVersion=$(optimizationwindows_ntx64MIBCRuntimeVersion);optimizationwindows_ntarm64MIBCRuntimeVersion=$(optimizationwindows_ntarm64MIBCRuntimeVersion);optimizationlinuxx64MIBCRuntimeVersion=$(optimizationlinuxx64MIBCRuntimeVersion);optimizationlinuxarm64MIBCRuntimeVersion=$(optimizationlinuxarm64MIBCRuntimeVersion)"
Targets="CopyMIBC"
RemoveProperties="TargetFramework"
StopOnFirstFailure="True" />
</Target>

</Project>
27 changes: 27 additions & 0 deletions eng/restore/optimizationData.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project>
<!-- We want to restore ALL the MIBCs when we build anything, since in the future it will contain different profiles, not only the FSC one we got from building Giraffe -->
<ItemGroup Condition="'$(IgnoreMIBC)' != 'true'">
<MIBCPackage Include="optimization.windows_nt-x86.mibc.runtime" Version="$(optimizationwindows_ntx86MIBCRuntimeVersion)" />
<MIBCPackage Include="optimization.windows_nt-x64.mibc.runtime" Version="$(optimizationwindows_ntx64MIBCRuntimeVersion)" />
<MIBCPackage Include="optimization.windows_nt-arm64.mibc.runtime" Version="$(optimizationwindows_ntarm64MIBCRuntimeVersion)" />
<MIBCPackage Include="optimization.linux-x64.mibc.runtime" Version="$(optimizationlinuxx64MIBCRuntimeVersion)" />
<MIBCPackage Include="optimization.linux-arm64.mibc.runtime" Version="$(optimizationlinuxarm64MIBCRuntimeVersion)" />
</ItemGroup>

<!-- We copy all packages to the output (per architecture) -->
<Target Name="CopyMIBC">
<ItemGroup>
<MibcFiles Include="$(NuGetPackageRoot)%(MibcPackage.Identity)\%(MibcPackage.Version)\**\DotNet_FSharp.mibc" />
</ItemGroup>

<Copy
SourceFiles="@(MibcFiles)"
DestinationFolder="$(ArtifactsDir)mibc\%(MibcPackage.Identity)\"
SkipUnchangedFiles="true" />

<Copy
SourceFiles="@(MibcFiles)"
DestinationFolder="$(ArtifactsDir)mibc-proto\%(MibcPackage.Identity)\"
SkipUnchangedFiles="true" />
</Target>
</Project>
4 changes: 4 additions & 0 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2856,12 +2856,16 @@ module EstablishTypeDefinitionCores =
let hasStructAttr = HasFSharpAttribute g g.attrib_StructAttribute attrs
let hasCLIMutable = HasFSharpAttribute g g.attrib_CLIMutableAttribute attrs
let hasAllowNullLiteralAttr = HasFSharpAttribute g g.attrib_AllowNullLiteralAttribute attrs
let hasSealedAttr = HasFSharpAttribute g g.attrib_SealedAttribute attrs
let structLayoutAttr = HasFSharpAttribute g g.attrib_StructLayoutAttribute attrs

// We want to keep these special attributes treatment and avoid having two errors for the same attribute.
let reportAttributeTargetsErrors =
g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets)
&& not hasCLIMutable // CLIMutableAttribute has a special treatment(specific error FS3132)
&& not hasAllowNullLiteralAttr // AllowNullLiteralAttribute has a special treatment(specific errors FS0934, FS093)
&& not hasSealedAttr // SealedAttribute has a special treatment(specific error FS942)
&& not structLayoutAttr // StructLayoutAttribute has a special treatment(specific error FS0937)

let noCLIMutableAttributeCheck() =
if hasCLIMutable then errorR (Error(FSComp.SR.tcThisTypeMayNotHaveACLIMutableAttribute(), m))
Expand Down
8 changes: 6 additions & 2 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11086,7 +11086,11 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
if not (isNil declaredTypars) then
errorR(Error(FSComp.SR.tcLiteralCannotHaveGenericParameters(), mBinding))

if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) && memberFlagsOpt.IsNone && not attrs.IsEmpty then
let supportEnforceAttributeTargets =
(g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) && memberFlagsOpt.IsNone && not attrs.IsEmpty)
&& not isVolatile // // VolatileFieldAttribute has a special treatment(specific error FS823)

if supportEnforceAttributeTargets then
TcAttributeTargetsOnLetBindings { cenv with tcSink = TcResultsSink.NoSink } env attrs overallPatTy overallExprTy (not declaredTypars.IsEmpty) isClassLetBinding

CheckedBindingInfo(inlineFlag, valAttribs, xmlDoc, tcPatPhase2, explicitTyparInfo, nameToPrelimValSchemeMap, rhsExprChecked, argAndRetAttribs, overallPatTy, mBinding, debugPoint, isCompGen, literalValue, isFixed), tpenv
Expand Down Expand Up @@ -11114,7 +11118,7 @@ and TcAttributeTargetsOnLetBindings (cenv: cenv) env attrs overallPatTy overallE
else
AttributeTargets.ReturnValue ||| AttributeTargets.Field ||| AttributeTargets.Property

TcAttributes cenv env attrTgt attrs |> ignore
TcAttributesWithPossibleTargets false cenv env attrTgt attrs |> ignore

and TcLiteral (cenv: cenv) overallTy env tpenv (attrs, synLiteralValExpr) =

Expand Down
61 changes: 57 additions & 4 deletions src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2044,14 +2044,15 @@ type FormattedDiagnosticDetailedInfo =
Location: FormattedDiagnosticLocation option
Canonical: FormattedDiagnosticCanonicalInformation
Message: string
Context: string option
}

[<RequireQualifiedAccess>]
type FormattedDiagnostic =
| Short of FSharpDiagnosticSeverity * string
| Long of FSharpDiagnosticSeverity * FormattedDiagnosticDetailedInfo

let FormatDiagnosticLocation (tcConfig: TcConfig) m : FormattedDiagnosticLocation =
let FormatDiagnosticLocation (tcConfig: TcConfig) (m: Range) : FormattedDiagnosticLocation =
if equals m rangeStartup || equals m rangeCmdArgs then
{
Range = m
Expand Down Expand Up @@ -2114,6 +2115,10 @@ let FormatDiagnosticLocation (tcConfig: TcConfig) m : FormattedDiagnosticLocatio
sprintf "%s(%d,%d,%d,%d): " file m.StartLine m.StartColumn m.EndLine m.EndColumn, m, file
else
"", m, file
| DiagnosticStyle.Rich ->
let file = file.Replace('/', Path.DirectorySeparatorChar)
let m = withStart (mkPos m.StartLine (m.StartColumn + 1)) m
(sprintf "◦→ %s (%d,%d)" file m.StartLine m.StartColumn), m, file

{
Range = m
Expand Down Expand Up @@ -2154,8 +2159,12 @@ let CollectFormattedDiagnostics (tcConfig: TcConfig, severity: FSharpDiagnosticS
let text =
match tcConfig.diagnosticStyle with
// Show the subcategory for --vserrors so that we can fish it out in Visual Studio and use it to determine error stickiness.
| DiagnosticStyle.Emacs
| DiagnosticStyle.Gcc
| DiagnosticStyle.Default
| DiagnosticStyle.Test -> sprintf "%s FS%04d: " message errorNumber
| DiagnosticStyle.VisualStudio -> sprintf "%s %s FS%04d: " subcategory message errorNumber
| _ -> sprintf "%s FS%04d: " message errorNumber
| DiagnosticStyle.Rich -> sprintf "\n◦→ %s FS%04d: " message errorNumber

let canonical: FormattedDiagnosticCanonicalInformation =
{
Expand All @@ -2164,11 +2173,51 @@ let CollectFormattedDiagnostics (tcConfig: TcConfig, severity: FSharpDiagnosticS
TextRepresentation = text
}

let message = diagnostic.FormatCore(tcConfig.flatErrors, suggestNames)
let message =
match tcConfig.diagnosticStyle with
| DiagnosticStyle.Emacs
| DiagnosticStyle.Gcc
| DiagnosticStyle.Default
| DiagnosticStyle.Test
| DiagnosticStyle.VisualStudio -> diagnostic.FormatCore(tcConfig.flatErrors, suggestNames)
| DiagnosticStyle.Rich ->
diagnostic.FormatCore(tcConfig.flatErrors, suggestNames).Split([| '\n' |])
|> Array.map (fun msg -> "\n" + msg)
|> String.Concat

let context =
match tcConfig.diagnosticStyle with
| DiagnosticStyle.Emacs
| DiagnosticStyle.Gcc
| DiagnosticStyle.Default
| DiagnosticStyle.Test
| DiagnosticStyle.VisualStudio -> None
| DiagnosticStyle.Rich ->
match diagnostic.Range with
| Some m ->
let content =
m.FileName
|> FileSystem.GetFullFilePathInDirectoryShim tcConfig.implicitIncludeDir
|> System.IO.File.ReadAllLines

if m.StartLine = m.EndLine then
$"\n◦ {m.StartLine} |{content[m.StartLine - 1]}\n"
+ $"""◦ {String.init (m.StartColumn + 3) (fun _ -> " ")}^{String.init (m.EndColumn - m.StartColumn) (fun _ -> "~")}"""
|> Some
else
content
|> fun lines -> Array.sub lines (m.StartLine - 1) (m.EndLine - m.StartLine - 1)
|> Array.fold
(fun (context, lineNumber) line -> (context + $"\n◦ {lineNumber} |{line}", lineNumber + 1))
("", (m.StartLine))
|> fst
|> Some
| None -> None

let entry: FormattedDiagnosticDetailedInfo =
{
Location = where
Context = context
Canonical = canonical
Message = message
}
Expand Down Expand Up @@ -2199,7 +2248,11 @@ type PhasedDiagnostic with
| FormattedDiagnostic.Short(_, txt) -> buf.AppendString txt
| FormattedDiagnostic.Long(_, details) ->
match details.Location with
| Some l when not l.IsEmpty -> buf.AppendString l.TextRepresentation
| Some l when not l.IsEmpty ->
buf.AppendString l.TextRepresentation
// Because details.Context depends on the value of details.Location, if details.Location is not None, details.Context can be accessed directly.
if details.Context.IsSome then
buf.AppendString details.Context.Value
| _ -> ()

buf.AppendString details.Canonical.TextRepresentation
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Driver/CompilerDiagnostics.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ type FormattedDiagnosticCanonicalInformation =
type FormattedDiagnosticDetailedInfo =
{ Location: FormattedDiagnosticLocation option
Canonical: FormattedDiagnosticCanonicalInformation
Message: string }
Message: string
Context: string option }

/// Used internally and in LegacyHostedCompilerForTesting
[<RequireQualifiedAccess>]
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Facilities/DiagnosticsLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ open Internal.Utilities.Library.Extras
open System.Threading.Tasks

/// Represents the style being used to format errors
[<RequireQualifiedAccess>]
[<RequireQualifiedAccess; NoComparison; NoEquality>]
type DiagnosticStyle =
| Default
| Emacs
| Test
| VisualStudio
| Gcc
| Rich

/// Thrown when we want to add some range information to a .NET exception
exception WrappedError of exn * range with
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Facilities/DiagnosticsLogger.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ open System.Runtime.CompilerServices
open System.Runtime.InteropServices

/// Represents the style being used to format errors
[<RequireQualifiedAccess>]
[<RequireQualifiedAccess; NoComparison; NoEquality>]
type DiagnosticStyle =
| Default
| Emacs
| Test
| VisualStudio
| Gcc
| Rich

/// Thrown when we want to add some range information to a .NET exception
exception WrappedError of exn * range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<NuspecProperty Include="configuration=$(Configuration)" />
</ItemGroup>

<ItemGroup Condition="'$(IgnoreMibc)' != 'true'">
<NuspecProperty Include="mibcRoot=$(ArtifactsDir)\mibc" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)..\fsi\fsiProject\fsi.fsproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\fsc\fscProject\fsc.fsproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<file src="FSharp.Build\$configuration$\netstandard2.0\Microsoft.FSharp.NetSdk.targets" target="contentFiles\any\any" />
<file src="FSharp.Build\$configuration$\netstandard2.0\Microsoft.FSharp.Overrides.NetSdk.targets" target="contentFiles\any\any" />

<!-- PGO, MIBC -->
<file src="$mibcRoot$\**\*.mibc" target="contentFiles\mibc" />

<!-- resources -->
<file src="FSharp.Core\$configuration$\netstandard2.0\**\FSharp.Core.resources.dll"
target="lib\$fSharpNetCoreProductTargetFramework$" />
Expand Down
13 changes: 13 additions & 0 deletions src/fsc/fscProject/fsc.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Proto'">
<MibcTargetOS>linux</MibcTargetOS>
<!-- We deliberately want to use linux mibc pgo data on macOS -->
<MibcTargetOS Condition="$([MSBuild]::IsOSPlatform('OSX'))">linux</MibcTargetOS>
<MibcTargetOS Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">windows_nt</MibcTargetOS>
<MibcTargetArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant)</MibcTargetArchitecture>
<MibcCurrentMachineArcitecture>$(MibcTargetOS)-$(MibcTargetArchitecture)</MibcCurrentMachineArcitecture>
<MibcFile>$(ArtifactsDir)mibc-proto\optimization.$(MibcCurrentMachineArcitecture).mibc.runtime\DotNet_FSharp.mibc</MibcFile>

<TargetFramework>$(FSharpNetCoreProductTargetFramework)</TargetFramework>
<PublishReadyToRun>$(EnablePublishReadyToRun)</PublishReadyToRun>
<RuntimeIdentifier>$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
<ReadyToRunOptimizationData>$(MibcFile)</ReadyToRunOptimizationData>
</PropertyGroup>

<ItemGroup Condition="'$(Configuration)' == 'Proto'">
Expand All @@ -24,6 +33,10 @@
<IntermediateOutputPath>$(ArtifactsDir)obj/$(MSBuildProjectName)/$(Configuration)/</IntermediateOutputPath>
</PropertyGroup>

<Target Name="ValidateMibcFile" AfterTargets="CopyMIBC" BeforeTargets="Build;Pack" Condition="'$(IgnoreMibc)' != 'true'">
<Error Condition="'$(Configuration)' == 'Proto' AND !Exists('$(MibcFile)')" Text="Mibc file '$(MibcFile)' does not exist." />
</Target>

<Import Project="$([MSBuild]::GetPathOfFileAbove('fsc.targets', '$(MSBuildThisFileDirectory)../'))" />

</Project>
Loading

0 comments on commit a5feb41

Please sign in to comment.