Skip to content

Commit 2e8ab38

Browse files
committed
squash
1 parent 635d723 commit 2e8ab38

File tree

119 files changed

+3722
-682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+3722
-682
lines changed

.fantomasignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ src/FSharp.Core/Query.fs
9090
src/FSharp.Core/seqcore.fs
9191

9292

93+
# fsharp (to investigate)
94+
95+
**/TypeProviders.fsi
96+
**/tainted.fsi
97+
98+
# uses nullness features
99+
100+
**/DependencyProvider.fsi
101+
src/FSharp.Core/array.fs
102+
src/FSharp.Core/option.fsi
103+
src/FSharp.Core/option.fs
104+
src/fsi/console.fs
105+
src/FSharp.Build/FSharpCommandLineBuilder.fs
106+
src/Compiler/Utilities/sformat.fs
107+
src/Compiler/Utilities/illib.fsi
108+
src/Compiler/Utilities/illib.fs
109+
93110
# Fantomas limitations on implementation files (to investigate)
94111

95112
src/Compiler/AbstractIL/ilwrite.fs

FSharp.Profiles.props

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -->
33
<Project>
4+
<PropertyGroup>
5+
<!-- This turns on/off the feature in FSharp.Core. -->
6+
<CheckNulls>false</CheckNulls>
7+
</PropertyGroup>
8+
9+
<PropertyGroup Condition="'$(FSHARPCORE_USE_PACKAGE)' == 'true'">
10+
<!-- nullness checking isn't possible when using shipped FSharp.Core package until it's updated -->
11+
<CheckNulls>false</CheckNulls>
12+
</PropertyGroup>
13+
14+
<PropertyGroup Condition="'$(Configuration)' == 'Proto'">
15+
<DefineConstants>BUILDING_WITH_LKG;NO_NULLCHECKING_LIB_SUPPORT;$(DefineConstants)</DefineConstants>
16+
<NullCheckingSupportInLibrary>false</NullCheckingSupportInLibrary>
17+
</PropertyGroup>
18+
19+
<PropertyGroup Condition="'$(Configuration)' != 'Proto'">
20+
<OtherFlags>$(OtherFlags) /langversion:preview</OtherFlags>
21+
</PropertyGroup>
22+
23+
<PropertyGroup Condition="'$(CheckNulls)' == 'true'">
24+
<OtherFlags>$(OtherFlags) /checknulls</OtherFlags>
25+
</PropertyGroup>
26+
27+
<PropertyGroup Condition="'$(CheckNulls)' == 'false'">
28+
<!-- 3271: warning nullness annotations being ignored -->
29+
<NoWarn>$(NoWarn);3271</NoWarn>
30+
<DefineConstants>NO_CHECKNULLS;$(DefineConstants)</DefineConstants>
31+
</PropertyGroup>
432

533
<Choose>
634
<When Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">

VisualFSharp.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Editor.Tests", "vsin
195195
EndProject
196196
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FSharp.Editor.IntegrationTests", "vsintegration\tests\FSharp.Editor.IntegrationTests\FSharp.Editor.IntegrationTests.csproj", "{E31F9B59-FCF1-4D04-8762-C7BB60285A7B}"
197197
EndProject
198+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "nullness", "tests\fsharp\core\nullness\nullness.fsproj", "{6992D926-AB1C-4CD4-94D5-0319D14DB54B}"
199+
EndProject
198200
Global
199201
GlobalSection(SolutionConfigurationPlatforms) = preSolution
200202
Debug|Any CPU = Debug|Any CPU
@@ -1033,6 +1035,18 @@ Global
10331035
{E31F9B59-FCF1-4D04-8762-C7BB60285A7B}.Release|Any CPU.Build.0 = Release|Any CPU
10341036
{E31F9B59-FCF1-4D04-8762-C7BB60285A7B}.Release|x86.ActiveCfg = Release|Any CPU
10351037
{E31F9B59-FCF1-4D04-8762-C7BB60285A7B}.Release|x86.Build.0 = Release|Any CPU
1038+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1039+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Debug|Any CPU.Build.0 = Debug|Any CPU
1040+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Debug|x86.ActiveCfg = Debug|Any CPU
1041+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Debug|x86.Build.0 = Debug|Any CPU
1042+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Proto|Any CPU.ActiveCfg = Debug|Any CPU
1043+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Proto|Any CPU.Build.0 = Debug|Any CPU
1044+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Proto|x86.ActiveCfg = Debug|Any CPU
1045+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Proto|x86.Build.0 = Debug|Any CPU
1046+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Release|Any CPU.ActiveCfg = Release|Any CPU
1047+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Release|Any CPU.Build.0 = Release|Any CPU
1048+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Release|x86.ActiveCfg = Release|Any CPU
1049+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B}.Release|x86.Build.0 = Release|Any CPU
10361050
EndGlobalSection
10371051
GlobalSection(SolutionProperties) = preSolution
10381052
HideSolutionNode = FALSE
@@ -1114,6 +1128,7 @@ Global
11141128
{FE23BB65-276A-4E41-8CC7-F7752241DEBA} = {39CDF34B-FB23-49AE-AB27-0975DA379BB5}
11151129
{CBC96CC7-65AB-46EA-A82E-F6A788DABF80} = {F7876C9B-FB6A-4EFB-B058-D6967DB75FB2}
11161130
{E31F9B59-FCF1-4D04-8762-C7BB60285A7B} = {F7876C9B-FB6A-4EFB-B058-D6967DB75FB2}
1131+
{6992D926-AB1C-4CD4-94D5-0319D14DB54B} = {CFE3259A-2D30-4EB0-80D5-E8B5F3D01449}
11171132
EndGlobalSection
11181133
GlobalSection(ExtensibilityGlobals) = postSolution
11191134
SolutionGuid = {48EDBBBE-C8EE-4E3C-8B19-97184A487B37}

