Skip to content

Commit 274c9a0

Browse files
dsymeKevinRansom
authored andcommitted
[RFC FS-1068] open static classes (#6807)
* open static classes feature * add missing change back * Update dependencies from https://github.com/dotnet/arcade build 20190704.2 - Microsoft.DotNet.Arcade.Sdk - 1.0.0-beta.19354.2 * support struct tuple in leaf expression converter (#7144) * Update dependencies from https://github.com/dotnet/arcade build 20190705.2 - Microsoft.DotNet.Arcade.Sdk - 1.0.0-beta.19355.2 * Update dependencies from https://github.com/dotnet/arcade build 20190706.1 - Microsoft.DotNet.Arcade.Sdk - 1.0.0-beta.19356.1 * fix merge
1 parent 5a91e91 commit 274c9a0

17 files changed

Lines changed: 373 additions & 207 deletions

File tree

eng/Version.Details.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<ProductDependencies>
44
</ProductDependencies>
55
<ToolsetDependencies>
6-
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="1.0.0-beta.19353.19">
6+
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="1.0.0-beta.19356.1">
77
<Uri>https://github.com/dotnet/arcade</Uri>
8-
<Sha>733f8297b68dd824044a77d955e62305b9dc43d5</Sha>
8+
<Sha>a65d0966dc28861394ce78cfdcb9d5dff370957c</Sha>
99
</Dependency>
1010
</ToolsetDependencies>
1111
</Dependencies>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
},
1212
"msbuild-sdks": {
13-
"Microsoft.DotNet.Arcade.Sdk": "1.0.0-beta.19353.19",
13+
"Microsoft.DotNet.Arcade.Sdk": "1.0.0-beta.19356.1",
1414
"Microsoft.DotNet.Helix.Sdk": "2.0.0-beta.19069.2"
1515
}
1616
}

src/fsharp/ErrorLogger.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ type public FSharpErrorSeverityOptions =
671671

672672

673673
// See https://github.com/Microsoft/visualfsharp/issues/6417, if a compile of the FSharp.Compiler.Services.dll or other compiler
674-
// binary produces exactly 65536 methods then older versions of the compiler raise a bug. If you hit this bug again then try removing
675-
// this.
676-
let dummyMethodFOrBug6417A() = ()
677-
let dummyMethodFOrBug6417B() = ()
674+
// binary produces exactly 65536 methods then older versions of the compiler raise a bug. If you hit this bug again then try adding
675+
// this back in.
676+
// let dummyMethodFOrBug6417A() = ()
677+
// let dummyMethodFOrBug6417B() = ()

src/fsharp/ExtensionTyping.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ module internal ExtensionTyping =
415415
member __.IsEnum = x.IsEnum
416416
member __.IsClass = x.IsClass
417417
member __.IsSealed = x.IsSealed
418+
member __.IsAbstract = x.IsAbstract
418419
member __.IsInterface = x.IsInterface
419420
member __.GetArrayRank() = x.GetArrayRank()
420421
member __.GenericParameterPosition = x.GenericParameterPosition

src/fsharp/ExtensionTyping.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ module internal ExtensionTyping =
120120
member IsInterface : bool
121121
member IsClass : bool
122122
member IsSealed : bool
123+
member IsAbstract : bool
123124
member IsPublic : bool
124125
member IsNestedPublic : bool
125126
member GenericParameterPosition : int

src/fsharp/NameResolution.fs

Lines changed: 248 additions & 168 deletions
Large diffs are not rendered by default.

src/fsharp/NameResolution.fsi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ val internal AddModuleOrNamespaceRefsToNameEnv : TcGlobals ->
201201
val internal AddModuleOrNamespaceRefToNameEnv : TcGlobals -> ImportMap -> range -> bool -> AccessorDomain -> NameResolutionEnv -> ModuleOrNamespaceRef -> NameResolutionEnv
202202

