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

Consider Reloadable Attribute for Hot Reload #54633

Closed
tommcdon opened this issue Jun 23, 2021 · 11 comments · Fixed by #55245
Closed

Consider Reloadable Attribute for Hot Reload #54633

tommcdon opened this issue Jun 23, 2021 · 11 comments · Fixed by #55245
Labels
api-approved API was approved in API review, it can be implemented area-System.Runtime.CompilerServices
Milestone

Comments

@tommcdon
Copy link
Member

tommcdon commented Jun 23, 2021

Background and Motivation

Roslyn is adding a Reloadable Type feature. Types marked with the Reloadable attribute instructs the Roslyn compiler to emit a new type rather than updating it when applying changes with .NET Hot Reload. This feature enables inner-dev loop changes to be made that normally would be considered to be rude edits. We are proposing the Reloadable attribute to be used by frameworks, 3rd party libraries, and end users. It will be consumed by the Roslyn compiler.

Proposed API

namespace System.Runtime.CompilerServices
{  
  [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)]  
  public class ReloadableAttribute : Attribute  
  {  

  }
}

Usage Examples

MyUIFramework knows how to serialize, instantiate, reinitialize, and display onscreen any View subclass. So even 'rude edits' that ends up being new version of types can be applied by MyUIFramework during a .NET Hot Reload session.

namespace MyUIFramework
{
  [Reloadable]
  public class View
  {

  }
}

Alternative Designs

  1. One alternative would be to the add known types at the Roslyn level, though this limits future extensibility by 3rd parties and app developers.

  2. Another alternative is to define an internal attribute for each framework that supports the reloadable type feature. The disadvantage is that there are possible conflicts when using InternalVisibleTo, and a lack of central documentation of the feature.

Risks

None at the runtime library level, as this only defines an attribute

UPDATE:
ReloadableAttribute renamed to CreateNewOnMetadataUpdateAttribute

@tommcdon tommcdon added api-suggestion Early API idea and discussion, it is NOT ready for implementation area-Meta labels Jun 23, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jun 23, 2021
@tommcdon
Copy link
Member Author

@tommcdon tommcdon removed the untriaged New issue has not been triaged by the area owner label Jun 23, 2021
@tommcdon tommcdon added this to the 6.0.0 milestone Jun 23, 2021
@pranavkm
Copy link
Contributor

pranavkm commented Jun 23, 2021

Since it's an API proposal:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)]  
public sealed class ReloadableAttribute : Attribute  
{  
}

Also consider ReloadableAttribute -> ApplyUpdateReloadableAttribute so that it's very clear about it's intent.

@tmat
Copy link
Member

tmat commented Jun 23, 2021

ApplyUpdateReloadableAttribute sounds odd to me.

@tommcdon
Copy link
Member Author

We should also consider placing the attribute in the System.Reflection.Metadata namespace, which is next to the MetadataUpdateHandler attribute.

@tmat
Copy link
Member

tmat commented Jun 23, 2021

I chose System.Runtime.CompilerServices because this attribute is for compiler (more precisely, for the IDE HR service) consumption and has no meaning to the runtime

@tommcdon
Copy link
Member Author

tommcdon commented Jun 23, 2021

Updated the proposal with @pranavkm's suggestion to include AllowMultiple = false

@tommcdon tommcdon added api-ready-for-review API is ready for review, it is NOT ready for implementation blocking Marks issues that we want to fast track in order to unblock other important work and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Jun 24, 2021
@stephentoub
Copy link
Member

Do we envision this ever being applied to things beyond types (even if not in .NET 6)? Wondering if it should be named ReloadableType instead of just Reloadable.

@tmat
Copy link
Member

tmat commented Jun 28, 2021

One possibility would be methods if we need finer-grained control.

@terrajobst
Copy link
Member

  • We should avoid "good names", that is single word names like [Reloadable].
  • Assuming you don't like EditMetadataByCreatingNewTypeAttribute come back with a few proposals and we can pick one over email
namespace System.Runtime.CompilerServices
{  
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)]  
    public class EditMetadataByCreatingNewTypeAttribute : Attribute  
    {  
    }
}

@terrajobst terrajobst added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation blocking Marks issues that we want to fast track in order to unblock other important work labels Jun 29, 2021
@tommcdon tommcdon linked a pull request Jul 7, 2021 that will close this issue
@tmat
Copy link
Member

tmat commented Jul 7, 2021

How about ReloadOnMetadataUpdate?

@terrajobst
Copy link
Member

We agreed over email to CreateNewOnMetadataUpdateAttribute

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-System.Runtime.CompilerServices
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

6 participants