src/Compiler/AbstractIL/ilread.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ let mkCacheInt32 lowMem _inbase _nm _sz =
931931
if lowMem then
932932
(fun f x -> f x)
933933
else
934-
let mutable cache = null
934+
let mutable cache: ConcurrentDictionary<int32, _> MaybeNull = null // TODO NULLNESS: this explicit annotation should not be needed
935935
let mutable count = 0
936936
#if STATISTICS
937937
addReport (fun oc ->
@@ -960,7 +960,7 @@ let mkCacheGeneric lowMem _inbase _nm _sz =
960960
if lowMem then
961961
(fun f x -> f x)
962962
else
963-
let mutable cache = null
963+
let mutable cache: ConcurrentDictionary<_, _> MaybeNull = null // TODO NULLNESS: this explicit annotation should not be needed
964964
let mutable count = 0
965965
#if STATISTICS
966966
addReport (fun oc ->

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,43 @@ let TranslatePartialValReprInfo tps (PrelimValReprInfo (argsData, retData)) =
971971
// Members
972972
//-------------------------------------------------------------------------
973973

974+
let TcAddNullnessToType (warn: bool) (cenv: cenv) (env: TcEnv) nullness innerTyC m =
975+
let g = cenv.g
976+
if g.langFeatureNullness then
977+
if TypeNullNever g innerTyC then
978+
let tyString = NicePrint.minimalStringOfType env.DisplayEnv innerTyC
979+
errorR(Error(FSComp.SR.tcTypeDoesNotHaveAnyNull(tyString), m))
980+
981+
match tryAddNullnessToTy nullness innerTyC with
982+
983+
| None ->
984+
let tyString = NicePrint.minimalStringOfType env.DisplayEnv innerTyC
985+
errorR(Error(FSComp.SR.tcTypeDoesNotHaveAnyNull(tyString), m))
986+
innerTyC
987+
988+
| Some innerTyCWithNull ->
989+
// The inner type is not allowed to support null or use null as a representation value.
990+
// For example "int option?" is not allowed, nor "string??".
991+
//
992+
// For variable types in FSharp.Core we make an exception because we must allow
993+
// val toObj: value: 'T option -> 'T __withnull when 'T : not struct (* and 'T : __notnull *)
994+
// wihout implying 'T is not null. This is because it is legitimate to use this
995+
// function to "collapse" null and obj-null-coming-from-option using such a function.
996+
997+
if not g.compilingFSharpCore || not (isTyparTy g innerTyC) then
998+
AddCxTypeDefnNotSupportsNull env.DisplayEnv cenv.css m NoTrace innerTyC
999+
1000+
innerTyCWithNull
1001+
1002+
else
1003+
if warn then
1004+
warning(Error(FSComp.SR.tcNullnessCheckingNotEnabled(), m))
1005+
innerTyC
1006+
1007+
//-------------------------------------------------------------------------
1008+
// Members
1009+
//-------------------------------------------------------------------------
1010+
9741011
let ComputeLogicalName (id: Ident) (memberFlags: SynMemberFlags) =
9751012
match memberFlags.MemberKind with
9761013
| SynMemberKind.ClassConstructor -> ".cctor"
@@ -2085,7 +2122,7 @@ module GeneralizationHelpers =
20852122
match tp.Constraints |> List.partition (function TyparConstraint.CoercesTo _ -> true | _ -> false) with
20862123
| [TyparConstraint.CoercesTo(tgtTy, _)], others ->
20872124
// Throw away null constraints if they are implied
2088-
if others |> List.exists (function TyparConstraint.SupportsNull _ -> not (TypeSatisfiesNullConstraint g m tgtTy) | _ -> true)
2125+
if others |> List.exists (function TyparConstraint.SupportsNull _ -> not (TypeNullIsExtraValue g m tgtTy) | _ -> true)
20892126
then None
20902127
else Some tgtTy
20912128
| _ -> None
@@ -3963,7 +4000,14 @@ let rec TcTyparConstraint ridx (cenv: cenv) newOk checkConstraints occ (env: TcE
39634000
tpenv
39644001

39654002
| SynTypeConstraint.WhereTyparSupportsNull(tp, m) ->
3966-
TcSimpleTyparConstraint cenv env newOk tpenv tp m AddCxTypeUseSupportsNull
4003+
TcSimpleTyparConstraint cenv env newOk tpenv tp m AddCxTypeDefnSupportsNull
4004+
4005+
| SynTypeConstraint.WhereTyparNotSupportsNull(tp, m) ->
4006+
if g.langFeatureNullness then
4007+
TcSimpleTyparConstraint cenv env newOk tpenv tp m AddCxTypeDefnNotSupportsNull
4008+
else
4009+
warning(Error(FSComp.SR.tcNullnessCheckingNotEnabled(), m))
4010+
tpenv
39674011

39684012
| SynTypeConstraint.WhereTyparIsComparable(tp, m) ->
39694013
TcSimpleTyparConstraint cenv env newOk tpenv tp m AddCxTypeMustSupportComparison
@@ -4377,11 +4421,18 @@ and TcTypeOrMeasure kindOpt (cenv: cenv) newOk checkConstraints occ (iwsam: Warn
43774421
| SynType.StaticConstant (synConst, m) ->
43784422
TcTypeStaticConstant kindOpt tpenv synConst m
43794423

4424+
| SynType.StaticConstantNull m
43804425
| SynType.StaticConstantNamed (_, _, m)
43814426
| SynType.StaticConstantExpr (_, m) ->
43824427
errorR(Error(FSComp.SR.parsInvalidLiteralInType(), m))
43834428
NewErrorType (), tpenv
43844429

4430+
| SynType.WithNull(innerTy, ambivalent, m) ->
4431+
let innerTyC, tpenv = TcTypeAndRecover cenv newOk checkConstraints occ WarnOnIWSAM.Yes env tpenv innerTy
4432+
let nullness = if ambivalent then KnownAmbivalentToNull else KnownWithNull
4433+
let tyWithNull = TcAddNullnessToType false cenv env nullness innerTyC m
4434+
tyWithNull, tpenv
4435+
43854436
| SynType.MeasurePower(ty, exponent, m) ->
43864437
TcTypeMeasurePower kindOpt cenv newOk checkConstraints occ env tpenv ty exponent m
43874438

@@ -4531,7 +4582,7 @@ and TcFunctionType (cenv: cenv) newOk checkConstraints occ env tpenv domainTy re
45314582
and TcArrayType (cenv: cenv) newOk checkConstraints occ env tpenv rank elemTy m =
45324583
let g = cenv.g
45334584
let elemTy, tpenv = TcTypeAndRecover cenv newOk checkConstraints occ WarnOnIWSAM.Yes env tpenv elemTy
4534-
let tyR = mkArrayTy g rank elemTy m
4585+
let tyR = mkArrayTy g rank g.knownWithoutNull elemTy m
45354586
tyR, tpenv
45364587

45374588
and TcTypeParameter kindOpt (cenv: cenv) env newOk tpenv tp =
@@ -4556,8 +4607,9 @@ and TcTypeWithConstraints (cenv: cenv) env newOk checkConstraints occ tpenv synT
45564607
and TcTypeHashConstraint (cenv: cenv) env newOk checkConstraints occ tpenv synTy m =
45574608
let tp = TcAnonTypeOrMeasure (Some TyparKind.Type) cenv TyparRigidity.WarnIfNotRigid TyparDynamicReq.Yes newOk m
45584609
let ty, tpenv = TcTypeAndRecover cenv newOk checkConstraints occ WarnOnIWSAM.No env tpenv synTy
4559-
AddCxTypeMustSubsumeType ContextInfo.NoContext env.DisplayEnv cenv.css m NoTrace ty (mkTyparTy tp)
4560-
tp.AsType, tpenv
4610+
let tpTy = mkTyparTy tp
4611+
AddCxTypeMustSubsumeType ContextInfo.NoContext env.DisplayEnv cenv.css m NoTrace ty tpTy
4612+
tpTy, tpenv
45614613

45624614
and TcTypeStaticConstant kindOpt tpenv c m =
45634615
match c, kindOpt with
@@ -4711,7 +4763,7 @@ and TcStaticConstantParameter (cenv: cenv) (env: TcEnv) tpenv kind (StripParenTy
47114763
| SynConst.Double n when typeEquiv g g.float_ty kind -> record(g.float_ty); box (n: double)
47124764
| SynConst.Char n when typeEquiv g g.char_ty kind -> record(g.char_ty); box (n: char)
47134765
| SynConst.String (s, _, _)
4714-
| SynConst.SourceIdentifier (_, s, _) when s <> null && typeEquiv g g.string_ty kind -> record(g.string_ty); box (s: string)
4766+
| SynConst.SourceIdentifier (_, s, _) when typeEquiv g g.string_ty kind -> record(g.string_ty); box (s: string)
47154767
| SynConst.Bool b when typeEquiv g g.bool_ty kind -> record(g.bool_ty); box (b: bool)
47164768
| _ -> fail()
47174769
v, tpenv
@@ -4740,7 +4792,6 @@ and TcStaticConstantParameter (cenv: cenv) (env: TcEnv) tpenv kind (StripParenTy
47404792
| Const.Single n -> record(g.float32_ty); box (n: single)
47414793
| Const.Double n -> record(g.float_ty); box (n: double)
47424794
| Const.Char n -> record(g.char_ty); box (n: char)
4743-
| Const.String null -> fail()
47444795
| Const.String s -> record(g.string_ty); box (s: string)
47454796
| Const.Bool b -> record(g.bool_ty); box (b: bool)
47464797
| _ -> fail()
@@ -4909,7 +4960,7 @@ and TcTypeApp (cenv: cenv) newOk checkConstraints occ env tpenv m tcref pathType
49094960
List.iter2 (UnifyTypes cenv env m) tinst actualArgTys
49104961

49114962
// Try to decode System.Tuple --> F# tuple types etc.
4912-
let ty = g.decompileType tcref actualArgTys
4963+
let ty = g.decompileType tcref actualArgTys g.knownWithoutNull
49134964

49144965
ty, tpenv
49154966

@@ -5564,8 +5615,11 @@ and TcExprUndelayed (cenv: cenv) (overallTy: OverallTy) env tpenv (synExpr: SynE
55645615

55655616
| SynExpr.Null m ->
55665617
TcNonControlFlowExpr env <| fun env ->
5618+
// Which?
55675619
AddCxTypeUseSupportsNull env.DisplayEnv cenv.css m NoTrace overallTy.Commit
5568-
mkNull m overallTy.Commit, tpenv
5620+
//AddCxTypeDefnSupportsNull env.DisplayEnv cenv.css m NoTrace overallTy.Commit
5621+
let tyWithNull = addNullnessToTy KnownWithNull overallTy.Commit
5622+
mkNull m tyWithNull, tpenv
55695623

55705624
| SynExpr.Lazy (synInnerExpr, m) ->
55715625
TcNonControlFlowExpr env <| fun env ->

src/Compiler/Checking/CheckPatterns.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ and TcRecordPat warnOnUpper cenv env vFlags patEnv ty fieldPats m =
461461
and TcNullPat cenv env patEnv ty m =
462462
try
463463
AddCxTypeUseSupportsNull env.DisplayEnv cenv.css m NoTrace ty
464+
// Which?
465+
//AddCxTypeDefnSupportsNull env.DisplayEnv cenv.css m NoTrace ty
464466
with exn ->
465467
errorRecovery exn m
466468
(fun _ -> TPat_null m), patEnv

0 commit comments

Comments
 (0)