203203
/// Add a list of modules or namespaces to the name resolution environment
204-
val internal AddModulesAndNamespacesContentsToNameEnv : TcGlobals -> ImportMap -> AccessorDomain -> range -> bool -> NameResolutionEnv -> ModuleOrNamespaceRef list -> NameResolutionEnv
204+
val internal AddEntitiesContentsToNameEnv : TcGlobals -> ImportMap -> AccessorDomain -> range -> bool -> NameResolutionEnv -> ModuleOrNamespaceRef list -> NameResolutionEnv
205205

206206
/// A flag which indicates if it is an error to have two declared type parameters with identical names
207207
/// in the name resolution environment.
@@ -468,8 +468,8 @@ type PermitDirectReferenceToGeneratedType =
468468
| Yes
469469
| No
470470

471-
/// Resolve a long identifier to a namespace or module.
472-
val internal ResolveLongIndentAsModuleOrNamespace : TcResultsSink -> ResultCollectionSettings -> Import.ImportMap -> range -> bool -> FullyQualifiedFlag -> NameResolutionEnv -> AccessorDomain -> Ident -> Ident list -> isOpenDecl: bool -> ResultOrException<(int * ModuleOrNamespaceRef * ModuleOrNamespaceType) list >
471+
/// Resolve a long identifier to a namespace, module or static class.
472+
val internal ResolveLongIndentAsModuleOrNamespaceOrStaticClass : TcResultsSink -> ResultCollectionSettings -> Import.ImportMap -> range -> allowStaticClasses: bool -> first: bool -> FullyQualifiedFlag -> NameResolutionEnv -> AccessorDomain -> Ident -> Ident list -> isOpenDecl: bool -> ResultOrException<(int * ModuleOrNamespaceRef * ModuleOrNamespaceType) list >
473473

474474
/// Resolve a long identifier to an object constructor.
475475
val internal ResolveObjectConstructor : NameResolver -> DisplayEnv -> range -> AccessorDomain -> TType -> ResultOrException<Item>

src/fsharp/TastOps.fs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8941,3 +8941,19 @@ let isThreadOrContextStatic g attrs =
89418941
let mkUnitDelayLambda (g: TcGlobals) m e =
89428942
let uv, _ = mkCompGenLocal m "unitVar" g.unit_ty
89438943
mkLambda m uv (e, tyOfExpr g e)
8944+
8945+
8946+
let isStaticClass (g:TcGlobals) (x: EntityRef) =
8947+
not x.IsModuleOrNamespace &&
8948+
x.TyparsNoRange.IsEmpty &&
8949+
((x.IsILTycon &&
8950+
x.ILTyconRawMetadata.IsSealed &&
8951+
x.ILTyconRawMetadata.IsAbstract)
8952+
#if !NO_EXTENSIONTYPING
8953+
|| (x.IsProvided &&
8954+
match x.TypeReprInfo with
8955+
| TProvidedTypeExtensionPoint info -> info.IsSealed && info.IsAbstract
8956+
| _ -> false)
8957+
#endif
8958+
|| (not x.IsILTycon && not x.IsProvided && HasFSharpAttribute g g.attrib_AbstractClassAttribute x.Attribs)) &&
8959+
not (HasFSharpAttribute g g.attrib_RequireQualifiedAccessAttribute x.Attribs)

src/fsharp/TastOps.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,3 +2295,4 @@ val isThreadOrContextStatic: TcGlobals -> Attrib list -> bool
22952295

22962296
val mkUnitDelayLambda: TcGlobals -> range -> Expr -> Expr
22972297

2298+
val isStaticClass: g: TcGlobals -> tcref: TyconRef -> bool

src/fsharp/TypeChecker.fs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,11 @@ let AddLocalTyconsAndReport tcSink scopem g amap m tycons env =
371371
CallEnvSink tcSink (scopem, env.NameEnv, env.eAccessRights)
372372
env
373373

