Skip to content

Commit

Permalink
Revert "Multi-assembly+debug emit for FSI (#12722)"
Browse files Browse the repository at this point in the history
This reverts commit 45518d2.
  • Loading branch information
KevinRansom committed Feb 24, 2022
1 parent 78ef2ed commit 89431cb
Show file tree
Hide file tree
Showing 90 changed files with 5,674 additions and 9,474 deletions.
4 changes: 4 additions & 0 deletions docs/debug-emit.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,7 @@ Some design-time services are un-implemented by F#:
* Unimplemented: [Proximity expressions](https://github.com/dotnet/fsharp/issues/4271) (for Autos window)

These are major holes in the F# experience and should be implemented.

### Missing debug emit for F# Interactive

For F# Interactive [we do not currently emit debug information for script code](https://github.com/dotnet/fsharp/issues/5457). This is because of a missing piece of functionality in the Reflection.Emit APIs, and means we have to change our approach to emitting code fragments in F# Interactive to no longer use dynamic assemblies.
84 changes: 0 additions & 84 deletions docs/fsi-emit.md

This file was deleted.

8 changes: 5 additions & 3 deletions src/fsharp/AttributeChecking.fs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type AttribInfo =
/// Check custom attributes. This is particularly messy because custom attributes come in in three different
/// formats.
let AttribInfosOfIL g amap scoref m (attribs: ILAttributes) =
attribs.AsList() |> List.map (fun a -> ILAttribInfo (g, amap, scoref, a, m))
attribs.AsList |> List.map (fun a -> ILAttribInfo (g, amap, scoref, a, m))

let AttribInfosOfFS g attribs =
attribs |> List.map (fun a -> FSAttribInfo (g, a))
Expand Down Expand Up @@ -443,7 +443,7 @@ let MethInfoIsUnseen g (m: range) (ty: TType) minfo =
// We are only interested in filtering out the method on System.Object, so it is sufficient
// just to look at the attributes on IL methods.
if tcref.IsILTycon then
tcref.ILTyconRawMetadata.CustomAttrs.AsArray()
tcref.ILTyconRawMetadata.CustomAttrs.AsArray
|> Array.exists (fun attr -> attr.Method.DeclaringType.TypeSpec.Name = typeof<TypeProviderEditorHideMethodsAttribute>.FullName)
else
false
Expand All @@ -452,7 +452,9 @@ let MethInfoIsUnseen g (m: range) (ty: TType) minfo =
false
#endif

isUnseenByObsoleteAttrib () || isUnseenByHidingAttribute ()
//let isUnseenByBeingTupleMethod () = isAnyTupleTy g ty

isUnseenByObsoleteAttrib () || isUnseenByHidingAttribute () //|| isUnseenByBeingTupleMethod ()

/// Indicate if a property has 'Obsolete' or 'CompilerMessageAttribute'.
/// Used to suppress the item in intellisense.
Expand Down
23 changes: 8 additions & 15 deletions src/fsharp/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -447,27 +447,27 @@ type TcConfigBuilder =
mutable showTimes: bool
mutable showLoadedAssemblies: bool
mutable continueAfterParseFailure: bool

#if !NO_EXTENSIONTYPING
/// show messages about extension type resolution?
mutable showExtensionTypeMessages: bool
#endif

/// Pause between passes?
/// pause between passes?
mutable pause: bool

/// Whenever possible, emit callvirt instead of call
/// whenever possible, emit callvirt instead of call
mutable alwaysCallVirt: bool

/// If true, strip away data that would not be of use to end users, but is useful to us for debugging
/// if true, strip away data that would not be of use to end users, but is useful to us for debugging
// REVIEW: "stripDebugData"?
mutable noDebugAttributes: bool

/// If true, indicates all type checking and code generation is in the context of fsi.exe
/// if true, indicates all type checking and code generation is in the context of fsi.exe
isInteractive: bool

isInvalidationSupported: bool

/// If true - every expression in quotations will be augmented with full debug info (filename, location in file)
/// used to log sqm data
/// if true - every expression in quotations will be augmented with full debug info (filename, location in file)
mutable emitDebugInfoInQuotations: bool

mutable exename: string option
Expand All @@ -477,14 +477,9 @@ type TcConfigBuilder =

/// When false FSI will lock referenced assemblies requiring process restart, false = disable Shadow Copy false (*default*)
mutable shadowCopyReferences: bool

mutable useSdkRefs: bool

mutable fxResolver: FxResolver option

// Is F# Interactive using multi-assembly emit?
mutable fsiMultiAssemblyEmit: bool

/// specify the error range for FxResolver
rangeForErrors: range

Expand Down Expand Up @@ -665,7 +660,6 @@ type TcConfigBuilder =
shadowCopyReferences = false
useSdkRefs = true
fxResolver = None
fsiMultiAssemblyEmit = true
internalTestSpanStackReferring = false
noConditionalErasure = false
pathMap = PathMap.empty
Expand Down Expand Up @@ -927,7 +921,6 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
#endif
None, data.legacyReferenceResolver.Impl.HighestInstalledNetFrameworkVersion()

member _.fsiMultiAssemblyEmit = data.fsiMultiAssemblyEmit
member x.FxResolver = data.FxResolver
member x.primaryAssembly = data.primaryAssembly
member x.noFeedback = data.noFeedback
Expand Down
4 changes: 0 additions & 4 deletions src/fsharp/CompilerConfig.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ type TcConfigBuilder =
mutable shadowCopyReferences: bool
mutable useSdkRefs: bool
mutable fxResolver: FxResolver option
mutable fsiMultiAssemblyEmit: bool
rangeForErrors: range
sdkDirOverride: string option

Expand Down Expand Up @@ -459,9 +458,6 @@ type TcConfig =
member isInteractive: bool
member isInvalidationSupported: bool

/// Indicates if F# Interactive is using single-assembly emit via Reflection.Emit, where internals are available.
member fsiMultiAssemblyEmit: bool

member xmlDocInfoLoader: IXmlDocumentationInfoLoader option

member FxResolver: FxResolver
Expand Down
14 changes: 7 additions & 7 deletions src/fsharp/CompilerImports.fs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ let MakeScopeRefForILModule (ilModule: ILModuleDef) =
| None -> ILScopeRef.Module (mkRefToILModule ilModule)

let GetCustomAttributesOfILModule (ilModule: ILModuleDef) =
(match ilModule.Manifest with Some m -> m.CustomAttrs | None -> ilModule.CustomAttrs).AsList()
(match ilModule.Manifest with Some m -> m.CustomAttrs | None -> ilModule.CustomAttrs).AsList

let GetAutoOpenAttributes ilModule =
ilModule |> GetCustomAttributesOfILModule |> List.choose TryFindAutoOpenAttr
Expand All @@ -669,7 +669,7 @@ type RawFSharpAssemblyDataBackedByFileOnDisk (ilModule: ILModuleDef, ilAssemblyR
member _.TryGetILModuleDef() = Some ilModule

member _.GetRawFSharpSignatureData(m, ilShortAssemName, filename) =
let resources = ilModule.Resources.AsList()
let resources = ilModule.Resources.AsList
let sigDataReaders =
[ for iresource in resources do
if IsSignatureDataResource iresource then
Expand All @@ -688,7 +688,7 @@ type RawFSharpAssemblyDataBackedByFileOnDisk (ilModule: ILModuleDef, ilAssemblyR

member _.GetRawFSharpOptimizationData(m, ilShortAssemName, filename) =
let optDataReaders =
ilModule.Resources.AsList()
ilModule.Resources.AsList
|> List.choose (fun r -> if IsOptimizationDataResource r then Some(GetOptimizationDataResourceName r, (fun () -> r.GetBytes())) else None)

// Look for optimization data in a file
Expand Down Expand Up @@ -733,14 +733,14 @@ type RawFSharpAssemblyData (ilModule: ILModuleDef, ilAssemblyRefs) =
member _.TryGetILModuleDef() = Some ilModule

member _.GetRawFSharpSignatureData(_, _, _) =
let resources = ilModule.Resources.AsList()
let resources = ilModule.Resources.AsList
[ for iresource in resources do
if IsSignatureDataResource iresource then
let ccuName = GetSignatureDataResourceName iresource
yield (ccuName, fun () -> iresource.GetBytes()) ]

member _.GetRawFSharpOptimizationData(_, _, _) =
ilModule.Resources.AsList()
ilModule.Resources.AsList
|> List.choose (fun r -> if IsOptimizationDataResource r then Some(GetOptimizationDataResourceName r, (fun () -> r.GetBytes())) else None)

member _.GetRawTypeForwarders() =
Expand Down Expand Up @@ -1499,7 +1499,7 @@ and [<Sealed>] TcImports(tcConfigP: TcConfigProvider, initialResolutions: TcAsse

let phase2 () =
#if !NO_EXTENSIONTYPING
ccuinfo.TypeProviders <- tcImports.ImportTypeProviderExtensions (ctok, tcConfig, filename, ilScopeRef, ilModule.ManifestOfAssembly.CustomAttrs.AsList(), ccu.Contents, invalidateCcu, m)
ccuinfo.TypeProviders <- tcImports.ImportTypeProviderExtensions (ctok, tcConfig, filename, ilScopeRef, ilModule.ManifestOfAssembly.CustomAttrs.AsList, ccu.Contents, invalidateCcu, m)
#endif
[ResolvedImportedAssembly ccuinfo]
phase2
Expand Down Expand Up @@ -1593,7 +1593,7 @@ and [<Sealed>] TcImports(tcConfigP: TcConfigProvider, initialResolutions: TcAsse
match ilModule.TryGetILModuleDef() with
| None -> () // no type providers can be used without a real IL Module present
| Some ilModule ->
let tps = tcImports.ImportTypeProviderExtensions (ctok, tcConfig, filename, ilScopeRef, ilModule.ManifestOfAssembly.CustomAttrs.AsList(), ccu.Contents, invalidateCcu, m)
let tps = tcImports.ImportTypeProviderExtensions (ctok, tcConfig, filename, ilScopeRef, ilModule.ManifestOfAssembly.CustomAttrs.AsList, ccu.Contents, invalidateCcu, m)
ccuinfo.TypeProviders <- tps
#else
()
Expand Down
34 changes: 17 additions & 17 deletions src/fsharp/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1565,11 +1565,11 @@ type TypeDefBuilder(tdef: ILTypeDef, tdefDiscards) =
let gnested = TypeDefsBuilder()

member b.Close() =
tdef.With(methods = mkILMethods (tdef.Methods.AsList() @ ResizeArray.toList gmethods),
fields = mkILFields (tdef.Fields.AsList() @ ResizeArray.toList gfields),
properties = mkILProperties (tdef.Properties.AsList() @ HashRangeSorted gproperties ),
events = mkILEvents (tdef.Events.AsList() @ ResizeArray.toList gevents),
nestedTypes = mkILTypeDefs (tdef.NestedTypes.AsList() @ gnested.Close()))
tdef.With(methods = mkILMethods (tdef.Methods.AsList @ ResizeArray.toList gmethods),
fields = mkILFields (tdef.Fields.AsList @ ResizeArray.toList gfields),
properties = mkILProperties (tdef.Properties.AsList @ HashRangeSorted gproperties ),
events = mkILEvents (tdef.Events.AsList @ ResizeArray.toList gevents),
nestedTypes = mkILTypeDefs (tdef.NestedTypes.AsList @ gnested.Close()))

member b.AddEventDef edef = gevents.Add edef

Expand Down Expand Up @@ -1618,11 +1618,11 @@ and TypeDefsBuilder() =
let tdef = b.Close()
// Skip the <PrivateImplementationDetails$> type if it is empty
if not eliminateIfEmpty
|| not (tdef.NestedTypes.AsList()).IsEmpty
|| not (tdef.Fields.AsList()).IsEmpty
|| not (tdef.Events.AsList()).IsEmpty
|| not (tdef.Properties.AsList()).IsEmpty
|| not (Array.isEmpty (tdef.Methods.AsArray())) then
|| not tdef.NestedTypes.AsList.IsEmpty
|| not tdef.Fields.AsList.IsEmpty
|| not tdef.Events.AsList.IsEmpty
|| not tdef.Properties.AsList.IsEmpty
|| not (Array.isEmpty tdef.Methods.AsArray) then
yield tdef ]

member b.FindTypeDefBuilder nm =
Expand Down Expand Up @@ -1704,9 +1704,7 @@ type AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbu
let ilFieldDefs =
mkILFields
[ for _, fldName, fldTy in flds ->
// The F# Interactive backend may split to multiple assemblies.
let access = (if cenv.opts.isInteractive then ILMemberAccess.Public else ILMemberAccess.Private)
let fdef = mkILInstanceField (fldName, fldTy, None, access)
let fdef = mkILInstanceField (fldName, fldTy, None, ILMemberAccess.Private)
fdef.With(customAttrs = mkILCustomAttrs [ g.DebuggerBrowsableNeverAttribute ]) ]

// Generate property definitions for the fields compiled as properties
Expand Down Expand Up @@ -4590,7 +4588,7 @@ and GenFormalReturnType m cenv eenvFormal returnTy : ILReturn =
| None -> ilRet
| Some ty ->
match GenReadOnlyAttributeIfNecessary cenv.g ty with
| Some attr -> ilRet.WithCustomAttrs (mkILCustomAttrs (ilRet.CustomAttrs.AsList() @ [attr]))
| Some attr -> ilRet.WithCustomAttrs (mkILCustomAttrs (ilRet.CustomAttrs.AsList @ [attr]))
| None -> ilRet

and instSlotParam inst (TSlotParam(nm, ty, inFlag, fl2, fl3, attrs)) =
Expand Down Expand Up @@ -5096,7 +5094,7 @@ and GenStaticDelegateClosureTypeDefs cenv (tref: ILTypeRef, ilGenParams, attrs,
// Apply the abstract attribute, turning the sealed class into abstract sealed (i.e. static class).
// Remove the redundant constructor.
tdefs |> List.map (fun td -> td.WithAbstract(true)
.With(methods= mkILMethodsFromArray (td.Methods.AsArray() |> Array.filter (fun m -> not m.IsConstructor))))
.With(methods= mkILMethodsFromArray (td.Methods.AsArray |> Array.filter (fun m -> not m.IsConstructor))))

and GenGenericParams cenv eenv tps =
tps |> DropErasedTypars |> List.map (GenGenericParam cenv eenv)
Expand Down Expand Up @@ -8650,7 +8648,9 @@ open System

/// The lookup* functions are the conversions available from ilreflect.
type ExecutionContext =
{ LookupTypeRef: ILTypeRef -> Type
{ LookupFieldRef: ILFieldRef -> FieldInfo
LookupMethodRef: ILMethodRef -> MethodInfo
LookupTypeRef: ILTypeRef -> Type
LookupType: ILType -> Type }

// A helper to generate a default value for any System.Type. I couldn't find a System.Reflection
Expand All @@ -8672,7 +8672,7 @@ let LookupGeneratedValue (amap: ImportMap) (ctxt: ExecutionContext) eenv (v: Val
try
// Convert the v.Type into a System.Type according to ilxgen and ilreflect.
let objTyp() =
let ilTy = GenType amap v.Range TypeReprEnv.Empty v.Type
let ilTy = GenType amap v.Range TypeReprEnv.Empty v.Type (* TypeReprEnv.Empty ok, not expecting typars *)
ctxt.LookupType ilTy
// Lookup the compiled v value (as an object).
match StorageForVal amap.g v.Range v eenv with
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/IlxGen.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type public IlxGenResults =
/// Used to support the compilation-inversion operations "ClearGeneratedValue" and "LookupGeneratedValue"
type ExecutionContext =
{
LookupFieldRef: ILFieldRef -> FieldInfo
LookupMethodRef: ILMethodRef -> MethodInfo
LookupTypeRef: ILTypeRef -> Type
LookupType: ILType -> Type
}
Expand Down
Loading

0 comments on commit 89431cb

Please sign in to comment.