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 release/dev17.12 #17568

Merged
merged 6 commits into from
Aug 20, 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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.400.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Fix for exponential runtime in CE builders when using nested implicit yields [PR #17096](https://github.com/dotnet/fsharp/pull/17096)
* Fix several AND operator parser bugs and regressions ([Issue #16447](https://github.com/dotnet/fsharp/issues/16447), [Issue #17134](https://github.com/dotnet/fsharp/issues/17134), [Issue #16309](https://github.com/dotnet/fsharp/issues/16309), [PR #17113](https://github.com/dotnet/fsharp/pull/17113))
* Treat exceptions as types in a namespace for graph based type checking ([Issue #17262](https://github.com/dotnet/fsharp/issues/17262), [PR #17268](https://github.com/dotnet/fsharp/pull/17268))
* FS0243 - Unrecognized option: '--realsig-' #17561 ([Issue #17561](https://github.com/dotnet/fsharp/issues/17561), [PR #17268](https://github.com/dotnet/fsharp/pull/17562))

### Added

Expand Down
2 changes: 2 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
* Fix `function` implicit conversion. ([Issue #7401](https://github.com/dotnet/fsharp/issues/7401), [PR #17487](https://github.com/dotnet/fsharp/pull/17487))
* Compiler fails to recognise namespace in FQN with enabled GraphBasedChecking. ([Issue #17508](https://github.com/dotnet/fsharp/issues/17508), [PR #17510](https://github.com/dotnet/fsharp/pull/17510))
* Fix missing message for type error (FS0001). ([Issue #17373](https://github.com/dotnet/fsharp/issues/17373), [PR #17516](https://github.com/dotnet/fsharp/pull/17516))
* Nullness export - make sure option<> and other UseNullAsTrueValue types are properly annotated as nullable for C# and reflection consumers [PR #17528](https://github.com/dotnet/fsharp/pull/17528)
* MethodAccessException on equality comparison of a type private to module. ([Issue #17541](https://github.com/dotnet/fsharp/issues/17541), [PR #17548](https://github.com/dotnet/fsharp/pull/17548))
* Fixed checking failure when `global` namespace is involved with enabled GraphBasedChecking ([PR #17553](https://github.com/dotnet/fsharp/pull/17553))

### Added

Expand Down
12 changes: 6 additions & 6 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Dependencies>
<ProductDependencies>
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="9.0.0-alpha.1.24413.1">
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="10.0.0-alpha.1.24415.3">
<Uri>https://github.com/dotnet/source-build-reference-packages</Uri>
<Sha>1b838a42e4952b8fdf212cb1b43c5ce4d69f27b3</Sha>
<Sha>e9c7c7740133e6e4f92d22d0410a379a8f2d24e7</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<!-- Intermediate is necessary for source build. -->
Expand Down Expand Up @@ -42,14 +42,14 @@
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="9.0.0-beta.24408.2">
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="9.0.0-beta.24416.2">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>60ae233c3d77f11c5fdb53e570b64d503b13ba59</Sha>
<Sha>8fe02bab989df1265eee225df2c28af6dbdccc83</Sha>
</Dependency>
<!-- Intermediate is necessary for source build. -->
<Dependency Name="Microsoft.SourceBuild.Intermediate.arcade" Version="9.0.0-beta.24408.2">
<Dependency Name="Microsoft.SourceBuild.Intermediate.arcade" Version="9.0.0-beta.24416.2">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>60ae233c3d77f11c5fdb53e570b64d503b13ba59</Sha>
<Sha>8fe02bab989df1265eee225df2c28af6dbdccc83</Sha>
<SourceBuild RepoName="arcade" ManagedOnly="true" />
</Dependency>
<Dependency Name="optimization.windows_nt-x64.MIBC.Runtime" Version="1.0.0-prerelease.23614.4">
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"perl": "5.38.2.2"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.24408.2",
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.24416.2",
"Microsoft.DotNet.Helix.Sdk": "8.0.0-beta.23255.2"
}
}
17 changes: 12 additions & 5 deletions src/Compiler/CodeGen/EraseUnions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open FSharp.Compiler.IlxGenSupport
open System.Collections.Generic
open System.Reflection
open Internal.Utilities.Library
open FSharp.Compiler.TypedTree
open FSharp.Compiler.TypedTreeOps
open FSharp.Compiler.Features
open FSharp.Compiler.TcGlobals
Expand Down Expand Up @@ -955,7 +956,14 @@ let convAlternativeDef
&& g.langFeatureNullness
&& repr.RepresentAlternativeAsNull(info, alt)
then
GetNullableAttribute g [ FSharp.Compiler.TypedTree.NullnessInfo.WithNull ]
let noTypars = td.GenericParams.Length

GetNullableAttribute
g
[
yield NullnessInfo.WithNull // The top-level value itself, e.g. option, is nullable
yield! List.replicate noTypars NullnessInfo.AmbivalentToNull
] // The typars are not (i.e. do not change option<string> into option<string?>
|> Array.singleton
|> mkILCustomAttrsFromArray
else
Expand Down Expand Up @@ -1199,7 +1207,7 @@ let convAlternativeDef

let attrs =
if g.checkNullness && g.langFeatureNullness then
GetNullableContextAttribute g :: debugAttrs
GetNullableContextAttribute g 1uy :: debugAttrs
else
debugAttrs

Expand Down Expand Up @@ -1365,8 +1373,7 @@ let mkClassUnionDef
match nullableIdx with
| None ->
existingAttrs
|> Array.append
[| GetNullableAttribute g [ FSharp.Compiler.TypedTree.NullnessInfo.WithNull ] |]
|> Array.append [| GetNullableAttribute g [ NullnessInfo.WithNull ] |]
| Some idx ->
let replacementAttr =
match existingAttrs[idx] with
Expand Down Expand Up @@ -1619,7 +1626,7 @@ let mkClassUnionDef
customAttrs =
if cud.IsNullPermitted && g.checkNullness && g.langFeatureNullness then
td.CustomAttrs.AsArray()
|> Array.append [| GetNullableAttribute g [ FSharp.Compiler.TypedTree.NullnessInfo.WithNull ] |]
|> Array.append [| GetNullableAttribute g [ NullnessInfo.WithNull ] |]
|> mkILCustomAttrsFromArray
|> storeILCustomAttrs
else
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,7 @@ type TypeDefBuilder(tdef: ILTypeDef, tdefDiscards) =
if attrsBefore |> TryFindILAttribute g.attrib_AllowNullLiteralAttribute then
yield GetNullableAttribute g [ NullnessInfo.WithNull ]
if (gmethods.Count + gfields.Count + gproperties.Count) > 0 then
yield GetNullableContextAttribute g
yield GetNullableContextAttribute g 1uy
|]
|> mkILCustomAttrsFromArray
else
Expand Down
9 changes: 7 additions & 2 deletions src/Compiler/CodeGen/IlxGenSupport.fs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ let GetDynamicDependencyAttribute (g: TcGlobals) memberTypes (ilType: ILType) =
/// Nested items not being annotated with Nullable attribute themselves are interpreted as being withoutnull
/// Doing it that way is a heuristical decision supporting limited usage of (| null) annotations and not allowing nulls in >50% of F# code
/// (if majority of fields/parameters/return values would be nullable, this heuristic would lead to bloat of generated metadata)
let GetNullableContextAttribute (g: TcGlobals) =
let GetNullableContextAttribute (g: TcGlobals) flagValue =
let tref = g.attrib_NullableContextAttribute.TypeRef

g.TryEmbedILType(
Expand All @@ -329,7 +329,7 @@ let GetNullableContextAttribute (g: TcGlobals) =
mkLocalPrivateAttributeWithPropertyConstructors (g, tref.Name, fields, PublicFields))
)

mkILCustomAttribute (tref, [ g.ilg.typ_Byte ], [ ILAttribElem.Byte 1uy ], [])
mkILCustomAttribute (tref, [ g.ilg.typ_Byte ], [ ILAttribElem.Byte flagValue ], [])

let GetNotNullWhenTrueAttribute (g: TcGlobals) (propNames: string array) =
let tref = g.attrib_MemberNotNullWhenAttribute.TypeRef
Expand Down Expand Up @@ -407,6 +407,11 @@ let rec GetNullnessFromTType (g: TcGlobals) ty =
else if isValueType then
// Generic value type: 0, followed by the representation of the type arguments in order including containing types
yield NullnessInfo.AmbivalentToNull
else if
IsUnionTypeWithNullAsTrueValue g tcref.Deref
|| TypeHasAllowNull tcref g FSharp.Compiler.Text.Range.Zero
then
yield NullnessInfo.WithNull
else
// Reference type: the nullability (0, 1, or 2), followed by the representation of the type arguments in order including containing types
yield nullness.Evaluate()
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/CodeGen/IlxGenSupport.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ val GenAdditionalAttributesForTy: g: TcGlobals -> ty: TypedTree.TType -> ILAttri
val GetReadOnlyAttribute: g: TcGlobals -> ILAttribute
val GetIsUnmanagedAttribute: g: TcGlobals -> ILAttribute
val GetNullableAttribute: g: TcGlobals -> nullnessInfos: TypedTree.NullnessInfo list -> ILAttribute
val GetNullableContextAttribute: g: TcGlobals -> ILAttribute
val GetNullableContextAttribute: g: TcGlobals -> byte -> ILAttribute
val GetNotNullWhenTrueAttribute: g: TcGlobals -> string array -> ILAttribute
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ let rec processStateEntry (trie: TrieNode) (state: FileContentQueryState) (entry
FoundDependencies = foundDependencies
}

| ModuleName name ->
| FileContentEntry.ModuleName name ->
// We need to check if the module name is a hit in the Trie.
let state' =
let queryResult = queryTrie trie [ name ]
Expand Down
7 changes: 7 additions & 0 deletions src/Compiler/Driver/GraphChecking/FileContentMapping.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ type Continuations = ((FileContentEntry list -> FileContentEntry list) -> FileCo
let collectFromOption (mapping: 'T -> 'U list) (t: 'T option) : 'U list = List.collect mapping (Option.toList t)

let longIdentToPath (skipLast: bool) (longId: LongIdent) : LongIdentifier =

// We always skip the "special" `global` identifier.
let longId =
match longId with
| h :: t when h.idText = "`global`" -> t
| _ -> longId

match skipLast, longId with
| true, _ :: _ -> List.take (longId.Length - 1) longId
| _ -> longId
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Driver/GraphChecking/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type internal TrieNode =

/// A significant construct found in the syntax tree of a file.
/// This construct needs to be processed in order to deduce potential links to other files in the project.
[<RequireQualifiedAccess; NoComparison; NoEquality>]
type internal FileContentEntry =
/// Any toplevel namespace a file might have.
/// In case a file has `module X.Y.Z`, then `X.Y` is considered to be the toplevel namespace
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Driver/GraphChecking/Types.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type internal TrieNode =

/// A significant construct found in the syntax tree of a file.
/// This construct needs to be processed in order to deduce potential links to other files in the project.
[<RequireQualifiedAccess; NoComparison; NoEquality>]
type internal FileContentEntry =
/// Any toplevel namespace a file might have.
/// In case a file has `module X.Y.Z`, then `X.Y` is considered to be the toplevel namespace
Expand Down
10 changes: 6 additions & 4 deletions src/Compiler/TypedTree/TypedTreeOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9198,16 +9198,18 @@ let reqTyForArgumentNullnessInference g actualTy reqTy =
changeWithNullReqTyToVariable g reqTy
| _ -> reqTy

let TypeHasAllowNull (tcref:TyconRef) g m =
not tcref.IsStructOrEnumTycon &&
not (isByrefLikeTyconRef g m tcref) &&
(TryFindTyconRefBoolAttribute g m g.attrib_AllowNullLiteralAttribute tcref = Some true)

/// The new logic about whether a type admits the use of 'null' as a value.
let TypeNullIsExtraValueNew g m ty =
let sty = stripTyparEqns ty

// Check if the type has AllowNullLiteral
(match tryTcrefOfAppTy g sty with
| ValueSome tcref ->
not tcref.IsStructOrEnumTycon &&
not (isByrefLikeTyconRef g m tcref) &&
(TryFindTyconRefBoolAttribute g m g.attrib_AllowNullLiteralAttribute tcref = Some true)
| ValueSome tcref -> TypeHasAllowNull tcref g m
| _ -> false)
||
// Check if the type has a nullness annotation
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/TypedTree/TypedTreeOps.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,8 @@ val TypeNullIsTrueValue: TcGlobals -> TType -> bool

val TypeNullIsExtraValue: TcGlobals -> range -> TType -> bool

val TypeHasAllowNull: TyconRef -> TcGlobals -> range -> bool

val TypeNullIsExtraValueNew: TcGlobals -> range -> TType -> bool

val TypeNullNever: TcGlobals -> TType -> bool
Expand Down
17 changes: 10 additions & 7 deletions src/FSharp.Build/Fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type public Fsc() as this =
let mutable preferredUILang: string MaybeNull = null
let mutable publicSign: bool = false
let mutable provideCommandLineArgs: bool = false
let mutable realsig: bool = true
let mutable realsig: bool option = None
let mutable references: ITaskItem[] = [||]
let mutable referencePath: string MaybeNull = null
let mutable refOnly: bool = false
Expand Down Expand Up @@ -197,10 +197,10 @@ type public Fsc() as this =
builder.AppendSwitch("--optimize-")

// realsig
if realsig then
builder.AppendSwitch("--realsig+")
else
builder.AppendSwitch("--realsig-")
match realsig with
| Some true -> builder.AppendSwitch("--realsig+")
| Some false -> builder.AppendSwitch("--realsig-")
| None -> ()

// Tailcalls
if not tailcalls then
Expand Down Expand Up @@ -544,8 +544,11 @@ type public Fsc() as this =

// --realsig[+-]
member _.RealSig
with get () = realsig
and set (b) = realsig <- b
with get () =
match realsig with
| Some true -> true
| _ -> false
and set (b) = realsig <- Some b

// -r <string>: Reference an F# or .NET assembly.
member _.References
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags,
int32) = ( 01 00 08 00 00 00 00 00 00 00 00 00 )
.param [0]
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 )
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 02 00 00 00 )

.maxstack 8
IL_0000: ldnull
Expand Down Expand Up @@ -188,7 +188,7 @@
.property class TestModule/MyNullableOption`1<!T>
MyNone()
{
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 )
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 02 00 00 00 )
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
Expand Down Expand Up @@ -266,7 +266,7 @@
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags,
int32) = ( 01 00 08 00 00 00 00 00 00 00 00 00 )
.param [0]
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 )
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 02 00 00 00 )

.maxstack 8
IL_0000: ldnull
Expand Down Expand Up @@ -382,7 +382,7 @@
.property class TestModule/MyOptionWhichCannotHaveNullInTheInside`1<!T>
MyNotNullNone()
{
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 )
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 02 00 00 00 )
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
Expand Down Expand Up @@ -422,6 +422,10 @@
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 )
.param type b
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 )
.param [0]
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 02 01 00 00 )
.param [2]
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 02 01 00 00 )

.maxstack 4
.locals init (class TestModule/MyNullableOption`1<!!a> V_0,
Expand Down Expand Up @@ -458,6 +462,10 @@
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 )
.param type b
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 )
.param [0]
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 02 01 00 00 )
.param [2]
.custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 02 01 00 00 )

.maxstack 4
.locals init (class TestModule/MyOptionWhichCannotHaveNullInTheInside`1<!!a> V_0,
Expand Down
Loading
Loading