374-
/// Adjust the TcEnv to account for opening the set of modules and namespaces implied by an `open` declaration
375-
let OpenModulesOrNamespaces tcSink g amap scopem root env mvvs openDeclaration =
374+
/// Adjust the TcEnv to account for opening the set of modules, namespaces or static classes implied by an `open` declaration
375+
let OpenEntities tcSink g amap scopem root env mvvs openDeclaration =
376376
let env =
377377
if isNil mvvs then env else
378-
{ env with eNameResEnv = AddModulesAndNamespacesContentsToNameEnv g amap env.eAccessRights scopem root env.eNameResEnv mvvs }
378+
{ env with eNameResEnv = AddEntitiesContentsToNameEnv g amap env.eAccessRights scopem root env.eNameResEnv mvvs }
379379
CallEnvSink tcSink (scopem, env.NameEnv, env.eAccessRights)
380380
CallOpenDeclarationSink tcSink openDeclaration
381381
env
@@ -645,11 +645,11 @@ let ImplicitlyOpenOwnNamespace tcSink g amap scopem enclosingNamespacePath env =
645645
match enclosingNamespacePathToOpen with
646646
| id :: rest ->
647647
let ad = env.eAccessRights
648-
match ResolveLongIndentAsModuleOrNamespace tcSink ResultCollectionSettings.AllResults amap scopem true OpenQualified env.eNameResEnv ad id rest true with
648+
match ResolveLongIndentAsModuleOrNamespaceOrStaticClass tcSink ResultCollectionSettings.AllResults amap scopem true true OpenQualified env.eNameResEnv ad id rest true with
649649
| Result modrefs ->
650650
let modrefs = List.map p23 modrefs
651651
let openDecl = OpenDeclaration.Create (enclosingNamespacePathToOpen, modrefs, scopem, true)
652-
OpenModulesOrNamespaces tcSink g amap scopem false env modrefs openDecl
652+
OpenEntities tcSink g amap scopem false env modrefs openDecl
653653
| Exception _ -> env
654654
| _ -> env
655655

