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

Globals and return types for script compilations should be surfaced as ITypeSymbol, not System.Type #20920

Open
abock opened this issue Jul 17, 2017 · 0 comments

Comments

@abock
Copy link
Contributor

abock commented Jul 17, 2017

Version Used: 2.3.0

Overview

Script compilations provide two facilities that currently tie the compilations to specific runtime host targets: return type and globals type (also called "host object type" in places).

In all public API necessary to create script compilations (e.g. Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CreateScriptCompilation Microsoft.CodeAnalysis.ProjectInfo), return type and globals object type are provided by the consumer of the API as a System.Type. In some cases (e.g. Xamarin Workbooks), these types must be reflection loaded in order to satisfy the Roslyn APIs.

Unfortunately, the reflection loading workaround no longer works when the assembly containing the type is a .NET core assembly (and Roslyn is running on .NET Framework / Desktop). This is currently preventing the Xamarin Workbooks team from cleanly providing support for .NET Core workbooks.

Fix Proposal

Roslyn needs an API audit to identify cases where System.Type is surfaced to the consumer. These APIs should be obsoleted and new ones provided that provide equivalent functionality through ITypeSymbol (or similar). This would allow the consumer of Roslyn to decide how to load the metadata (Cci, System.Reflection.Metadata, Cecil, etc.) and take no dependency on the runtime hosting Roslyn.

Further, a single name should be chosen for APIs representing the globals type. Currently this concept is called "host object type" and "globals type" in different APIs. I'd vote for "globals type" since it is more clear as to what the type is used for (surfacing "global" APIs to scripts).

Type Old API New API
M.CA.ScriptCompilationInfo System.Type GlobalsType ITypeSymbol GlobalsTypeSymbol
M.CA.ScriptCompilationInfo System.Type ReturnType ITypeSymbol ReturnTypeSymbol
M.CA.Scripting.Script System.Type GlobalsType ITypeSymbol GlobalsTypeSymbol
M.CA.Scripting.Script System.Type ReturnType ITypeSymbol ReturnTypeSymbol
M.CA.ProjectInfo System.Type HostObjectType ITypeSymbol GlobalsTypeSymbol

Note: this table is not a complete audit, nor does it cover method parameters, but changing public properties should allow everything else to become obvious.

Addendum

Independent of this issue, #20919 - the ReturnType API is not surfaced at all on Microsoft.CodeAnalysis.ProjectInfo. Fixing that issue should wait until this issue is addressed.

This is also somewhat related to / will affect similar code paths as #8506, which was fixed by #8507.

sandyarmstrong added a commit to microsoft/workbooks that referenced this issue Nov 2, 2017
Additionally, the Xamarin.Interactive.Shared project that was consumed
by each agent assembly is gone. All those types are now part of the
actual Xamarin.Interactive.dll. Same with
Xamarin.Interactive.Bootstrap.

InspectorSupport is no longer a partial class, because the shared
projects are gone now. But we need to keep the same API for Inspector
extension compatibility, and because that API is based on static
methods there's no helpful way to abstract any of it. So there is a
little duplication now.

Xamarin.Interactive.Facades is no longer necessary, and neither is the
PCL loading code in `UnifiedInspectorSupport`.

Xamarin.Forms has been bumped from 2.3.4.231 to 2.4.0.18342 for .NET
Standard 2.0 support.

`CompilationWorkspaceFactory` has to do some manual loading of
`Xamarin.Interactive.dll` and `netstandard.dll` now, but this will go
away when dotnet/roslyn#20920 gets fixed.
sandyarmstrong added a commit to microsoft/workbooks that referenced this issue Nov 3, 2017
Additionally, the Xamarin.Interactive.Shared project that was consumed
by each agent assembly is gone. All those types are now part of the
actual Xamarin.Interactive.dll. Same with
Xamarin.Interactive.Bootstrap.

InspectorSupport is no longer a partial class, because the shared
projects are gone now. But we need to keep the same API for Inspector
extension compatibility, and because that API is based on static
methods there's no helpful way to abstract any of it. So there is a
little duplication now.

Xamarin.Interactive.Facades is no longer necessary, and neither is the
PCL loading code in `UnifiedInspectorSupport`.

Xamarin.Forms has been bumped from 2.3.4.231 to 2.4.0.18342 for .NET
Standard 2.0 support.

`CompilationWorkspaceFactory` has to do some manual loading of
`Xamarin.Interactive.dll` and `netstandard.dll` now, but this will go
away when dotnet/roslyn#20920 gets fixed.
sandyarmstrong added a commit to microsoft/workbooks that referenced this issue Nov 3, 2017
Additionally, the Xamarin.Interactive.Shared project that was consumed
by each agent assembly is gone. All those types are now part of the
actual Xamarin.Interactive.dll. Same with
Xamarin.Interactive.Bootstrap.

InspectorSupport is no longer a partial class, because the shared
projects are gone now. But we need to keep the same API for Inspector
extension compatibility, and because that API is based on static
methods there's no helpful way to abstract any of it. So there is a
little duplication now.

Xamarin.Interactive.Facades is no longer necessary, and neither is the
PCL loading code in `UnifiedInspectorSupport`.

Xamarin.Forms has been bumped from 2.3.4.231 to 2.4.0.18342 for .NET
Standard 2.0 support.

