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

FSI on coreclr with no cl args #3140

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DotnetCLIToolsVersion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0-preview3-003886
20 changes: 19 additions & 1 deletion init-tools.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ setlocal
set INIT_TOOLS_LOG=%~dp0init-tools.log
set PACKAGES_DIR=%~dp0packages\
set TOOLRUNTIME_DIR=%~dp0Tools
set DOTNET_PATH=%TOOLRUNTIME_DIR%\dotnetcli\
set DOTNET_PATH=%TOOLRUNTIME_DIR%\dotnet\
set DOTNET_TOOLS_PATH=%TOOLRUNTIME_DIR%\dotnetcli\
set DOTNET_TOOLS_CMD=%DOTNET_PATH%dotnet.exe
set DOTNET_CMD=%DOTNET_PATH%dotnet.exe
if [%BUILDTOOLS_SOURCE%]==[] set BUILDTOOLS_SOURCE=https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json
set /P BUILDTOOLS_VERSION=< "%~dp0BuildToolsVersion.txt"
Expand Down Expand Up @@ -39,6 +41,22 @@ if NOT exist "%PROJECT_JSON_PATH%" mkdir "%PROJECT_JSON_PATH%"
echo %PROJECT_JSON_CONTENTS% > "%PROJECT_JSON_FILE%"
echo Running %0 > "%INIT_TOOLS_LOG%"

set /p DOTNET_TOOLS_VERSION=< "%~dp0DotnetCLIToolsVersion.txt"
if exist "%DOTNET_TOOLS_PATH%" goto :afterdotnettoolsrestore

echo Installing dotnet OLD VERSION OF THE cli...
echo ==========================================
echo This is temporary until we build using the new dotnetcli
echo The dotnet cli is a large file it may take a few minutes ...
echo powershell -ExecutionPolicy unrestricted -NoProfile -Command ".\dotnet-install.ps1 -InstallDir %DOTNET_PATH% -Architecture x64 -Version %DOTNET_TOOLS_VERSION% -NoPath true; exit $LastExitCode;"
powershell -ExecutionPolicy unrestricted -NoProfile -Command ".\dotnet-install.ps1 -InstallDir %DOTNET_TOOLS_PATH% -Architecture x64 -Version %DOTNET_TOOLS_VERSION% -NoPath true; exit $LastExitCode;"
if errorlevel 1 (
echo ERROR: Could not install dotnet cli correctly.
set TOOLS_INIT_RETURN_CODE=1
goto :DONE
)
:afterdotnettoolsrestore

set /p DOTNET_VERSION=< "%~dp0DotnetCLIVersion.txt"
if exist "%DOTNET_CMD%" goto :afterdotnetrestore

Expand Down
17 changes: 7 additions & 10 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,7 @@ let DefaultReferencesForScriptsAndOutOfProjectSources(assumeDotNetFramework) =
let SystemAssemblies () =
HashSet
[ yield "mscorlib"
yield "System.PrivateCoreLib"
yield "System.Runtime"
yield GetFSharpCoreLibraryName()
yield "System"
Expand Down Expand Up @@ -2522,7 +2523,6 @@ let GetNameOfILModule (m: ILModuleDef) =
| Some manifest -> manifest.Name
| None -> m.Name


let MakeScopeRefForILModule (ilModule: ILModuleDef) =
match ilModule.Manifest with
| Some m -> ILScopeRef.Assembly (mkRefToILAssembly m)
Expand Down Expand Up @@ -2608,7 +2608,7 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
#if !ENABLE_MONO_SUPPORT
// TODO: we have to get msbuild out of this
if data.useSimpleResolution then
None, (0, ""), false
None, ((if runningOnMono then 0 else 4), ""), false
else
#endif
None, (4, data.legacyReferenceResolver.HighestInstalledNetFrameworkVersion()), false
Expand Down Expand Up @@ -2825,7 +2825,7 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
let apiFacades = Path.Combine(api, "Facades")
match tcConfig.resolutionEnvironment with
#if !FSI_TODO_NETCORE
// For F# Interactive code we must inly reference impementation assemblies
// For F# Interactive code we must only reference impementation assemblies
| ReferenceResolver.RuntimeLike ->
yield runtimeRoot
if Directory.Exists(rootFacades) then
Expand All @@ -2847,18 +2847,15 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
try
[
match tcConfig.resolutionEnvironment with
#if !FSI_TODO_NETCORE
| ReferenceResolver.RuntimeLike ->
yield System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()
#endif
| ReferenceResolver.RuntimeLike -> yield System.IO.Path.GetDirectoryName(typeof<obj>.Assembly.Location)
| _ ->
let frameworkRoot = tcConfig.legacyReferenceResolver.DotNetFrameworkReferenceAssembliesRootDirectory
let frameworkRootVersion = Path.Combine(frameworkRoot,tcConfig.targetFrameworkVersion)
yield frameworkRootVersion
let facades = Path.Combine(frameworkRootVersion, "Facades")
if Directory.Exists(facades) then
yield facades
]
if Directory.Exists(facades) then yield facades
yield System.IO.Path.GetDirectoryName(typeof<obj>.Assembly.Location)
]
with e ->
errorRecovery e range0; []

Expand Down
12 changes: 9 additions & 3 deletions src/fsharp/fsi/fsimain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ let evaluateSession(argv: string[]) =
let fsiTy = fsiAssembly.GetType("Microsoft.FSharp.Compiler.Interactive.Settings")
if isNull fsiAssembly then failwith "failed to find type Microsoft.FSharp.Compiler.Interactive.Settings in FSharp.Compiler.Interactive.Settings.dll"
Some (callStaticMethod fsiTy "get_fsi" [ ])

let fsiConfig0 =
match fsiObjOpt with
| None -> FsiEvaluationSession.GetDefaultConfiguration()
Expand Down Expand Up @@ -279,7 +279,13 @@ let evaluateSession(argv: string[]) =
member __.GetOptionalConsoleReadLine(probe) = getConsoleReadLine(probe) }

// Create the console
and fsiSession = FsiEvaluationSession.Create (fsiConfig, argv, Console.In, Console.Out, Console.Error, collectible=false, legacyReferenceResolver=MSBuildReferenceResolver.Resolver)
and fsiSession =
#if FX_RESHAPED_MSBUILD
let resolver = (SimulatedMSBuildReferenceResolver.GetBestAvailableResolver())
#else
let resolver = (MSBuildReferenceResolver.Resolver)
#endif
FsiEvaluationSession.Create (fsiConfig, argv, Console.In, Console.Out, Console.Error, collectible=false, legacyReferenceResolver=resolver)


#if !FX_NO_WINFORMS
Expand All @@ -293,7 +299,7 @@ let evaluateSession(argv: string[]) =
// Route GUI application exceptions to the exception handlers
Application.add_ThreadException(new ThreadExceptionEventHandler(fun _ args -> fsiSession.ReportUnhandledException args.Exception));

let runningOnMono = try System.Type.GetType("Mono.Runtime") <> null with e-> false
let runningOnMono = try System.Type.GetType("Mono.Runtime") <> null with _ -> false
if not runningOnMono then
try
TrySetUnhandledExceptionMode()
Expand Down
37 changes: 18 additions & 19 deletions src/utils/reshapedreflection.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.FSharp.Core
open System.IO
open System.Reflection

//Replacement for: System.Security.SecurityElement.Escape(line) All platforms
Expand Down Expand Up @@ -318,40 +319,38 @@ module internal ReflectionAdapters =
member this.GetGetMethod() = this.GetMethod
member this.GetSetMethod() = this.SetMethod

type System.Reflection.Assembly with
#if FX_RESHAPED_REFLECTION_CORECLR
let globalLoadContext = AssemblyLoadContext.Default

type CustomAssemblyResolver() =
inherit AssemblyLoadContext()
override this.Load (assemblyName:AssemblyName):Assembly =
this.LoadFromAssemblyName(assemblyName)
<<<<<<< HEAD
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks likes an unresolved merge conflict

static member LoadFrom(filename:string) =
globalLoadContext.LoadFromAssemblyPath(filename)

let globalLoadContext = new CustomAssemblyResolver()
static member UnsafeLoadFrom(filename:string) =
globalLoadContext.LoadFromAssemblyPath(filename)
=======
let globalLoadContext = AssemblyLoadContext.Default
>>>>>>> 7913fe5721e866bc283104054dd7bbf32b57d110

type System.Reflection.AssemblyName with
static member GetAssemblyName(path) =
System.Runtime.Loader.AssemblyLoadContext.GetAssemblyName(path)
#endif
type System.Reflection.Assembly with

member this.GetTypes() =
this.DefinedTypes
|> Seq.map (fun ti -> ti.AsType())
|> Seq.toArray

member this.GetExportedTypes() =
this.DefinedTypes
|> Seq.filter(fun ti -> ti.IsPublic)
|> Seq.map (fun ti -> ti.AsType())
|> Seq.toArray
member this.Location =
this.ManifestModule.FullyQualifiedName

#if FX_RESHAPED_REFLECTION_CORECLR
static member LoadFrom(filename:string) =
globalLoadContext.LoadFromAssemblyPath(filename)

static member UnsafeLoadFrom(filename:string) =
globalLoadContext.LoadFromAssemblyPath(filename)

type System.Reflection.AssemblyName with
static member GetAssemblyName(path) =
System.Runtime.Loader.AssemblyLoadContext.GetAssemblyName(path)
#endif
member this.Location =
this.ManifestModule.FullyQualifiedName

type System.Delegate with
static member CreateDelegate(delegateType, methodInfo : MethodInfo) = methodInfo.CreateDelegate(delegateType)
Expand Down