Skip to content

Conversation

@BillWagner
Copy link
Member

Fixes #5289

This PR adds the overview to "What's new in C# 7.3". I updated the wording in the TOC to remove the repeated "What's new" phrasing.

/cc @jcouv @MadsTorgersen

/cc @Welchen

This PR relies on new files added in PR #5408

Summary

Describe your changes here.

Fixes #Issue_Number (if available)

@BillWagner BillWagner requested review from jcouv, mairaw and rpetrusha May 17, 2018 18:46
@BillWagner BillWagner added the 🚧 Hold for related PR Indicates a PR can only be merged when other related PRs are merged (see comments for links) label May 17, 2018

- You can test `==` and `!=` with tuple types.
- You can use expression variables in more locations.
- You may attach attributes to the backing field of auto implemented properties.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: auto-implemented

- You can use expression variables in more locations.
- You may attach attributes to the backing field of auto implemented properties.
- Method resolution when arguments differ by `in` has been improved.
- Overload resolution new has fewer ambiguous cases.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: new -> now


The new compiler options are:

- `deterministic` to ensure that subsequent compilations of the same source generate the same binary output.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised. "deterministic" is not a new option. It was there for a while.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we got behind. I can move it to the correct version. Do you know when it was first added?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-deterministic was added in C# 6.0.

---
# What's new in C# 7.3

There are two main themes to the C# 7.3 release. One theme provides features that enable safe code to be as performant as unsafe code. The second theme provides incremental improvements to existing features. In addition, new compilers were added in this release.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the last sentence: ...new compilers... -> ...new compiler options...

- You can reassign `ref` local variables.
- You can use initializers on `stackalloc` arrays.
- You can use `fixed` statements with any type that supports a pattern.
- You can use additional generic constraints.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one is on the border :). @BillWagner what made you put this in this theme and not in the theme of the enhancements to the existing features?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could go in either section. I put it here because of the unmanaged constraint. That enables some more perf oriented generic programming.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see, thank you for the reply.

- You can use expression variables in more locations.
- You may attach attributes to the backing field of auto implemented properties.
- Method resolution when arguments differ by `in` has been improved.
- Overload resolution new has fewer ambiguous cases.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overload resolution new... -> New overload resolution...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"overload resolution now..."


- `deterministic` to ensure that subsequent compilations of the same source generate the same binary output.
- `publicsign` to enable OSS signing of assemblies.
- `pathmap` to provide a mapping for source directories.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be dashes in front of each compiler option?


### Tuples support `==` and `!=`

The C# tuple types now support `==` and `!=`. You can learn more about the rules in the article on [tuples](../tuples.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider to give the link to the section in that article: ../tuples.md#equality-and-tuples


By default, every compilation unique output on each compilation. The compiler adds a timestamp, and a GUID generated from random numbers. You use this option if you want to compare the byte-for-byte output to ensure consistency across builds.

For more information, see the [deterministic compiler option](../language-reference/compiler-options/deterministic-compiler-option.md) article.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: As far as I noticed, dashes are also used in the link texts throughout the docs.


The `-publicsign` compiler option instructs the compiler to sign the assembly using a public key. The assembly is marked as signed, but the signature is taken from the public key. This option enables you to build signed assemblies from open-source projects using a public key.

For more information, see the [publicsign compiler option](../language-reference/compiler-options/publicsign-compiler-option.md) article.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: dash in the link text


The `-pathmap` compiler option instructs the compiler to replace source paths from the build environment with mapped source paths. The pathmap option controls the source path written by the compiler to PDB files or for the <xref:System.Runtime.CompilerServices.CallerFilePathAttribute>.

For more information, see the [pathmap compiler option](../language-reference/compiler-options/pathmap-compile-option.md) article.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: dash in the link text

