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

Rework some F# layering #17370

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
The table of contents is too big for display.
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 @@ -31,6 +31,7 @@
* Support empty-bodied computation expressions. ([Language suggestion #1232](https://github.com/fsharp/fslang-suggestions/issues/1232), [RFC FS-1144 (PR #774)](https://github.com/fsharp/fslang-design/pull/774), [PR #17352](https://github.com/dotnet/fsharp/pull/17352))

### Changed
* `Initial refactoring of FSharp.Core` ([Issues #17372](https://github.com/dotnet/fsharp/issues/17372), [PR #17370](https://github.com/dotnet/fsharp/pull/17370))
* Enforce `AttributeTargets.Interface` ([PR #17173](https://github.com/dotnet/fsharp/pull/17173))
* Minor compiler perf improvements. ([PR #17130](https://github.com/dotnet/fsharp/pull/17130))
* Improve error messages for active pattern argument count mismatch ([PR #16846](https://github.com/dotnet/fsharp/pull/16846), [PR #17186](https://github.com/dotnet/fsharp/pull/17186))
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
### 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))
* Initial refactoring of FSharp.Core ([Issues #17372](https://github.com/dotnet/fsharp/issues/17372), [PR #17370](https://github.com/dotnet/fsharp/pull/17370))

### Breaking Changes
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Core/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### 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))
* Initial refactoring of FSharp.Core ([Issues #17372](https://github.com/dotnet/fsharp/issues/17372), [PR #17370](https://github.com/dotnet/fsharp/pull/17370))

### Breaking Changes

3 changes: 2 additions & 1 deletion release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ These release notes track our current efforts to document changes to the F# proj
A 'do expr' declaration in a module will correspond to a SynModuleDecl.Expr enclosing a SynExpr.Do
This constructo also loses the debug point as it was always None. The debug point
is always implicit for this construct.
* In FCS API, FSharpParsingOptions, `CompilingFsLib` --> `CompilingFSharpCore`
* In FCS API, FSharpParsingOptions, `CompilingFsLib` --> `compilingFSharpCore`
* In FCS API, FSharpParsingOptions, `ErrorSeverityOptions` --> `DiagnosticOptions`
* [SynIdent](https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-syntax-synident.html#SynIdent) was introduced in the Untyped Syntax Tree.
This represent an `Ident` with potential additional information, stored as [IdentTrivia](https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-syntaxtrivia-identtrivia.html)).
Expand All @@ -40,6 +40,7 @@ These release notes track our current efforts to document changes to the F# proj
* `DoesIdentifierNeedBackticks` is removed, it should always be sufficient to call `NormalizeIdentifierBackticks` or else call something in `PrettyNaming`
* `AddBackticksToIdentifierIfNeeded` is removed, it should always be sufficient to call `NormalizeIdentifierBackticks`
* `DeclarationListItem.Name` --> `DeclarationListItem.NameInList`
* In FCS API, FSharpParsingOptions, `compilingFSharpCore` --> `compilingCoreLibrary`

### F# 6.0 / Visual Studio 17.0

Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/AbstractIL/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4774,11 +4774,11 @@ let compareILVersions (version1: ILVersionInfo) (version2: ILVersionInfo) =
let c = compare version1.Revision version2.Revision
if c <> 0 then c else 0

let DummyFSharpCoreScopeRef =
let mkDummyCoreLibraryScopeRef coreLibraryName =
let asmRef =
// The exact public key token and version used here don't actually matter, or shouldn't.
ILAssemblyRef.Create(
"FSharp.Core",
coreLibraryName,
None,
Some(PublicKeyToken(Bytes.ofInt32Array [| 0xb0; 0x3f; 0x5f; 0x7f; 0x11; 0xd5; 0x0a; 0x3a |])),
false,
Expand All @@ -4789,7 +4789,7 @@ let DummyFSharpCoreScopeRef =
ILScopeRef.Assembly asmRef

let PrimaryAssemblyILGlobals =
mkILGlobals (ILScopeRef.PrimaryAssembly, [], DummyFSharpCoreScopeRef)
mkILGlobals (ILScopeRef.PrimaryAssembly, [], mkDummyCoreLibraryScopeRef "FSharp.Core")

let rec decodeCustomAttrElemType bytes sigptr x =
match x with
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/AbstractIL/il.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -2406,6 +2406,7 @@ val internal sha1HashBytes: byte[] -> byte (* SHA1 hash *) []
val internal parseILVersion: string -> ILVersionInfo
val internal formatILVersion: ILVersionInfo -> string
val internal compareILVersions: ILVersionInfo -> ILVersionInfo -> int
val internal mkDummyCoreLibraryScopeRef: string -> ILScopeRef

/// Decompose a type definition according to its kind.
type internal ILEnumInfo =
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Checking/AttributeChecking.fs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ let CheckFSharpAttributes (g:TcGlobals) attribs m =
// See attribute on FSharp.Core 'nameof'
if n = 3501 then
()
elif isError && (not g.compilingFSharpCore || n <> 1204) then
elif isError && (not g.compilingCoreLibrary || n <> 1204) then
do! ErrorD msg
else
do! WarnD msg
Expand All @@ -304,7 +304,7 @@ let CheckFSharpAttributes (g:TcGlobals) attribs m =
match TryFindFSharpAttribute g g.attrib_ExperimentalAttribute attribs with
| Some(Attrib(_, _, [ AttribStringArg(s) ], _, _, _, _)) ->
let isExperimentalAttributeDisabled (s:string) =
if g.compilingFSharpCore then
if g.compilingCoreLibrary then
true
else
g.langVersion.IsPreviewEnabled && (s.IndexOf(langVersionPrefix, StringComparison.OrdinalIgnoreCase) >= 0)
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Checking/AugmentWithHashCompare.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ let CheckAugmentationAttribs isImplementation g amap (tycon: Tycon) =

let TyconIsCandidateForAugmentationWithCompare (g: TcGlobals) (tycon: Tycon) =
// This type gets defined in prim-types, before we can add attributes to F# type definitions
let isUnit = g.compilingFSharpCore && tycon.DisplayName = "Unit"
let isUnit = g.compilingCoreLibrary && tycon.DisplayName = "Unit"

not isUnit
&& not (isByrefLikeTyconRef g tycon.Range (mkLocalTyconRef tycon))
Expand All @@ -1175,7 +1175,7 @@ let TyconIsCandidateForAugmentationWithCompare (g: TcGlobals) (tycon: Tycon) =

let TyconIsCandidateForAugmentationWithEquals (g: TcGlobals) (tycon: Tycon) =
// This type gets defined in prim-types, before we can add attributes to F# type definitions
let isUnit = g.compilingFSharpCore && tycon.DisplayName = "Unit"
let isUnit = g.compilingCoreLibrary && tycon.DisplayName = "Unit"

not isUnit
&& not (isByrefLikeTyconRef g tycon.Range (mkLocalTyconRef tycon))
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/CheckBasics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ type TcFileState =
isSig = isSig
haveSig = haveSig
namedDebugPointsForInlinedCode = Dictionary()
compilingCanonicalFslibModuleType = (isSig || not haveSig) && g.compilingFSharpCore
compilingCanonicalFslibModuleType = (isSig || not haveSig) && g.compilingCoreLibrary
conditionalDefines = conditionalDefines
isInternalTestSpanStackReferring = isInternalTestSpanStackReferring
diagnosticOptions = diagnosticOptions
Expand Down
7 changes: 3 additions & 4 deletions src/Compiler/Checking/CheckComputationExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3465,7 +3465,7 @@ let TcSequenceExpressionEntry (cenv: cenv) env (overallTy: OverallTy) tpenv (has
errorR (Error(FSComp.SR.tcInvalidObjectSequenceOrRecordExpression (), m))
| _ -> ()

if not hasBuilder && not cenv.g.compilingFSharpCore then
if not hasBuilder && not cenv.g.compilingCoreLibrary then
error (Error(FSComp.SR.tcInvalidSequenceExpressionSyntaxForm (), m))

TcSequenceExpression cenv env tpenv comp overallTy m
Expand All @@ -3490,7 +3490,7 @@ let TcArrayOrListComputedExpression (cenv: cenv) env (overallTy: OverallTy) tpen
let expr, tpenv = TcExpr cenv (MustEqual exprTy) env tpenv replacementExpr

let expr =
if cenv.g.compilingFSharpCore then
if cenv.g.compilingCoreLibrary then
expr
else
// We add a call to 'seq ... ' to make sure sequence expression compilation gets applied to the contents of the
Expand Down Expand Up @@ -3600,8 +3600,7 @@ let TcArrayOrListComputedExpression (cenv: cenv) env (overallTy: OverallTy) tpen
let expr = mkCoerceIfNeeded cenv.g exprTy (tyOfExpr cenv.g expr) expr

let expr =
if cenv.g.compilingFSharpCore then
//warning(Error(FSComp.SR.fslibUsingComputedListOrArray(), expr.Range))
if cenv.g.compilingCoreLibrary then
expr
else
// We add a call to 'seq ... ' to make sure sequence expression compilation gets applied to the contents of the
Expand Down
14 changes: 7 additions & 7 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ exception NotUpperCaseConstructorWithoutRQA of range: range

let CheckNamespaceModuleOrTypeName (g: TcGlobals) (id: Ident) =
// type names '[]' etc. are used in fslib
if not g.compilingFSharpCore && id.idText.IndexOfAny IllegalCharactersInTypeAndNamespaceNames <> -1 then
if not g.compilingCoreLibrary && id.idText.IndexOfAny IllegalCharactersInTypeAndNamespaceNames <> -1 then
errorR(Error(FSComp.SR.tcInvalidNamespaceModuleTypeUnionName(), id.idRange))

let CheckDuplicates (idf: _ -> Ident) k elems =
Expand Down Expand Up @@ -1556,7 +1556,7 @@ module MutRecBindingChecking =
//
// REVIEW: consider allowing an optimization switch to turn off these checks

let needsSafeStaticInit = not g.compilingFSharpCore
let needsSafeStaticInit = not g.compilingCoreLibrary

// We only need safe static init checks if there are some static field bindings (actually, we look for non-method bindings)
let hasStaticBindings =
Expand Down Expand Up @@ -2173,7 +2173,7 @@ module TyconConstraintInference =
assumedTycons |> Set.filter (fun tyconStamp ->
let tycon, structuralTypes = tab[tyconStamp]

if cenv.g.compilingFSharpCore &&
if cenv.g.compilingCoreLibrary &&
AugmentTypeDefinitions.TyconIsCandidateForAugmentationWithCompare g tycon &&
not (HasFSharpAttribute g g.attrib_StructuralComparisonAttribute tycon.Attribs) &&
not (HasFSharpAttribute g g.attrib_NoComparisonAttribute tycon.Attribs) then
Expand Down Expand Up @@ -2301,7 +2301,7 @@ module TyconConstraintInference =

let tycon, structuralTypes = tab[tyconStamp]

if cenv.g.compilingFSharpCore &&
if cenv.g.compilingCoreLibrary &&
AugmentTypeDefinitions.TyconIsCandidateForAugmentationWithEquals g tycon &&
not (HasFSharpAttribute g g.attrib_StructuralEqualityAttribute tycon.Attribs) &&
not (HasFSharpAttribute g g.attrib_NoEqualityAttribute tycon.Attribs) then
Expand Down Expand Up @@ -3341,7 +3341,7 @@ module EstablishTypeDefinitionCores =
let hasAbstractAttr = HasFSharpAttribute g g.attrib_AbstractClassAttribute attrs
let hasSealedAttr =
// The special case is needed for 'unit' because the 'Sealed' attribute is not yet available when this type is defined.
if g.compilingFSharpCore && id.idText = "Unit" then
if g.compilingCoreLibrary && id.idText = "Unit" then
Some true
else
TryFindFSharpBoolAttribute g g.attrib_SealedAttribute attrs
Expand Down Expand Up @@ -3387,7 +3387,7 @@ module EstablishTypeDefinitionCores =

let hiddenReprChecks hasRepr =
structLayoutAttributeCheck false
if hasSealedAttr = Some false || (hasRepr && hasSealedAttr <> Some true && not (id.idText = "Unit" && g.compilingFSharpCore) ) then
if hasSealedAttr = Some false || (hasRepr && hasSealedAttr <> Some true && not (id.idText = "Unit" && g.compilingCoreLibrary) ) then
errorR(Error(FSComp.SR.tcRepresentationOfTypeHiddenBySignature(), m))
if hasAbstractAttr then
errorR (Error(FSComp.SR.tcOnlyClassesCanHaveAbstract(), m))
Expand Down Expand Up @@ -4190,7 +4190,7 @@ module TcDeclarations =
| _ ->
//false
// There is a special case we allow when compiling FSharp.Core.dll which permits interface implementations across namespace fragments
g.compilingFSharpCore && tcref.LogicalName.StartsWithOrdinal("Tuple`")
g.compilingCoreLibrary && tcref.LogicalName.StartsWithOrdinal("Tuple`")

let nReqTypars = reqTypars.Length

Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ let ComputeAccessAndCompPath (g:TcGlobals) env (declKindOpt: DeclKind option) m
let CheckForAbnormalOperatorNames (cenv: cenv) (idRange: range) coreDisplayName (memberInfoOpt: ValMemberInfo option) =
let g = cenv.g
if (idRange.EndColumn - idRange.StartColumn <= 5) &&
not g.compilingFSharpCore
not g.compilingCoreLibrary
then
let opName = ConvertValLogicalNameToDisplayNameCore coreDisplayName
let isMember = memberInfoOpt.IsSome
Expand Down Expand Up @@ -10590,13 +10590,13 @@ and TcStaticOptimizationConstraint cenv env tpenv c =

match c with
| SynStaticOptimizationConstraint.WhenTyparTyconEqualsTycon(tp, ty, m) ->
if not g.compilingFSharpCore then
if not g.compilingCoreLibrary then
errorR(Error(FSComp.SR.tcStaticOptimizationConditionalsOnlyForFSharpLibrary(), m))
let tyR, tpenv = TcType cenv NewTyparsOK CheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv ty
let tpR, tpenv = TcTypar cenv env NewTyparsOK tpenv tp
TTyconEqualsTycon(mkTyparTy tpR, tyR), tpenv
| SynStaticOptimizationConstraint.WhenTyparIsStruct(tp, m) ->
if not g.compilingFSharpCore then
if not g.compilingCoreLibrary then
errorR(Error(FSComp.SR.tcStaticOptimizationConditionalsOnlyForFSharpLibrary(), m))
let tpR, tpenv = TcTypar cenv env NewTyparsOK tpenv tp
TTyconIsStruct(mkTyparTy tpR), tpenv
Expand Down
12 changes: 6 additions & 6 deletions src/Compiler/Checking/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ let rec CheckTypeDeep (cenv: cenv) (visitTy, visitTyconRefOpt, visitAppTyOpt, vi
| _ -> ()

let ty =
if g.compilingFSharpCore then
if g.compilingCoreLibrary then
match stripTyparEqns ty with
// When compiling FSharp.Core, do not strip type equations at this point if we can't dereference a tycon.
| TType_app (tcref, _, _) when not tcref.CanDeref -> ty
Expand Down Expand Up @@ -659,7 +659,7 @@ let CheckTypeAux permitByRefLike (cenv: cenv) env m ty onInnerByrefError =
match info with
| FSMethSln(_, vref, _, _) ->
//printfn "considering %s..." vref.DisplayName
if valRefInThisAssembly cenv.g.compilingFSharpCore vref && not (cenv.boundVals.ContainsKey(vref.Stamp)) then
if valRefInThisAssembly cenv.g.compilingCoreLibrary vref && not (cenv.boundVals.ContainsKey(vref.Stamp)) then
//printfn "recording %s..." vref.DisplayName
cenv.potentialUnboundUsesOfVals <- cenv.potentialUnboundUsesOfVals.Add(vref.Stamp, m)
| _ -> ()
Expand Down Expand Up @@ -1768,7 +1768,7 @@ and CheckLambdas isTop (memberVal: Val option) cenv env inlined valReprInfo alwa
CheckNoReraise cenv freesOpt body

// Check the body of the lambda
if isTop && not g.compilingFSharpCore && isByrefLikeTy g m bodyTy then
if isTop && not g.compilingCoreLibrary && isByrefLikeTy g m bodyTy then
// allow byref to occur as return position for byref-typed top level function or method
CheckExprPermitReturnableByRef cenv env body |> ignore
else
Expand All @@ -1780,7 +1780,7 @@ and CheckLambdas isTop (memberVal: Val option) cenv env inlined valReprInfo alwa
CheckForByrefLikeType cenv env m bodyTy (fun () ->
errorR(Error(FSComp.SR.chkFirstClassFuncNoByref(), m)))

elif not g.compilingFSharpCore && isByrefTy g bodyTy then
elif not g.compilingCoreLibrary && isByrefTy g bodyTy then
// check no byrefs-in-the-byref
CheckForByrefType cenv env (destByrefTy g bodyTy) (fun () ->
errorR(Error(FSComp.SR.chkReturnTypeNoByref(), m)))
Expand Down Expand Up @@ -2112,7 +2112,7 @@ let CheckModuleBinding cenv env (TBind(v, e, _) as bind) =
IsSimpleSyntacticConstantExpr g e &&
// Check the thing is actually compiled as a property
IsCompiledAsStaticProperty g v ||
(g.compilingFSharpCore && v.Attribs |> List.exists(fun (Attrib(tc, _, _, _, _, _, _)) -> tc.CompiledName = "ValueAsStaticPropertyAttribute"))
(g.compilingCoreLibrary && v.Attribs |> List.exists(fun (Attrib(tc, _, _, _, _, _, _)) -> tc.CompiledName = "ValueAsStaticPropertyAttribute"))
then
v.SetIsCompiledAsStaticPropertyWithoutField()

Expand Down Expand Up @@ -2545,7 +2545,7 @@ let CheckEntityDefn cenv env (tycon: Entity) =
| None -> ()
| Some ty ->
// Library-defined outref<'T> and inref<'T> contain byrefs on the r.h.s.
if not g.compilingFSharpCore then
if not g.compilingCoreLibrary then
CheckForByrefType cenv env ty (fun () -> errorR(Error(FSComp.SR.chkNoByrefInTypeAbbrev(), tycon.Range)))

let CheckEntityDefns cenv env tycons =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/TailCallChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ and CheckLambdas
destLambdaWithValReprInfo g cenv.amap valReprInfo (expr, ety)

// Check the body of the lambda
if isTop && not g.compilingFSharpCore && isByrefLikeTy g m bodyTy then
if isTop && not g.compilingCoreLibrary && isByrefLikeTy g m bodyTy then
// allow byref to occur as return position for byref-typed top level function or method
CheckExprPermitReturnableByRef cenv body
else
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Checking/infos.fs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ type MethInfo =
/// Indicates if this is a method defined in this assembly with an internal XML comment
member x.HasDirectXmlComment =
match x with
| FSMeth(g, _, vref, _) -> valRefInThisAssembly g.compilingFSharpCore vref
| FSMeth(g, _, vref, _) -> valRefInThisAssembly g.compilingCoreLibrary vref
#if !NO_TYPEPROVIDERS
| ProvidedMeth _ -> true
#endif
Expand Down Expand Up @@ -1720,7 +1720,7 @@ type PropInfo =
member x.HasDirectXmlComment =
match x with
| FSProp(g, _, Some vref, _)
| FSProp(g, _, _, Some vref) -> valRefInThisAssembly g.compilingFSharpCore vref
| FSProp(g, _, _, Some vref) -> valRefInThisAssembly g.compilingCoreLibrary vref
#if !NO_TYPEPROVIDERS
| ProvidedProp _ -> true
#endif
Expand Down
Loading
Loading