From bafe4d98dd39d02e8124798ab73c046c62b6758f Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Tue, 14 Nov 2023 17:41:36 -0500 Subject: [PATCH 1/4] Add support for module initializers --- standard/attributes.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/standard/attributes.md b/standard/attributes.md index 6afb317d8..946a2ce97 100644 --- a/standard/attributes.md +++ b/standard/attributes.md @@ -524,6 +524,7 @@ A small number of attributes affect the language in some way. These attributes i - `System.Diagnostics.ConditionalAttribute` ([§22.5.3](attributes.md#2253-the-conditional-attribute)), is a multi-use attribute class which is used to define conditional methods and conditional attribute classes. This attribute indicates a condition by testing a conditional compilation symbol. - `System.ObsoleteAttribute` ([§22.5.4](attributes.md#2254-the-obsolete-attribute)), which is used to mark a member as obsolete. - `System.Runtime.CompilerServices.CallerLineNumberAttribute` ([§22.5.5.2](attributes.md#22552-the-callerlinenumber-attribute)), `System.Runtime.CompilerServices.CallerFilePathAttribute` ([§22.5.5.3](attributes.md#22553-the-callerfilepath-attribute)), and `System.Runtime.CompilerServices.CallerMemberNameAttribute` ([§22.5.5.4](attributes.md#22554-the-callermembername-attribute)), which are used to supply information about the calling context to optional parameters. +- `System.Runtime.CompilerServices.ModuleInitializer` (§module-init-attr), which is used to mark a method as a module initializer. An execution environment may provide additional implementation-specific attributes that affect the execution of a C# program. @@ -852,6 +853,22 @@ For invocations that occur within field or event initializers, the member name u For invocations that occur within declarations of instance constructors, static constructors, finalizers and operators the member name used is implementation-dependent. +### §module-init-attr The ModuleInitializer attribute + +The attribute `ModuleInitializer` is used to mark a method as a ***module initializer***. Such a method is called during initialization of the containing module. A module may have multiple initializers, which are called in an implementation-defined order. + +There are no limitations on what code is permitted in a module initializer. + +A module initializer shall have the following characteristics: + +- The *method_modifier* `static`. +- No *parameter_list*. +- A *return_type* of `void`. +- No *type_parameter_list*. +- Not be declared inside a *class_declaration* having a *type_parameter_list*. +- Be accessible from the containing module (that is, have an access modifier `internal` or `public`). +- Not be a local function. + ## 22.6 Attributes for interoperation For interoperation with other languages, an indexer may be implemented using indexed properties. If no `IndexerName` attribute is present for an indexer, then the name `Item` is used by default. The `IndexerName` attribute enables a developer to override this default and specify a different name. From 5f65af0f7b38ffdaa0a13b8a167b0335883d89a6 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Tue, 14 Nov 2023 17:43:33 -0500 Subject: [PATCH 2/4] Add support for module initializers --- standard/portability-issues.md | 1 + 1 file changed, 1 insertion(+) diff --git a/standard/portability-issues.md b/standard/portability-issues.md index 7e846a428..928829a5a 100644 --- a/standard/portability-issues.md +++ b/standard/portability-issues.md @@ -33,6 +33,7 @@ A conforming implementation is required to document its choice of behavior in ea 1. When a `System.ArithmeticException` (or a subclass thereof) is thrown when performing a decimal remainder operation ([§12.10.4](expressions.md#12104-remainder-operator)). 1. The impact of thread termination when a thread has no handler for an exception, and the thread is itself terminated ([§13.10.6](statements.md#13106-the-throw-statement)). 1. The impact of thread termination when no matching `catch` clause is found for an exception and the code that initially started that thread is reached. ([§21.4](exceptions.md#214-how-exceptions-are-handled)). +1. The order of execution of module initializers in a module (§module-init-attr). 1. The mappings between pointers and integers ([§23.5.1](unsafe-code.md#2351-general)). 1. The effect of applying the unary `*` operator to a `null` pointer ([§23.6.2](unsafe-code.md#2362-pointer-indirection)). 1. The behavior when pointer arithmetic overflows the domain of the pointer type ([§23.6.6](unsafe-code.md#2366-pointer-increment-and-decrement), [§23.6.7](unsafe-code.md#2367-pointer-arithmetic)). From dcf247501d4061865001752633b4c29978b8c1dc Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Tue, 14 Nov 2023 17:48:40 -0500 Subject: [PATCH 3/4] Add support for module initializers --- standard/standard-library.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/standard/standard-library.md b/standard/standard-library.md index 79a6d3c3c..2f534d00a 100644 --- a/standard/standard-library.md +++ b/standard/standard-library.md @@ -512,6 +512,12 @@ namespace System.Runtime.CompilerServices void OnCompleted(Action continuation); } + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public sealed class ModuleInitializerAttribute : Attribute + { + public ModuleInitializerAttribute() { } + } + public readonly struct TaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion { From 3abc67081add2dab2201669152fe15202f7d8df4 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Tue, 14 Nov 2023 18:03:44 -0500 Subject: [PATCH 4/4] fix md formatting --- standard/attributes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard/attributes.md b/standard/attributes.md index 946a2ce97..18573ced6 100644 --- a/standard/attributes.md +++ b/standard/attributes.md @@ -862,7 +862,7 @@ There are no limitations on what code is permitted in a module initializer. A module initializer shall have the following characteristics: - The *method_modifier* `static`. -- No *parameter_list*. +- No *parameter_list*. - A *return_type* of `void`. - No *type_parameter_list*. - Not be declared inside a *class_declaration* having a *type_parameter_list*.