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

Obsolete Regex.CompileToAssembly #50535

Closed
buyaa-n opened this issue Apr 1, 2021 · 17 comments · Fixed by #59734
Closed

Obsolete Regex.CompileToAssembly #50535

buyaa-n opened this issue Apr 1, 2021 · 17 comments · Fixed by #59734
Assignees
Labels
api-approved API was approved in API review, it can be implemented area-System.Text.RegularExpressions
Milestone

Comments

@buyaa-n
Copy link
Member

buyaa-n commented Apr 1, 2021

EDIT 9/28/2021 by @stephentoub:
Now that for .NET 7 we have a regex source generator, and as there are no plans to enable CompileToAssembly (which has been and continues to throw PlatformNotSupportedException in Core), we should just obsolete it. This means obsoleting these members:

public class Regex
{
    public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname);
    public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname, CustomAttributeBuilder[]? attributes);
    public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname, CustomAttributeBuilder[]? attributes, string? resourceFile);
}

as well as the whole RegexCompilationInfo class:

public class RegexCompilationInfo { ... }

As part of #47228 i am running an analyzer to detect APIs throwing PNSE but not annotated with Obsolete/SupportedOSPlatform/UnsupportedOSPlatform attributes, we need to annotate them so that developers get warnings when they use them unexpectedly

For now, I have results only cross-platform builds, analysis of targeted builds are coming soon which could detect more APIs and will be added here

API Comment Suggestion Location
'RegexAssemblyCompiler.Save()' Seems not supported on .Net core add [Obsolete] libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexAssemblyCompiler.cs(246,13)

Note: We are suggesting adding [Obsolete] for the APIs only supported in .Net framework but not supported in .NetCore, with the corresponding Message, DiagnosticId, and UrlFormat