`CompilationWorkspaceFactory` has to do some manual loading of
`Xamarin.Interactive.dll` and `netstandard.dll` now, but this will go
away when dotnet/roslyn#20920 gets fixed.
sandyarmstrong added a commit to microsoft/workbooks that referenced this issue Nov 8, 2017
Additionally, the Xamarin.Interactive.Shared project that was consumed
by each agent assembly is gone. All those types are now part of the
actual Xamarin.Interactive.dll. Same with
Xamarin.Interactive.Bootstrap.

InspectorSupport is no longer a partial class, because the shared
projects are gone now. But we need to keep the same API for Inspector
extension compatibility, and because that API is based on static
methods there's no helpful way to abstract any of it. So there is a
little duplication now.

Xamarin.Interactive.Facades is no longer necessary, and neither is the
PCL loading code in `UnifiedInspectorSupport`.

Xamarin.Forms has been bumped from 2.3.4.231 to 2.4.0.18342 for .NET
Standard 2.0 support.

`CompilationWorkspaceFactory` has to do some manual loading of
`Xamarin.Interactive.dll` and `netstandard.dll` now, but this will go
away when dotnet/roslyn#20920 gets fixed.
sandyarmstrong added a commit to microsoft/workbooks that referenced this issue Nov 8, 2017
Additionally, the Xamarin.Interactive.Shared project that was consumed
by each agent assembly is gone. All those types are now part of the
actual Xamarin.Interactive.dll. Same with
Xamarin.Interactive.Bootstrap.

InspectorSupport is no longer a partial class, because the shared
projects are gone now. But we need to keep the same API for Inspector
extension compatibility, and because that API is based on static
methods there's no helpful way to abstract any of it. So there is a
little duplication now.

Xamarin.Interactive.Facades is no longer necessary, and neither is the
PCL loading code in `UnifiedInspectorSupport`.

Xamarin.Forms has been bumped from 2.3.4.231 to 2.4.0.18342 for .NET
Standard 2.0 support.

`CompilationWorkspaceFactory` has to do some manual loading of
`Xamarin.Interactive.dll` and `netstandard.dll` now, but this will go
away when dotnet/roslyn#20920 gets fixed.
sandyarmstrong added a commit to microsoft/workbooks that referenced this issue Nov 10, 2017
Additionally, the Xamarin.Interactive.Shared project that was consumed
by each agent assembly is gone. All those types are now part of the
actual Xamarin.Interactive.dll. Same with
Xamarin.Interactive.Bootstrap.

InspectorSupport is no longer a partial class, because the shared
projects are gone now. But we need to keep the same API for Inspector
extension compatibility, and because that API is based on static
methods there's no helpful way to abstract any of it. So there is a
little duplication now.

Xamarin.Interactive.Facades is no longer necessary, and neither is the
PCL loading code in `UnifiedInspectorSupport`.

Xamarin.Forms has been bumped from 2.3.4.231 to 2.4.0.18342 for .NET
Standard 2.0 support.

`CompilationWorkspaceFactory` has to do some manual loading of
`Xamarin.Interactive.dll` and `netstandard.dll` now, but this will go
away when dotnet/roslyn#20920 gets fixed.
sandyarmstrong added a commit to microsoft/workbooks that referenced this issue Nov 10, 2017
Additionally, the Xamarin.Interactive.Shared project that was consumed
by each agent assembly is gone. All those types are now part of the
actual Xamarin.Interactive.dll. Same with
Xamarin.Interactive.Bootstrap.

InspectorSupport is no longer a partial class, because the shared
projects are gone now. But we need to keep the same API for Inspector
extension compatibility, and because that API is based on static
methods there's no helpful way to abstract any of it. So there is a
little duplication now.

Xamarin.Interactive.Facades is no longer necessary, and neither is the
PCL loading code in `UnifiedInspectorSupport`.

Xamarin.Forms has been bumped from 2.3.4.231 to 2.4.0.18342 for .NET
Standard 2.0 support.

`CompilationWorkspaceFactory` has to do some manual loading of
`Xamarin.Interactive.dll` and `netstandard.dll` now, but this will go
away when dotnet/roslyn#20920 gets fixed.
sandyarmstrong added a commit to microsoft/workbooks that referenced this issue Nov 10, 2017
Additionally, the Xamarin.Interactive.Shared project that was consumed
by each agent assembly is gone. All those types are now part of the
actual Xamarin.Interactive.dll. Same with
Xamarin.Interactive.Bootstrap.

InspectorSupport is no longer a partial class, because the shared
projects are gone now. But we need to keep the same API for Inspector
extension compatibility, and because that API is based on static
methods there's no helpful way to abstract any of it. So there is a
little duplication now.

Xamarin.Interactive.Facades is no longer necessary, and neither is the
PCL loading code in `UnifiedInspectorSupport`.

Xamarin.Forms has been bumped from 2.3.4.231 to 2.4.0.18342 for .NET
Standard 2.0 support.

`CompilationWorkspaceFactory` has to do some manual loading of
`Xamarin.Interactive.dll` and `netstandard.dll` now, but this will go
away when dotnet/roslyn#20920 gets fixed.
@jinujoseph jinujoseph added this to the Unknown milestone Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants