Skip to content

Commit

Permalink
fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom committed Dec 20, 2022
1 parent 25f3252 commit 81da03f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 52 deletions.
Binary file added a
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CreateILModule.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ open FSharp.Compiler.TypedTree
/// Represents the configuration settings used to perform strong-name signing
type StrongNameSigningInfo

/// Get the SsigningInfo for specific values(delaysign, tcConfig.publicsign, signer, container)
/// Get the SigningInfo for specific values(delaysign, tcConfig.publicsign, signer, container)
val GetStrongNameSigningInfo:
delaysign: bool * publicsign: bool * signer: byte array option * container: string option -> StrongNameSigningInfo

Expand Down
38 changes: 19 additions & 19 deletions src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1380,8 +1380,6 @@ type internal FsiDynamicCompiler(

let rangeStdin0 = rangeN stdinMockFileName 0

//let _writer = moduleBuilder.GetSymWriter()

let infoReader = InfoReader(tcGlobals,tcImports.GetImportMap())

let reportedAssemblies = Dictionary<string, DateTime>()
Expand Down Expand Up @@ -1413,7 +1411,8 @@ type internal FsiDynamicCompiler(
]
{ manifest with
Name = multiAssemblyName
Version = Some (parseILVersion $"0.0.0.{dynamicAssemblyId}")
// Because the coreclr loader will not load a higher assembly make versions go downwards
Version = Some (parseILVersion $"0.0.0.{5000 - dynamicAssemblyId}")
CustomAttrsStored = storeILCustomAttrs (mkILCustomAttrs attrs)
}

Expand Down Expand Up @@ -1476,18 +1475,23 @@ type internal FsiDynamicCompiler(
yield! loop (enc@[tdef]) ntdef ]
[ for tdef in ilxMainModule.TypeDefs do yield! loop [] tdef ]

// Make the 'exec' functions for the entry point initializations
let execs =
let execs =
[ for edef in entries do
if edef.ArgCount = 0 then
yield
(fun () ->
yield (fun () ->
let typ = asm.GetType(edef.DeclaringTypeRef.BasicQualifiedName)
try
ignore (typ.InvokeMember (edef.Name, BindingFlags.InvokeMethod ||| BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.Static, null, null, [| |], Globalization.CultureInfo.InvariantCulture))
None
with :? TargetInvocationException as e ->
Some e.InnerException) ]
with
//| :? TargetInvocationException as e when e.InnerException.GetType() = typeof<TypeLoadException> ->
// ignore (typ.InvokeMember (edef.Name, BindingFlags.InvokeMethod ||| BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.Static, null, null, [| |], Globalization.CultureInfo.InvariantCulture))
// File.WriteAllBytes($"""c:\temp\FSI-ASSEMBLY-{dynamicAssemblyId} - {Guid.NewGuid()}""", assemblyBytes)
// None
// //Some e.InnerException
| :? TargetInvocationException as e ->
Some e.InnerException)
]

emEnv.AddModuleDef asm ilScopeRef ilxMainModule

Expand Down Expand Up @@ -1707,11 +1711,10 @@ type internal FsiDynamicCompiler(

let nextFragmentId() =
fragmentId <- fragmentId + 1
fragmentId
$"%04d{fragmentId}"

let mkFragmentPath m i =
// NOTE: this text shows in exn traces and type names. Make it clear and fixed width
[mkSynId m (FsiDynamicModulePrefix + sprintf "%04d" i)]
let mkFragmentPath m fragmentId =
[mkSynId m (FsiDynamicModulePrefix + fragmentId())]

let processContents istate declaredImpls =
let tcState = istate.tcState
Expand Down Expand Up @@ -1836,8 +1839,7 @@ type internal FsiDynamicCompiler(
dynamicAssemblies |> ResizeArray.tryFind (fun asm -> getName (asm.GetName()) = name)

member _.EvalParsedSourceFiles (ctok, diagnosticsLogger, istate, inputs, m) =
let i = nextFragmentId()
let prefix = mkFragmentPath m i
let prefix = mkFragmentPath m nextFragmentId
// Ensure the path includes the qualifying name
let inputs = inputs |> List.map (PrependPathToInput prefix)
let isIncrementalFragment = false
Expand All @@ -1847,9 +1849,8 @@ type internal FsiDynamicCompiler(
/// Evaluate the given definitions and produce a new interactive state.
member _.EvalParsedDefinitions (ctok, diagnosticsLogger: DiagnosticsLogger, istate, showTypes, isInteractiveItExpr, defs: SynModuleDecl list) =
let fileName = stdinMockFileName
let i = nextFragmentId()
let m = match defs with [] -> rangeStdin0 | _ -> List.reduce unionRanges [for d in defs -> d.Range]
let prefix = mkFragmentPath m i
let prefix = mkFragmentPath m nextFragmentId
let prefixPath = pathOfLid prefix
let impl = SynModuleOrNamespace(prefix,false, SynModuleOrNamespaceKind.NamedModule,defs,PreXmlDoc.Empty,[],None,m, { LeadingKeyword = SynModuleOrNamespaceLeadingKeyword.None })
let isLastCompiland = true
Expand Down Expand Up @@ -2203,9 +2204,8 @@ type internal FsiDynamicCompiler(
let ty = List.head tys
let amap = istate.tcImports.GetImportMap()

let i = nextFragmentId()
let m = rangeStdin0
let prefix = mkFragmentPath m i
let prefix = mkFragmentPath m nextFragmentId
let prefixPath = pathOfLid prefix
let qualifiedName = ComputeQualifiedNameOfFileFromUniquePath (m,prefixPath)

Expand Down
77 changes: 45 additions & 32 deletions tests/FSharp.Compiler.UnitTests/FsiTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Sentinel () =
module MyModule =
let test(x: int) = ()

[<Collection("SingleThreaded")>]
[<CollectionDefinition("FsiTests", DisableParallelization = true)>]
module FsiTests =

let createFsiSession (useOneDynamicAssembly: bool) =
Expand Down Expand Up @@ -646,35 +646,48 @@ module FsiTests =

#if NETCOREAPP
[<Fact>]
let ``Evaluating simple reference and code succeeds under permutations``() =

for useSdkRefsFlag in ["/usesdkrefs"; "/usesdkrefs-"] do
for multiemitFlag in ["/multiemit"; "/multiemit-"] do
let config = FsiEvaluationSession.GetDefaultConfiguration()
let argv = [|
typeof<Sentinel>.Assembly.Location
"--noninteractive"
"--targetprofile:netcore"
"--langversion:preview"
multiemitFlag
useSdkRefsFlag
|]
let fsi = FsiEvaluationSession.Create(config, argv, TextReader.Null, TextWriter.Null, TextWriter.Null)
let assemblyPath = typeof<Sentinel>.Assembly.Location.Replace("\\", "/")
let code = $@"
#r ""{assemblyPath}""
FSharp.Compiler.UnitTests.MyModule.test(3)"
let ch, errors = fsi.EvalInteractionNonThrowing(code, CancellationToken.None)
errors
|> Array.iter (fun e -> printfn "error: %A" e)
match ch with
| Choice1Of2 v ->
let v =
match v with
| Some v -> sprintf "%A" v.ReflectionValue
| None -> "(none)"
printfn "value: %A" v
| Choice2Of2 e ->
printfn "exception: %A" e
raise e
let ``Evaluating simple reference and code succeeds with multiemit on``() =

use fsiSession = createFsiSession false
let assemblyPath = typeof<Sentinel>.Assembly.Location.Replace("\\", "/")
let res, errors = fsiSession.EvalInteractionNonThrowing($"""
#r "{assemblyPath}"
FSharp.Compiler.UnitTests.MyModule.test(3)""")

errors
|> Array.iter (fun e -> printfn "error: %A" e)

match res with
| Choice1Of2 v ->
let v =
match v with
| Some v -> sprintf "%A" v.ReflectionValue
| None -> "(none)"
printfn "value: %A" v
| Choice2Of2 e ->
printfn "exception: %A" e
raise e

[<Fact>]
let ``Evaluating simple reference and code succeeds with multiemit off``() =

use fsiSession = createFsiSession true
let assemblyPath = typeof<Sentinel>.Assembly.Location.Replace("\\", "/")
let res, errors = fsiSession.EvalInteractionNonThrowing($"""
#r "{assemblyPath}"
FSharp.Compiler.UnitTests.MyModule.test(3)""")

errors
|> Array.iter (fun e -> printfn "error: %A" e)

match res with
| Choice1Of2 v ->
let v =
match v with
| Some v -> sprintf "%A" v.ReflectionValue
| None -> "(none)"
printfn "value: %A" v
| Choice2Of2 e ->
printfn "exception: %A" e
raise e
#endif

0 comments on commit 81da03f

Please sign in to comment.