* [C# 7.1](csharp-7-1.md):
- This page describes the features in C# 7.1. These features were added in [Visual Studio 2017 version 15.3](https://www.visualstudio.com/vs/whatsnew/), and in the [.NET Core 2.0 SDK](../../core/whats-new/index.md).

- This page describes the features in C# 7.1. These features were added in [Visual Studio 2017 version 15.3](https://www.visualstudio.com/vs/whatsnew/), and in the [.NET Core 2.0 SDK](../../core/whats-new/index.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first sentence should be: This page describes the features added in C# 7.1.

* [C# 7.2](csharp-7-2.md):
- This page describes the latest features in the C# language. C# 7.2 is currently available in [Visual Studio 2017 version 15.5](https://www.visualstudio.com/vs/whatsnew/), and in the [.NET Core 2.0 SDK](../../core/whats-new/index.md).

- This page describes the latest features in the C# language. C# 7.2 is currently available in [Visual Studio 2017 version 15.5](https://www.visualstudio.com/vs/whatsnew/), and in the [.NET Core 2.0 SDK](../../core/whats-new/index.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first sentence should be: This page describes the features added in C# 7.2

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks!

@MihaMarkic
Copy link

MihaMarkic commented May 18, 2018

LGTM as well. Perhaps you could add a couple of enhancements:

  • add a Span<int> arr = stackalloc [] {1, 2, 3}; sample
  • add either Enum or Delegate or both samples to generic constraints

@MihaMarkic
Copy link

MihaMarkic commented May 18, 2018

OTOH,

When the in argument modifier was added, these two methods would cause an ambiguity:

static void M(S arg);
static void M(in S arg);

Is this real? I've tested it with 7.2 and it works:

        static void X(int a) {}
        static void X(in int a) {}

@BillWagner
Copy link
Member Author

BillWagner commented May 18, 2018

Perhaps you could add a couple of enhancements:
add a Span arr = stackalloc [] {1, 2, 3}; sample

I like this idea. I added it.

add either Enum or Delegate or both samples to generic constraints

If want to keep this article reasonably short. The articles linked at the end of that section have samples of both Enum and Delegate, in addition to unmanaged.

@BillWagner
Copy link
Member Author

Is this real? I've tested it with 7.2 and it works:

Yes, and I added a note that this is a bug fix, and the new resolution applies even if C# 7.2 is selected as the language version.

> The C# language relies on types and methods in a *standard library* for some of the features. One example is exception processing. Every `throw` statement or expression is checked to ensure the object being thrown is derived from <xref:System.Exception>. Similarly, every `catch` is checked to ensure that the type being caught is derived from <xref:System.Exception>. Each version may add new requirements. To use the latest language features in older environments, you may need to install specific libraries. These dependencies are documented in the page for each specific version. You can learn more about the [relationships between language and library](relationships-between-language-and-library.md) for background on this dependency.
* [C# 7.3](csharp-7-3.md):
- This page describes the latest features in the C# language. C# 7.3 is currently available in [Visual Studio 2017 version 15.7](https://www.visualstudio.com/vs/whatsnew/), and in the [.NET Core 2.1 SDK Preview](../../core/whats-new/index.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.1.300 RC1?

Copy link
Contributor

@mairaw mairaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @BillWagner. Left a couple of comments.


You can also use the new `unmanaged` constraint, to specify that a type parameter must be an **unmanaged type**. An **unmanaged type** is a type that isn't a reference type, and doesn't contain any reference type at any level of nesting.

You can learn more in the articles on [`where` generic constraints](../language-reference/keywords/where-generic-type-constraints.md) and the article covering [constraints on type parameters](../programming-guide/generics/constraints-on-type-parameters.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a few broken links warnings like this one in the build report

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this one. The others rely on #5408


You can learn more in the article on [`ref` returns and `ref` locals](../programming-guide/classes-and-structs/ref-returns.md).

### `stackalloc` arrays support initializers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I find it weird how the heading gets rendered when we use inline code. Wondering if it would be worth to ask them not to format inline code in headings while we still lock the word for Loc. Same applies to links.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm torn. I hate not styling them, because otherwise the first word should be caps. And the loc issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the styling. My thought process was more related to UX changes. Like, should we work with @adkinn and co. to come up with some rules for when inline code should not be formatted like in headings and links?


You can now specify the type <xref:System.Enum?displayProperty=nameWithType> or <xref:System.Delegate?displayProperty=nameWithType> as base class constraints for a type parameter.

You can also use the new `unmanaged` constraint, to specify that a type parameter must be an **unmanaged type**. An **unmanaged type** is a type that isn't a reference type, and doesn't contain any reference type at any level of nesting.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove comma from last sentence


### pathmap

The `-pathmap` compiler option instructs the compiler to replace source paths from the build environment with mapped source paths. The pathmap option controls the source path written by the compiler to PDB files or for the <xref:System.Runtime.CompilerServices.CallerFilePathAttribute>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline code pathmap?

static void M(in S arg);
```

Now, the by value (first in the preceding example) overload is better than the by readonly reference version. To specify the by readonly reference version is called, you must include the `in` modifier when calling the method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first part of the last sentence is a bit hard to parse. Maybe if you change to something like "To call the by readonly reference version"?


```csharp
var arr = new int[3] {1, 2, 3};
var arr2 = new int[] { 1, 2, 3};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit remove extra space


```csharp
int* pArr = stackalloc int[3] {1, 2, 3};
int* pArr2 = stackalloc int[] { 1, 2, 3};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit remove extra space


### Extend expression variables in initializers

The syntax added in C# 7.0 to permit out variable declarations has been extended to include field initializers, property initializers, constructor initializers, and query clauses. It enables code such as the following example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace permit with allow? inline code out?


## New compiler options

New compiler options support new build and DevOps scenarios for C# programs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing punctuation


The new compiler options are:

- `-publicsign` to enable OSS signing of assemblies.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spell out OSS on first usage

### Tuples support `==` and `!=`

The C# tuple types now support `==` and `!=`. You can learn more about the rules in the article on [tuples](../tuples.md#equality-and-tuples).
The C# tuple types now support `==` and `!=`. Fore more information, see the section covering [equality](../tuples.md#equality-and-tuples) in the article on [tuples](../tuples.md#equality-and-tuples).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the sentence should end with the link to the article itself, not the section:
...in the article on [tuples](../tuples.md)

### Extend expression variables in initializers

The syntax added in C# 7.0 to permit out variable declarations has been extended to include field initializers, property initializers, constructor initializers, and query clauses. It enables code such as the following example:
The syntax added in C# 7.0 to aloow `out` variable declarations has been extended to include field initializers, property initializers, constructor initializers, and query clauses. It enables code such as the following example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: aloow -> allow

### pathmap

The `-pathmap` compiler option instructs the compiler to replace source paths from the build environment with mapped source paths. The pathmap option controls the source path written by the compiler to PDB files or for the <xref:System.Runtime.CompilerServices.CallerFilePathAttribute>.
The `-pathmap` compiler option instructs the compiler to replace source paths from the build environment with mapped source paths. The `pathmap` option controls the source path written by the compiler to PDB files or for the <xref:System.Runtime.CompilerServices.CallerFilePathAttribute>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add dash to the second mention of -pathmap

@BillWagner
Copy link
Member Author

closing and reopening to start a new build.

@BillWagner BillWagner closed this May 23, 2018
@BillWagner BillWagner reopened this May 23, 2018
@BillWagner BillWagner removed the 🚧 Hold for related PR Indicates a PR can only be merged when other related PRs are merged (see comments for links) label May 23, 2018
}
```

The variable `p` doesn't need to be pinned. Note that you still need an `unsafe` context. In earlier versions of C#, you need to declare a second fixed pointer:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's inaccurate to say that p doesn't need to be pinned. p is just an int, it can't be pinned and the following example does not pin p.

public void M()
{
int p = s.myFixedField[5];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the following text says, this code has be in an unsafe context, so I think this example should include unsafe somewhere (probably on the method).


```csharp
ref VeryLargeStruct reflocal = ref veryLargeStruct; // initialization
refLocal = ref anotherVeryLargeStruct; // reassigned, refLocal refers to different storage.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: first line uses reflocal (with lowecase l), second line refLocal (with capital L).

@mairaw
Copy link
Contributor

mairaw commented May 25, 2018

There are some build warnings here, @BillWagner. I'll take a look at the rest now.

Copy link
Contributor

@mairaw mairaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @svick had some new comments you might wanna check and you still have one instance of OSS which is not spelled out. You can use the acronym after you show what it means once.

BillWagner and others added 5 commits May 25, 2018 15:59
Fixes #5289

This PR adds the overview to "What's new in C# 7.3". I updated the wording in the TOC to remove the repeated "What's new" phrasing.

/cc @jcouv @MadsTorgersen

/cc @Welchen

This PR relies on new files added in PR #5408
@BillWagner BillWagner force-pushed the whats-new-in-csharp branch from 469998f to e5e4ce1 Compare May 25, 2018 20:01
compile => compiler.
@BillWagner BillWagner merged commit 7534a56 into dotnet:master May 25, 2018
@BillWagner BillWagner deleted the whats-new-in-csharp branch May 25, 2018 20:21
Now, `ref` locals may be reassigned to refer to different instances after being initialized. The following code now compiles:

```csharp
ref VeryLargeStruct refLocal = ref veryLargeStruct; // initialization
Copy link
Member

@jcouv jcouv May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one more form of ref local re-assignment: foreach ref. It was missing from the spec, but it is implemented and shipped.

using System;
class E
{
    public class Enumerator
    {
        public ref int Current => throw new NotImplementedException();
        public bool MoveNext() => throw new NotImplementedException();
    }

    public Enumerator GetEnumerator() => new Enumerator();
}

class C
{
    void M()
    {
        foreach (ref int x in new E())
        {

        }
    }
}

[I'd given a bad example. Updated]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcouv that means we can make such shoot-in-the-leg things now:

var _array = new byte[5];
new Random(42).NextBytes(_array);
Span<byte> span = _array;
foreach (ref byte element in span)
{
    element = 4;
    Console.WriteLine(element);
}
Console.WriteLine(string.Join(" ", _array));
Console.ReadLine();

That outputs only 4s. Wow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants