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

New custom attribute required to support C++ inline namespaces #783

Closed
tgani-msft opened this issue Dec 12, 2019 · 5 comments
Closed

New custom attribute required to support C++ inline namespaces #783

tgani-msft opened this issue Dec 12, 2019 · 5 comments
Labels
api-approved API was approved in API review, it can be implemented area-System.Runtime.CompilerServices
Milestone

Comments

@tgani-msft
Copy link
Contributor

tgani-msft commented Dec 12, 2019

Namespaces in .NET are not a first class concept in metadata but are implicit in type names. C++ inline namespaces are namespaces whose contents are implicitly available in the enclosing namespace. E.g.

namespace N {
  inline namespace I {
     ref class R {};
  }
}

The type R is simply name N.I.R in the metadata and upon import the C++ compiler does not know whether I is an inline namespace or not. To help the compiler import this correctly, an assembly-level custom attribute is emitted to the assembly for every inline namespace in the assembly. E.g., for the above we would emit

[CppInlineNamespace("N.I")];

To implement this, we need the attribute System.Runtime.CompilerServices.CppInlineNamespaceAttribute in System.Runtime.CompilerServices.VisualC.dll:

namespace System.Runtime.CompilerServices
{
    [AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
    public sealed class CppInlineNamespaceAttribute : Attribute
    {
        public CppInlineNamespaceAttribute(string dottedName);
    }
}

An explanation of how inline namespaces work is at https://foonathan.net/2018/11/inline-namespaces:

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Dec 12, 2019
@terrajobst
Copy link
Member

terrajobst commented Dec 12, 2019

Couple of questions.

Is this only emitted for assemblies? Can this also be emitted for modules?

C++ inline namespaces are namespaces whose contents are implicitly available in the enclosing namespace.

So when I have a using N; directive (or whatever the C++ equivalent is) I can see R even though it's a nested namespace I? What's the point of having a nested namespace then?

Do you expect other compilers (such as C#) to honor this attribute?

@tgani-msft
Copy link
Contributor Author

In theory, yes, we could build a .netmodule though we don't officially support it.

An explanation of how inline namespaces work is at https://foonathan.net/2018/11/inline-namespaces/

We don't expect other compilers to do anything with this custom attribute, hence its location in VisualC.dll.

@terrajobst
Copy link
Member

terrajobst commented Dec 12, 2019

An explanation of how inline namespaces work is at https://foonathan.net/2018/11/inline-namespaces/

Excellent, that helps!

We're reviewing API requests once a week on Tuesdays. So expect an answer by EOD the upcoming Tuesday.

@terrajobst terrajobst added api-ready-for-review area-System.Runtime.CompilerServices and removed untriaged New issue has not been triaged by the area owner labels Dec 12, 2019
@terrajobst terrajobst added this to the 5.0 milestone Dec 12, 2019
@carlossanlop carlossanlop added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-ready-for-review labels Jul 6, 2020
@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 Jul 16, 2020
@terrajobst
Copy link
Member

terrajobst commented Jul 16, 2020

Video

  • Looks good as proposed.
  • @jkotas pointed out that you may no longer need it. If you don't, please close this issue. If you do, consider it approved.
namespace System.Runtime.CompilerServices
{
    [AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
    public sealed class CppInlineNamespaceAttribute : Attribute
    {
        public CppInlineNamespaceAttribute(string dottedName);
    }
}

@tgani
Copy link

tgani commented Jul 16, 2020

We went with a different design based on @jkotas feedback. I'll close this issue.

@jkotas jkotas closed this as completed Jul 16, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
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
None yet
Development

No branches or pull requests

6 participants