Skip to content

Commit

Permalink
Rename LifetimeAnnotationAttribute to ScopedRefAttribute and remo…
Browse files Browse the repository at this point in the history
…ve unnecessary members (#6325)
  • Loading branch information
jcouv authored Jul 27, 2022
1 parent fe13c0f commit 88ced28
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions proposals/low-level-struct-improvements.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,28 +514,22 @@ Detailed Notes:
- Any member that is not declared on a `struct`
- Any `static` member, `init` member or constructor on a `struct`

### LifetimeAnnotationAttribute
The `scoped` and `unscoped` annotations will be emitted into metadata via the type `System.Runtime.CompilerServices.LifetimeAttribute` attribute. This attribute will be matched by name meaning it does not need to appear in any specific assembly.
### ScopedRefAttribute
The `scoped` annotations will be emitted into metadata via the type `System.Runtime.CompilerServices.ScopedRefAttribute` attribute. This attribute will be matched by name meaning it does not need to appear in any specific assembly.

The type will have the following definition:

```c#
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter)]
public sealed class LifetimeAnnotationAttribute : Attribute
namespace System.Runtime.CompilerServices
{
private int _value;
public bool IsScoped => _value == 1;

public LifetimeAnnotationAttribute(int value)
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
internal sealed class ScopedRefAttribute : Attribute
{
_value = value;
}
}
```

The attribute uses `int` instead of `bool` to allow for future lifetime expansions in this space.

The compiler will emit this attribute on the element targeted by the `scoped` or `unscoped` syntax. This is true for types, methods and parameters. This will only be emitted when the syntax causes the value to differ from its default state. For example `scoped out` will cause no attribute to be emitted.
The compiler will emit this attribute on the parameter with `scoped` syntax. This will only be emitted when the syntax causes the value to differ from its default state. For example `scoped out` will cause no attribute to be emitted.

### Safe fixed size buffers
The language will relax the restrictions on fixed sized arrays such that they can be declared in safe code and the element type can be managed or unmanaged. This will make types like the following legal:
Expand Down

0 comments on commit 88ced28

Please sign in to comment.