Skip to content

Commit

Permalink
[RFC FS-1060] Nullness checking (#15181)
Browse files Browse the repository at this point in the history
* squash

* squash

* move adhoc tests and clean errors

* fix up constraint solving and adhoc testing

* remove tests

* fantomas

* skip fails

* fix tests

* fix up test baselines for change in order in checking

* update tests

* don't overwrite baselines

* fix some test failures

* skip warnings

* skip warnings

* fix warning logic

* fix tests

* fix sizes

* fix build

* fantomas and validation update

* corrections to self-use

* [WIP] [RFC FS-1060] Nullness checking (applied to codebase) (#15265)

* enablement

* enablement

* fix build

* fix build

* fantomas

* selective adoption

* Revert "[WIP] [RFC FS-1060] Nullness checking (applied to codebase) (#15265)" (#15309)

This reverts commit 559c058.

* Fixes

* Feature/nullness - parsing of constraints (#15753)

* Feature/nullness - parsing of constraints for:
'T: not null ....  syntax in Type argument specification
appType | NULL ...  for specifying types

* applying changed syntax

* positive.fs updated

* positive.fs paranthesis

* fixing "parse warning Remove spaces between the type name and type parameter, e.g. "C<'T>", not "C <'T>". Type parameters must be placed directly adjacent to the type name."

* positive .bsl updated

* Please mighty fantomas

* Feature nullness metadata export (#15981)

* fix merge mistake

* fix build

* fantomas

* bsl fix

* il tests update

* fix test

* tests fixed

* fantomas

* fix tests

* trim test

* trimming test

* trim check

* now?

* IL tests

* il tests

* trim test

* trim

* one more time

* Merge main to feature/nullness (#16366)

* Fixes #16359 - correctly handle imports with 0 length public key tokens (#16363)

* Parser: recover on unfinished record decls, fix field ranges (#16357)

* Parser: recover on unfinished record decls, fix field ranges

* Fantomas

* Better diagnostic ranges for fields

* More parser tests

* Update surface area

* Fix xml doc test

* Update baselines

* Update src/Compiler/SyntaxTree/SyntaxTree.fsi

Co-authored-by: Edgar Gonzalez <[email protected]>

* Add MutableKeyword to SynFieldTrivia. (#11)

* Simplify

* Fantomas

---------

Co-authored-by: Edgar Gonzalez <[email protected]>
Co-authored-by: Florian Verdonck <[email protected]>

---------

Co-authored-by: Kevin Ransom (msft) <[email protected]>
Co-authored-by: Eugene Auduchinok <[email protected]>
Co-authored-by: Edgar Gonzalez <[email protected]>
Co-authored-by: Florian Verdonck <[email protected]>
Co-authored-by: Tomas Grosup <[email protected]>

* syntax tree layout

* Nullness-related aggressive trimming of FSharp.Core (#16387)

* Merge main to feature/nullness (#16397)

* [main] Update dependencies from dnceng/internal/dotnet-optimization (#16150)

* Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-optimization build 20231019.5

optimization.linux-arm64.MIBC.Runtime , optimization.linux-x64.MIBC.Runtime , optimization.windows_nt-arm64.MIBC.Runtime , optimization.windows_nt-x64.MIBC.Runtime , optimization.windows_nt-x86.MIBC.Runtime
 From Version 1.0.0-prerelease.23515.2 -> To Version 1.0.0-prerelease.23519.5

* Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-optimization build 20231019.5

optimization.linux-arm64.MIBC.Runtime , optimization.linux-x64.MIBC.Runtime , optimization.windows_nt-arm64.MIBC.Runtime , optimization.windows_nt-x64.MIBC.Runtime , optimization.windows_nt-x86.MIBC.Runtime
 From Version 1.0.0-prerelease.23515.2 -> To Version 1.0.0-prerelease.23519.5

* Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-optimization build 20231021.3

optimization.linux-arm64.MIBC.Runtime , optimization.linux-x64.MIBC.Runtime , optimization.windows_nt-arm64.MIBC.Runtime , optimization.windows_nt-x64.MIBC.Runtime , optimization.windows_nt-x86.MIBC.Runtime
 From Version 1.0.0-prerelease.23515.2 -> To Version 1.0.0-prerelease.23521.3

* Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-optimization build 20231021.3

optimization.linux-arm64.MIBC.Runtime , optimization.linux-x64.MIBC.Runtime , optimization.windows_nt-arm64.MIBC.Runtime , optimization.windows_nt-x64.MIBC.Runtime , optimization.windows_nt-x86.MIBC.Runtime
 From Version 1.0.0-prerelease.23515.2 -> To Version 1.0.0-prerelease.23521.3

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>

* [main] Update dependencies from dotnet/arcade (#16241)

* Update dependencies from https://github.com/dotnet/arcade build 20231106.5

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23556.5

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231106.5

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23556.5

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231106.5

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23556.5

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231106.5

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23556.5

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231106.5

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23556.5

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231106.5

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23556.5

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231106.5

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23556.5

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231114.4

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23564.4

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231130.1

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23580.1

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231130.1

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23580.1

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231130.1

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23580.1

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231130.1

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23580.1

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

* Update dependencies from https://github.com/dotnet/arcade build 20231130.1

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.23463.1 -> To Version 8.0.0-beta.23580.1

Dependency coherency updates

Microsoft.DotNet.XliffTasks
 From Version 1.0.0-beta.23426.1 -> To Version 1.0.0-beta.23475.1 (parent: Microsoft.DotNet.Arcade.Sdk

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Vlad Zarytovskii <[email protected]>
Co-authored-by: Tomas Grosup <[email protected]>

* Name resolution: don't search extension members in type abbreviations (#16390)

* Name resolution: don't search extension members in type abbreviations

* Add test

* Revert "[main] Update dependencies from dotnet/arcade (#16241)" (#16396)

This reverts commit f219a99.

* trimmed size updated

---------

Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Vlad Zarytovskii <[email protected]>
Co-authored-by: Tomas Grosup <[email protected]>
Co-authored-by: Eugene Auduchinok <[email protected]>

* Nullness interop - import of C#-emitted metadata (#16423)

* Nullness - include in QuickInfo and in general in "typeEnc" (string representation of a type) (#16555)

* failing test

* todo for IL import

* explanation added

* il meta parsing

* flags evaluation

* you shall passs

* evaluateFirstOrderNullnessAndAdvance

* import il type with nullness

* type import

* IL nullness import

fields, props, events, method args, method return types - nullness imported from IL

* test rename

* fantomas

* get stack trace on error

* split ilmethod's type

* fix crashes for Csharp style extensions

* solve coexistance of nullness and Is* properties of DUs

* updating tests

* clean tests

* fantomas

* fantomas one more time

* importing nullness for generic typars

* print failing ivals, let's see

* write even more!

* isolated failing test - combo of module rec, signature file, IVT

* another attempt

* format

* test

* hide tests

* Remove 'specialname' for DU case tester

* format

* warning as error

* update baseline netcore

* nullable errors not in desktop framework

* surface area, trimming

* surface area

* cosmetic cleanup & annotations

* Rename to ILMethParentTypeInfo

* making vMapFold tail recursive

* physical nullnessEquiv

* format

* Commenting SkipNullness usages

* Nullness work - activity module

* Remove strict generic 'T:null' import

* Null|NonNull pattern also for regular compilation

* Backported Null|NonNull active pattern

* one more time

* revert

* Show nullness in quickinfo and in general in type representations

* Merge main to feature/nullness (#16539)

Merge of main + syntax conflict resolution + semantic conflict resolution

* release notes

* Fix ILType.Array import (#16585)

* Nullness - reading+writing metadata for  'inherits' and interface implementations (#16597)

* ILGenerator test case

* Nullness :: Format string %s should allow nullable string (#16656)

* Nullness::  Unchecked.nonNull for FSharp.Core (#16654)

* Nullness :: Pattern matching with null should mark input for subsequent clauses as without null + support for matching nulls in tuples (#16659)

* Feature nullness - support overrides of nullness annotation in the imported object hierarchy (#16711)

* Improve type inference w.r.t. nullness in printing (#16681)

* Update tests/AheadOfTime/Trimming/check.ps1

* Fix merge errors

* il tests reflecting visibility change

* Nullness feature :: New warning for functions insisting on a (WithNull) argument + typar equality fix (#16853)

Null-handling functions now have the option to raise a warning when they are called with a known-to-be-withoutNull argument.
That way, API authors (incl. Fsharp.Core) can help with cleaning code from superflous null checks.

While doing it, a strange error kept coming when using Option.ofObj and other functions with a (T | null) typar.
It turned out that nullness info had been striped from nullable typars on stripTyparEqnsAux calls in some occasions, leading to treating all typars as 'KnownWithoutNull' even when that was not true.

* Feature nullness - propper guards against ` | null ` on unsupported types (#16907)

TODOs resolved:
* mkAppTy resolved
* mkFunTyWithNullness
* delayed checks of post-infered values for nullness-carrying capabilities

* Feature nullness :: warn also for 'obj' type (since it can be infered for null literal) (#16962)

* Nullness feature :: various bugfixes (#17080)

* Bugfix - matching aliased nullable should strip nullness

Eliminating nullness after pattern matching null (that is , for subsequent patterns) must visit contents of abbreviations as well. Otherwise it does not work with the Maybe<T> type whcih we use in the compiler.

* Making 'obj' work with new 'not null' constraints in fslib functions

Bugfix: obj cannot be passed to generic typars which require T: not null, such as the NonNull active pattern.

This commit fixes it.

* Bugfix - false 'useless null' warning in nested applications

Error fixed:
Error on useless null checkwith nullness constraint propagation in code like this:let meTry = Option.ofObj (Path.GetDirectoryName "")`. The warning about 'useless Option.ofObj' points to the string literal, ignoring the string literal is first passed to an API which may return null

* Fix import for C# extension methods

Bugfix for:
C# extension methods which put "?" on the this argument are wrongly interpreted by moving the nullability elsewhere. See AsMemory<T> from System.Memory.dll , this treats byteArray.ToMemory() as resulting in a Memory<byte | null> which is clearly wrong.

Also, this now allows to call C# extension methods with ?this to be invoked on a nullable value.

* LinkedList First,Last bugfix

There was a bug of LinkedList .First and .Last properties not returning nullable nodes.
This was fixed by improved byte import in previous commit, adding a regression test for guarding this.


* Bugfix: Solve nullness for typars

This fixes a bug where `not null` generic constraint was incorrectly passed between two typars:`T1 | null` with not null constraint on T1, and T2 without constraints.

This occured when calling Option.ofObj(..) when the inner expression caused solving of generic type arguments, e.g. after (|>) or (id) function.

This uses additional inference variable to unify them.

* updating IL tests

* One more try

* surface area

* trimmed size

* trimmed size

* fix issues for plain 'dotnet build Fsharp.Compiler.Service.sln`

* update FSharpCoreShippedPackageVersionValue

* Wkraround attributetargets issue by using 'obj'. This removes 3x box and adds 1x unbox.

* Feature nullness :: Bugfixes (#17102)

* Ignore Nullness applied on structs (C# allows T? when when T is a struct)
* Bigfix: Working with CLI events in Fsharp
* Bugfix: Mutable binding initially assigned to null should not need type annotation
* Solving `let mutable cache = null` via type inference
* Enforcing TyparConstraint.IsReferenceType when WithNull type is used
* Nullness-related constraint consistency
* Bugfix for emitting Nullable attrs for C#

* Automated command ran: fantomas

  Co-authored-by: T-Gro <[email protected]>

* Feature nullness ::  Try infer without null even when function/method arg is marked as nullable (#17269)

* Feature nullness :: apply nullness annotations to usages of 'obj' in Fsharp.Core (#17284)

* resolve build error from auto-merge

* Feature nullness :: Cleanups, Test reorg, fix incrementalbuild cache behavior (#17309)


* Fix TransparentCompiler - it should report PostInference errors if it only encountered a warning (reported as an error due to confiig)

* fix build issues

* resolve semantic merge error

* Nullness subsumption when used for contravariant typars

* fix nullness plain build (#17404)

* Update docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

* Update release notes

* Update check.ps1

* Update check.ps1

---------

Co-authored-by: Vlad Zarytovskii <[email protected]>
Co-authored-by: Tomas Grosup <[email protected]>
Co-authored-by: dotnet bot <[email protected]>
Co-authored-by: Kevin Ransom (msft) <[email protected]>
Co-authored-by: Eugene Auduchinok <[email protected]>
Co-authored-by: Edgar Gonzalez <[email protected]>
Co-authored-by: Florian Verdonck <[email protected]>
Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: psfinaki <[email protected]>
  • Loading branch information
12 people authored Jul 17, 2024
1 parent 3125875 commit b73be15
Show file tree
Hide file tree
Showing 381 changed files with 20,622 additions and 2,630 deletions.
17 changes: 17 additions & 0 deletions .fantomasignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ src/FSharp.Core/Query.fs
src/FSharp.Core/seqcore.fs


# fsharp (to investigate)

**/TypeProviders.fsi
**/tainted.fsi

# uses nullness features

**/DependencyProvider.fsi
src/FSharp.Core/array.fs
src/FSharp.Core/option.fsi
src/FSharp.Core/option.fs
src/fsi/console.fs
src/FSharp.Build/FSharpCommandLineBuilder.fs
src/Compiler/Utilities/sformat.fs
src/Compiler/Utilities/illib.fsi
src/Compiler/Utilities/illib.fs

# Fantomas limitations on implementation files (to investigate)

src/Compiler/AbstractIL/ilwrite.fs
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ nCrunchTemp_*
tests/FSharp.Compiler.Service.Tests/FSharp.CompilerService.SurfaceArea.netstandard.actual
*.vsp
/tests/AheadOfTime/Trimming/output.txt
*.svclog
micro.exe
positive.exe
3 changes: 1 addition & 2 deletions FSharp.Benchmarks.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32113.165
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down
30 changes: 30 additions & 0 deletions FSharp.Profiles.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -->
<Project>
<PropertyGroup>
<!-- This turns on/off the use of the feature within the codebase -->
<!-- The default is off - it is selectively enabled -->
<CheckNulls Condition="'$(CheckNulls)' == ''">false</CheckNulls>
</PropertyGroup>

<PropertyGroup Condition="'$(FSHARPCORE_USE_PACKAGE)' == 'true'">
<!-- nullness checking isn't possible when using shipped FSharp.Core package until it's updated -->
<CheckNulls>false</CheckNulls>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Proto'">
<CheckNulls>false</CheckNulls>
<DefineConstants>NO_CHECKNULLS;BUILDING_WITH_LKG;NO_NULLCHECKING_LIB_SUPPORT;$(DefineConstants)</DefineConstants>
<NullCheckingSupportInLibrary>false</NullCheckingSupportInLibrary>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' != 'Proto' and '$(BUILDING_USING_DOTNET)' != 'true'">
<OtherFlags>$(OtherFlags) /langversion:preview</OtherFlags>
</PropertyGroup>

<PropertyGroup Condition="'$(CheckNulls)' == 'true'">
<OtherFlags>$(OtherFlags) /checknulls</OtherFlags>
</PropertyGroup>

<PropertyGroup Condition="'$(CheckNulls)' == 'false'">
<!-- 3271: warning nullness annotations being ignored -->
<NoWarn>$(NoWarn);3271</NoWarn>
<DefineConstants>NO_CHECKNULLS;$(DefineConstants)</DefineConstants>
</PropertyGroup>

<Choose>
<When Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">
Expand Down
4 changes: 4 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
### Fixed

* Compiler hangs when compiling inline recursive invocation ([Issue #17376](https://github.com/dotnet/fsharp/issues/17376), [PR #17394](https://github.com/dotnet/fsharp/pull/17394))

### Added

* Support for nullable reference types ([PR #15181](https://github.com/dotnet/fsharp/pull/15181))

### Changed

* Change compiler default setting realsig+ when building assemblies ([Issue #17384](https://github.com/dotnet/fsharp/issues/17384), [PR #17378](https://github.com/dotnet/fsharp/pull/17385))
* Change compiler default setting for compressedMetadata ([Issue #17379](https://github.com/dotnet/fsharp/issues/17379), [PR #17383](https://github.com/dotnet/fsharp/pull/17383))

Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.Language/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Speed up `for x in xs -> …` in list & array comprehensions in certain scenarios. ([PR #16948](https://github.com/dotnet/fsharp/pull/16948))
* Lower integral ranges to fast loops in more cases and optimize list and array construction from ranges. ([PR #16650](https://github.com/dotnet/fsharp/pull/16650), [PR #16832](https://github.com/dotnet/fsharp/pull/16832))
* Support for nullable reference types ([PR #15181](https://github.com/dotnet/fsharp/pull/15181))
* Better generic unmanaged structs handling. ([Language suggestion #692](https://github.com/fsharp/fslang-suggestions/issues/692), [PR #12154](https://github.com/dotnet/fsharp/pull/12154))
* Bidirectional F#/C# interop for 'unmanaged' constraint. ([PR #12154](https://github.com/dotnet/fsharp/pull/12154))
* Make `.Is*` discriminated union properties visible. ([Language suggestion #222](https://github.com/fsharp/fslang-suggestions/issues/222), [PR #16341](https://github.com/dotnet/fsharp/pull/16341))
Expand Down
32 changes: 25 additions & 7 deletions src/Compiler/AbstractIL/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,7 @@ type ILTypeDef
attributes: TypeAttributes,
layout: ILTypeDefLayout,
implements: ILTypes,
implementsCustomAttrs: (ILAttributesStored * int) list option,
genericParams: ILGenericParameterDefs,
extends: ILType option,
methods: ILMethodDefs,
Expand All @@ -2651,6 +2652,7 @@ type ILTypeDef
attributes,
layout,
implements,
implementsCustomAttrs,
genericParams,
extends,
methods,
Expand All @@ -2667,6 +2669,7 @@ type ILTypeDef
attributes,
layout,
implements,
implementsCustomAttrs,
genericParams,
extends,
methods,
Expand All @@ -2677,7 +2680,7 @@ type ILTypeDef
properties,
additionalFlags,
storeILSecurityDecls securityDecls,
customAttrs,
storeILCustomAttrs customAttrs,
NoMetadataIdx
)

Expand All @@ -2693,6 +2696,8 @@ type ILTypeDef

member _.Implements = implements

member _.ImplementsCustomAttrs = implementsCustomAttrs

member _.Extends = extends

member _.Methods = methods
Expand Down Expand Up @@ -2732,7 +2737,8 @@ type ILTypeDef
?properties,
?newAdditionalFlags,
?customAttrs,
?securityDecls
?securityDecls,
?implementsCustomAttrs
) =
ILTypeDef(
name = defaultArg name x.Name,
Expand All @@ -2741,6 +2747,7 @@ type ILTypeDef
genericParams = defaultArg genericParams x.GenericParams,
nestedTypes = defaultArg nestedTypes x.NestedTypes,
implements = defaultArg implements x.Implements,
implementsCustomAttrs = defaultArg implementsCustomAttrs x.ImplementsCustomAttrs,
extends = defaultArg extends x.Extends,
methods = defaultArg methods x.Methods,
securityDecls = defaultArg securityDecls x.SecurityDecls,
Expand All @@ -2749,7 +2756,7 @@ type ILTypeDef
events = defaultArg events x.Events,
properties = defaultArg properties x.Properties,
additionalFlags = defaultArg newAdditionalFlags additionalFlags,
customAttrs = defaultArg customAttrs (storeILCustomAttrs x.CustomAttrs)
customAttrs = defaultArg customAttrs (x.CustomAttrs)
)

member x.CustomAttrs: ILAttributes =
Expand Down Expand Up @@ -3439,6 +3446,11 @@ type ILGlobals(primaryScopeRef: ILScopeRef, equivPrimaryAssemblyRefs: ILAssembly

let mkSysILTypeRef nm = mkILTyRef (primaryScopeRef, nm)

let byteIlType = ILType.Value(mkILNonGenericTySpec (mkSysILTypeRef tname_Byte))

let stringIlType =
mkILBoxedType (mkILNonGenericTySpec (mkSysILTypeRef tname_String))

member _.primaryAssemblyScopeRef = primaryScopeRef

member x.primaryAssemblyRef =
Expand All @@ -3456,7 +3468,7 @@ type ILGlobals(primaryScopeRef: ILScopeRef, equivPrimaryAssemblyRefs: ILAssembly

member val typ_Object = mkILBoxedType (mkILNonGenericTySpec (mkSysILTypeRef tname_Object))

member val typ_String = mkILBoxedType (mkILNonGenericTySpec (mkSysILTypeRef tname_String))
member val typ_String = stringIlType

member val typ_Array = mkILBoxedType (mkILNonGenericTySpec (mkSysILTypeRef tname_Array))

Expand All @@ -3470,7 +3482,11 @@ type ILGlobals(primaryScopeRef: ILScopeRef, equivPrimaryAssemblyRefs: ILAssembly

member val typ_Int64 = ILType.Value(mkILNonGenericTySpec (mkSysILTypeRef tname_Int64))

member val typ_Byte = ILType.Value(mkILNonGenericTySpec (mkSysILTypeRef tname_Byte))
member val typ_Byte = byteIlType

member val typ_ByteArray = ILType.Array(ILArrayShape.SingleDimensional, byteIlType)

member val typ_StringArray = ILType.Array(ILArrayShape.SingleDimensional, stringIlType)

member val typ_UInt16 = ILType.Value(mkILNonGenericTySpec (mkSysILTypeRef tname_UInt16))

Expand Down Expand Up @@ -4231,12 +4247,13 @@ let mkILGenericClass (nm, access, genparams, extends, impl, methods, fields, nes
attributes = attributes,
genericParams = genparams,
implements = impl,
implementsCustomAttrs = None,
layout = ILTypeDefLayout.Auto,
extends = Some extends,
methods = methods,
fields = fields,
nestedTypes = nestedTypes,
customAttrs = storeILCustomAttrs attrs,
customAttrs = attrs,
methodImpls = emptyILMethodImpls,
properties = props,
events = events,
Expand All @@ -4255,12 +4272,13 @@ let mkRawDataValueTypeDef (iltyp_ValueType: ILType) (nm, size, pack) =
||| TypeAttributes.BeforeFieldInit
||| TypeAttributes.AnsiClass),
implements = [],
implementsCustomAttrs = None,
extends = Some iltyp_ValueType,
layout = ILTypeDefLayout.Explicit { Size = Some size; Pack = Some pack },
methods = emptyILMethods,
fields = emptyILFields,
nestedTypes = emptyILTypeDefs,
customAttrs = emptyILCustomAttrsStored,
customAttrs = emptyILCustomAttrs,
methodImpls = emptyILMethodImpls,
properties = emptyILProperties,
events = emptyILEvents,
Expand Down
32 changes: 28 additions & 4 deletions src/Compiler/AbstractIL/il.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,13 @@ type ILAttributes =

/// Represents the efficiency-oriented storage of ILAttributes in another item.
[<NoEquality; NoComparison>]
type ILAttributesStored
type ILAttributesStored =
/// Computed by ilread.fs based on metadata index
| Reader of (int32 -> ILAttribute[])
/// Already computed
| Given of ILAttributes

member GetCustomAttrs: int32 -> ILAttributes

/// Method parameters and return values.
[<RequireQualifiedAccess; NoEquality; NoComparison>]
Expand Down Expand Up @@ -1070,6 +1076,8 @@ type ILMethodDef =
member IsEntryPoint: bool
member GenericParams: ILGenericParameterDefs
member CustomAttrs: ILAttributes
member MetadataIndex: int32
member CustomAttrsStored: ILAttributesStored
member ParameterTypes: ILTypes
member IsIL: bool
member Code: ILCode option
Expand Down Expand Up @@ -1243,6 +1251,10 @@ type ILFieldDef =

member CustomAttrs: ILAttributes

member MetadataIndex: int32

member CustomAttrsStored: ILAttributesStored

member IsStatic: bool

member IsSpecialName: bool
Expand Down Expand Up @@ -1326,6 +1338,8 @@ type ILEventDef =
member FireMethod: ILMethodRef option
member OtherMethods: ILMethodRef list
member CustomAttrs: ILAttributes
member MetadataIndex: int32
member CustomAttrsStored: ILAttributesStored
member IsSpecialName: bool
member IsRTSpecialName: bool

Expand Down Expand Up @@ -1388,6 +1402,8 @@ type ILPropertyDef =
member Init: ILFieldInit option
member Args: ILTypes
member CustomAttrs: ILAttributes
member MetadataIndex: int32
member CustomAttrsStored: ILAttributesStored
member IsSpecialName: bool
member IsRTSpecialName: bool

Expand Down Expand Up @@ -1498,6 +1514,7 @@ type ILTypeDef =
attributes: TypeAttributes *
layout: ILTypeDefLayout *
implements: ILTypes *
implementsCustomAttrs: (ILAttributesStored * int) list option *
genericParams: ILGenericParameterDefs *
extends: ILType option *
methods: ILMethodDefs *
Expand All @@ -1518,6 +1535,7 @@ type ILTypeDef =
attributes: TypeAttributes *
layout: ILTypeDefLayout *
implements: ILTypes *
implementsCustomAttrs: (ILAttributesStored * int) list option *
genericParams: ILGenericParameterDefs *
extends: ILType option *
methods: ILMethodDefs *
Expand All @@ -1528,7 +1546,7 @@ type ILTypeDef =
properties: ILPropertyDefs *
additionalFlags: ILTypeDefAdditionalFlags *
securityDecls: ILSecurityDecls *
customAttrs: ILAttributesStored ->
customAttrs: ILAttributes ->
ILTypeDef

member Name: string
Expand All @@ -1537,6 +1555,7 @@ type ILTypeDef =
member Layout: ILTypeDefLayout
member NestedTypes: ILTypeDefs
member Implements: ILTypes
member ImplementsCustomAttrs: (ILAttributesStored * int) list option
member Extends: ILType option
member Methods: ILMethodDefs
member SecurityDecls: ILSecurityDecls
Expand All @@ -1545,6 +1564,8 @@ type ILTypeDef =
member Events: ILEventDefs
member Properties: ILPropertyDefs
member CustomAttrs: ILAttributes
member MetadataIndex: int32
member CustomAttrsStored: ILAttributesStored
member IsClass: bool
member IsStruct: bool
member IsInterface: bool
Expand Down Expand Up @@ -1593,8 +1614,9 @@ type ILTypeDef =
?events: ILEventDefs *
?properties: ILPropertyDefs *
?newAdditionalFlags: ILTypeDefAdditionalFlags *
?customAttrs: ILAttributesStored *
?securityDecls: ILSecurityDecls ->
?customAttrs: ILAttributes *
?securityDecls: ILSecurityDecls *
?implementsCustomAttrs: (ILAttributesStored * int) list option ->
ILTypeDef

/// Represents a prefix of information for ILTypeDef.
Expand Down Expand Up @@ -1890,11 +1912,13 @@ type internal ILGlobals =
member typ_Enum: ILType
member typ_Object: ILType
member typ_String: ILType
member typ_StringArray: ILType
member typ_Type: ILType
member typ_Array: ILType
member typ_IntPtr: ILType
member typ_UIntPtr: ILType
member typ_Byte: ILType
member typ_ByteArray: ILType
member typ_Int16: ILType
member typ_Int32: ILType
member typ_Int64: ILType
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/AbstractIL/ilmorph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ let rec tdef_ty2ty_ilmbody2ilmbody_mdefs2mdefs isInKnownSet enc fs (tdef: ILType
methodImpls = mimpls_ty2ty fTyInCtxtR tdef.MethodImpls,
events = edefs_ty2ty fTyInCtxtR tdef.Events,
properties = pdefs_ty2ty fTyInCtxtR tdef.Properties,
customAttrs = storeILCustomAttrs (cattrs_ty2ty fTyInCtxtR tdef.CustomAttrs)
customAttrs = cattrs_ty2ty fTyInCtxtR tdef.CustomAttrs
)

and tdefs_ty2ty_ilmbody2ilmbody_mdefs2mdefs isInKnownSet enc fs tdefs =
Expand Down
Loading

0 comments on commit b73be15

Please sign in to comment.