@@ -6884,7 +6884,7 @@ and TcConstExpr cenv overallTy env m tpenv c =
68846884
let expr =
68856885
let modName = "NumericLiteral" + suffix
68866886
let ad = env.eAccessRights
6887-
match ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AtMostOneResult cenv.amap m true OpenQualified env.eNameResEnv ad (ident (modName, m)) [] false with
6887+
match ResolveLongIndentAsModuleOrNamespaceOrStaticClass cenv.tcSink ResultCollectionSettings.AtMostOneResult cenv.amap m true true OpenQualified env.eNameResEnv ad (ident (modName, m)) [] false with
68886888
| Result []
68896889
| Exception _ -> error(Error(FSComp.SR.tcNumericLiteralRequiresModule modName, m))
68906890
| Result ((_, mref, _) :: _) ->
@@ -8774,7 +8774,7 @@ and TcNameOfExpr cenv env tpenv (synArg: SynExpr) =
87748774
| LongOrSingleIdent (false, (LongIdentWithDots(longId, _) as lidd), _, _) when longId.Length > 0 ->
87758775
let ad = env.eAccessRights
87768776
let id, rest = List.headAndTail longId
8777-
match ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m true OpenQualified env.eNameResEnv ad id rest true with
8777+
match ResolveLongIndentAsModuleOrNamespaceOrStaticClass cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m false true OpenQualified env.eNameResEnv ad id rest true with
87788778
| Result modref when delayed.IsEmpty && modref |> List.exists (p23 >> IsEntityAccessible cenv.amap m ad) ->
87798779
() // resolved to a module or namespace, done with checks
87808780
| _ ->
@@ -12642,19 +12642,19 @@ let TcTyconMemberSpecs cenv env containerInfo declKind tpenv (augSpfn: SynMember
1264212642
// Bind 'open' declarations
1264312643
//-------------------------------------------------------------------------
1264412644

12645-
let TcModuleOrNamespaceLidAndPermitAutoResolve tcSink env amap (longId: Ident list) =
12645+
let TcOpenLidAndPermitAutoResolve tcSink env amap (longId : Ident list) =
1264612646
let ad = env.eAccessRights
1264712647
match longId with
1264812648
| [] -> []
1264912649
| id :: rest ->
1265012650
let m = longId |> List.map (fun id -> id.idRange) |> List.reduce unionRanges
12651-
match ResolveLongIndentAsModuleOrNamespace tcSink ResultCollectionSettings.AllResults amap m true OpenQualified env.eNameResEnv ad id rest true with
12651+
match ResolveLongIndentAsModuleOrNamespaceOrStaticClass tcSink ResultCollectionSettings.AllResults amap m true true OpenQualified env.eNameResEnv ad id rest true with
1265212652
| Result res -> res
1265312653
| Exception err ->
1265412654
errorR(err); []
1265512655

1265612656
let TcOpenDecl tcSink (g: TcGlobals) amap m scopem env (longId: Ident list) =
12657-
match TcModuleOrNamespaceLidAndPermitAutoResolve tcSink env amap longId with
12657+
match TcOpenLidAndPermitAutoResolve tcSink env amap longId with
1265812658
| [] -> env
1265912659
| modrefs ->
1266012660

@@ -12706,7 +12706,7 @@ let TcOpenDecl tcSink (g: TcGlobals) amap m scopem env (longId: Ident list) =
1270612706
modrefs |> List.iter (fun modref -> CheckEntityAttributes g modref m |> CommitOperationResult)
1270712707

1270812708
let openDecl = OpenDeclaration.Create (longId, modrefs, scopem, false)
12709-
let env = OpenModulesOrNamespaces tcSink g amap scopem false env modrefs openDecl
12709+
let env = OpenEntities tcSink g amap scopem false env modrefs openDecl
1271012710
env
1271112711

1271212712

@@ -14181,7 +14181,7 @@ module MutRecBindingChecking =
1418114181
let resolved =
1418214182
match p with
1418314183
| [] -> Result []
14184-
| id :: rest -> ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m true OpenQualified env.eNameResEnv ad id rest false
14184+
| id :: rest -> ResolveLongIndentAsModuleOrNamespaceOrStaticClass cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m false true OpenQualified env.eNameResEnv ad id rest false
1418514185
let mvvs = ForceRaise resolved
1418614186
if isNil mvvs then env else
1418714187
let modrefs = mvvs |> List.map p23
@@ -17008,7 +17008,7 @@ let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synS
1700817008
let resolved =
1700917009
match p with
1701017010
| [] -> Result []
17011-
| id :: rest -> ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m true OpenQualified env.eNameResEnv ad id rest false
17011+
| id :: rest -> ResolveLongIndentAsModuleOrNamespaceOrStaticClass cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m false true OpenQualified env.eNameResEnv ad id rest false
1701217012
let mvvs = ForceRaise resolved
1701317013
let scopem = unionRanges m endm
1701417014
let unfilteredModrefs = mvvs |> List.map p23
@@ -17562,7 +17562,7 @@ let ApplyAssemblyLevelAutoOpenAttributeToTcEnv g amap (ccu: CcuThunk) scopem env
1756217562
| ValueNone -> warn()
1756317563
| ValueSome _ ->
1756417564
let openDecl = OpenDeclaration.Create ([], [modref], scopem, false)
17565-
OpenModulesOrNamespaces TcResultsSink.NoSink g amap scopem root env [modref] openDecl
17565+
OpenEntities TcResultsSink.NoSink g amap scopem root env [modref] openDecl
1756617566

1756717567
// Add the CCU and apply the "AutoOpen" attributes
1756817568
let AddCcuToTcEnv(g, amap, scopem, env, assemblyName, ccu, autoOpens, internalsVisible) =

0 commit comments

Comments
 (0)