[Obsolete(Obsoletions.AuthenticationManagerMessage, DiagnosticId = Obsoletions.AuthenticationManagerDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
You can claim the next available DiagnosticId from Obsoletions.cs .

EDIT: Annotating internal API is useless, we should add [Obsolete] into Regex.CompileToAssembly(...) overloads instead

cc @jeffhandley @terrajobst @GrabYourPitchforks

@ghost
Copy link

ghost commented Apr 1, 2021

Tagging subscribers to this area: @eerhardt, @pgovind
See info in area-owners.md if you want to be subscribed.

Issue Details

As part of #47228 i am running an analyzer to detect APIs throwing PNSE but not annotated with Obsolete/SupportedOSPlatform/UnsupportedOSPlatform attributes, we need to annotate them so that developers get warnings when they use them unexpectedly

For now, I have results only cross-platform and .Net 5.0 or higher builds, analysis of targeted builds or lower envs are coming soon which could detect more APIs and will be added here

API Comment Suggestion Location
'RegexAssemblyCompiler.Save()' Seems not supported on .Net core add [Obsolete] libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexAssemblyCompiler.cs(246,13)
'RegexAssemblyCompiler.RegexAssemblyCompiler(AssemblyName, CustomAttributeBuilder[]?, string?)' throwing condition seems not related to platform Consider changing the exception to NotSupportedException libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexAssemblyCompiler.cs(28,17)

Note: We are suggesting to add [Obsolete] with the corresponding message for APIs supported in .Net framework but not supported in .NetCore, if it is only supported on a specific platform(s) consider adding [SupportedOSPlatform("platformName")] or if it is unsupported on a specific platform(s) [UnsupportedOSPlatform("platformName")] attribute instead

  • Suggestions for changing the exception is optional

cc @jeffhandley @terrajobst @GrabYourPitchforks

Author: buyaa-n
Assignees: -
Labels:

area-System.Text.RegularExpressions

Milestone: 6.0.0

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Apr 1, 2021
@stephentoub
Copy link
Member

stephentoub commented Apr 1, 2021

This is effectively a dup of #30153. Either we implement CompileToAssembly as in #30153, or we mark CompileToAssembly obsolete and throw unconditionally. The methods cited in this issue are internal implementation details below that.

@buyaa-n
Copy link
Member Author

buyaa-n commented Apr 1, 2021

Sorry, seems we should add [obsolete] into Regex.CompileToAssembly overloads instead

@stephentoub
Copy link
Member

seems we should add [obsolete] into Regex.CompileToAssembly overloads instead

If we decide to never implement #30153

@buyaa-n
Copy link
Member Author

buyaa-n commented Apr 1, 2021

That was my concern not adding Obsolete initially, but I heard we can remove the Obsolete when we add the support, no?

@stephentoub
Copy link
Member

stephentoub commented Apr 1, 2021

i heard we can remove the Obsolete when we add the support, no?

I hadn't heard any discussions about that, and I'm not sure I've ever seen us do that.

@terrajobst, do we obsolete things even if we think we may want to unobsolete them in the future? I would think we'd only want to obsolete things if we firmly believe they shouldn't be used now or any time in the future (obviously we could change our minds, but based on the knowledge we have at that time, we think it's a permanent thing).

@jeffhandley
Copy link
Member

I heard we can remove the Obsolete when we add the support, no?

I asked the question of "why not?" which probably came across as "we can." I don't know of us ever doing it. Do we have any other options here?

<joking> Should we introduce [Obsolete?] ? </joking>

@danmoseley
Copy link
Member

Maybe it is time to say we will not do #30153. Source generators are the new way.

@GrabYourPitchforks
Copy link
Member

@stephentoub @terrajobst We have un-obsoleted APIs before (in Full Framework, in fact!) in aspnet. I don't remember offhand what API it was since I'd need to diff all the SDK ref asms, but I think it was something like we wanted people to stop using some specific API, then we realized later that it was still popular in some scenario and we didn't have a good alternative, so we un-obsoleted it. So there's precedent, at least.

@stephentoub
Copy link
Member

stephentoub commented Apr 1, 2021

then we realized later

This is the important part. It's one thing to say we made a mistake obsoleting something and then undo that mistake. It's another to say "until we implement xyz, we'll temporarily obsolete it". We shouldn't do the latter. It weakens the meaning of obsolete.

@buyaa-n
Copy link
Member Author

buyaa-n commented Apr 1, 2021

Makes sense, @stephentoub what you think about @danmoseley's point? If we decide not to do #30153 we can obsolete it.

@pgovind
Copy link
Contributor

pgovind commented Apr 1, 2021

Maybe it is time to say we will not do #30153. Source generators are the new way.

FWIW, I think this is what we should do and mark these APIs as obsolete. If we realize down the road that source generators won't get us a like for like replacement of RegexCompiler.Save, I think it'd be reasonable to say we made a mistake and un-obsolete these APIs at that point :)

@buyaa-n
Copy link
Member Author

buyaa-n commented Apr 6, 2021

[Brief Meeting Note]:
We have 3 options for handling APIs not supported in .NetCore but having open issue for future support:

  • If we decide not to support the API we can close the related issue and add [Obsolete] to the API
  • Add support for AllPlatforms scenario to PCA analyzer and annotate the API with [UnsupportedOSPlatform("AllPlatforms")]
  • Leave the API un annotated until we decide if we really gonna add support for this

For the APIs in this issue, we are leaving them unannotated until we decide to not support them for sure. @tannergooding will work on that

@marek-safar
Copy link
Contributor

Add support for AllPlatforms scenario to PCA analyzer and annotate the API with [UnsupportedOSPlatform("AllPlatforms")]

I think [SupportedOSPlatform("")] combination would make more sense

@buyaa-n
Copy link
Member Author

buyaa-n commented Apr 6, 2021

I think [SupportedOSPlatform("")] combination would make more sense

We have talked about a variant of using empty constructor for this too, anyway, AllPlatforms is just the idea, for now, we are not exactly doing option 2 as there is not enough API need this, we might consider doing it if more issues found in the future

@marek-safar marek-safar removed the untriaged New issue has not been triaged by the area owner label Apr 20, 2021
@eerhardt
Copy link
Member

I assume our plan for 6.0 is

Leave the API un annotated until we decide if we really gonna add support for this

And we should just move this issue to 7.0. Is that a fair assumption?

@eerhardt eerhardt modified the milestones: 6.0.0, 7.0.0 Aug 11, 2021
@stephentoub stephentoub added the api-ready-for-review API is ready for review, it is NOT ready for implementation label Sep 28, 2021
@stephentoub stephentoub changed the title Annotate unsupported APIs in System.Text.RegularExpressions Obsolete Regex.CompileToAssembly Sep 28, 2021
@terrajobst
Copy link
Member

terrajobst commented Sep 28, 2021

Video

  • Looks good
    • We should add a diagnostic ID for all these obsoletions.
    • Adjust message as needed to be consistent
  • Should we also obsolete the other APIs that persist an assembly to disk, such as
    • AssemblyBuilder.Save
namespace System.Text.RegularExpressions
{
    public partial class Regex
    {
        [Obsolete("This API isn't supported anymore. Please use source generated regexes instead.", DiagnosticId = "TBD")]
        public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname);
        [Obsolete("This API isn't supported anymore. Please use source generated regexes instead.", DiagnosticId = "TBD")]
        public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname, CustomAttributeBuilder[]? attributes);
        [Obsolete("This API isn't supported anymore. Please use source generated regexes instead.", DiagnosticId = "TBD")]
        public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname, CustomAttributeBuilder[]? attributes, string? resourceFile);
    }
    [Obsolete("This API isn't supported anymore. Please use source generated regexes instead.", DiagnosticId = "TBD")]
    public partial class RegexCompilationInfo
    {

    }
}

@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 labels Sep 28, 2021
@stephentoub stephentoub self-assigned this Sep 29, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Sep 29, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Sep 30, 2021
@dotnet dotnet locked as resolved and limited conversation to collaborators Nov 3, 2021
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.Text.RegularExpressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants