Skip to content

Commit 8854f5d

Browse files
authored
fix records in multiemit (#12889) (#12935)
* fix records in multiemit * fix build * fix test
1 parent 31803ec commit 8854f5d

26 files changed

+93
-27855
lines changed

src/fsharp/IlxGen.fs

+14-3
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ type IlxGenOptions =
221221

222222
ilxBackend: IlxGenBackend
223223

224+
fsiMultiAssemblyEmit: bool
225+
224226
/// Indicates the code is being generated in FSI.EXE and is executed immediately after code generation
225227
/// This includes all interactively compiled code, including #load, definitions, and expressions
226228
isInteractive: bool
@@ -1722,8 +1724,10 @@ type AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbu
17221724
let ilFieldDefs =
17231725
mkILFields
17241726
[ for _, fldName, fldTy in flds ->
1725-
// The F# Interactive backend may split to multiple assemblies.
1726-
let access = (if cenv.opts.isInteractive then ILMemberAccess.Public else ILMemberAccess.Private)
1727+
// Don't hide fields when splitting to multiple assemblies.
1728+
let access =
1729+
if cenv.opts.isInteractive && cenv.opts.fsiMultiAssemblyEmit then ILMemberAccess.Public
1730+
else ILMemberAccess.Private
17271731
let fdef = mkILInstanceField (fldName, fldTy, None, access)
17281732
fdef.With(customAttrs = mkILCustomAttrs [ g.DebuggerBrowsableNeverAttribute ]) ]
17291733

@@ -8060,14 +8064,21 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) =
80608064
// The IL field is hidden if the property/field is hidden OR we're using a property
80618065
// AND the field is not mutable (because we can take the address of a mutable field).
80628066
// Otherwise fields are always accessed via their property getters/setters
8063-
let isFieldHidden = isPropHidden || (not useGenuineField && not isFSharpMutable)
8067+
//
8068+
// Additionally, don't hide fields for multiemit in F# Interactive
8069+
let isFieldHidden =
8070+
isPropHidden ||
8071+
(not useGenuineField &&
8072+
not isFSharpMutable &&
8073+
not (cenv.opts.isInteractive && cenv.opts.fsiMultiAssemblyEmit))
80648074

80658075
let extraAttribs =
80668076
match tyconRepr with
80678077
| TFSharpRecdRepr _ when not useGenuineField -> [ g.DebuggerBrowsableNeverAttribute ] // hide fields in records in debug display
80688078
| _ -> [] // don't hide fields in classes in debug display
80698079

80708080
let access = ComputeMemberAccess isFieldHidden
8081+
80718082
let literalValue = Option.map (GenFieldInit m) fspec.LiteralValue
80728083

80738084
let fdef =

src/fsharp/IlxGen.fsi

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ type internal IlxGenOptions =
4242
/// Indicates which backend we are generating code for
4343
ilxBackend: IlxGenBackend
4444

45+
/// Is --multiemit enabled?
46+
fsiMultiAssemblyEmit: bool
47+
4548
/// Indicates the code is being generated in FSI.EXE and is executed immediately after code generation
4649
/// This includes all interactively compiled code, including #load, definitions, and expressions
4750
isInteractive: bool

src/fsharp/OptimizeInputs.fs

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ let GenerateIlxCode
177177
testFlagEmitFeeFeeAs100001 = tcConfig.testFlagEmitFeeFeeAs100001
178178
mainMethodInfo= mainMethodInfo
179179
ilxBackend = ilxBackend
180+
fsiMultiAssemblyEmit = tcConfig.fsiMultiAssemblyEmit
180181
isInteractive = tcConfig.isInteractive
181182
isInteractiveItExpr = isInteractiveItExpr
182183
alwaysCallVirt = tcConfig.alwaysCallVirt }

0 commit comments

Comments
 (0)