ufcpp-live / UfcppLiveAgenda

@ufcpp live streaming agenda
MIT License
24 stars 2 forks source link

Visual Studio 2022 も RC #47

Closed ufcpp closed 2 years ago

ufcpp commented 2 years ago

配信URL: https://youtu.be/rumE3mORrdk 2021/10/17日 13:00~ 予定。

ブログでの公式発表系:

ちなみに、C# 10 の修正点(バグ修正というか、「やっぱまずかった?」的な修正):

public void M()
{
    // 前まで: ambiguous エラー
    // RC 2で: Action の方に行く
    Method(() => { });
}

void Method(Action action) { }
void Method(Expression expr) { }

色…

この時期、もう新機能の PR は次(VS 17.1 とか .NET 7 Preview)向けにでてるわけですが:

LDM 2021/10/13:

ufcpp commented 2 years ago

そうそう、前回の配信の最後の方の雑談で触れてた C# ソースコードのシンタックスハイライトした状態のものを HTML としてコピーする GUI アプリ、リポジトリ独立させた:

https://github.com/ufcpp/RoslynCsharpToHtml/

ついでに緩募 https://twitter.com/ufcpp/status/1449341020261347336 https://github.com/ufcpp/UfcppSample/issues/366

ufcpp commented 2 years ago

前半は「WeekRef.NETを見て」であっさり済ますかも? (まゆきさんに感謝。)

ufcpp-live commented 2 years ago
[main:STAThread]

{ }
ufcpp-live commented 2 years ago
using System.Text;
namespace ConsoleApp1;
using System.Text.RegularExpressions;

internal class Class1
{
    private StringBuilder s;
    private Regex r;
}
ufcpp-live commented 2 years ago
namespace ConsoleApp1;
namespace A; // ダメ!
ufcpp-live commented 2 years ago

案外知らない人がいたらしい nested namespace

namespace ConsoleApp1.A
{
    record R();
}

namespace ConsoleApp1
{
    namespace A
    {
        record R();
    }
}
ufcpp-live commented 2 years ago

抵抗素子方式でバージョン問題解決! (そのCSSが書けるとは言っていない) (抵抗素子で意味は通じるけどどの色がどの値かまではわからない)

image

ufcpp-live commented 2 years ago

image

ufcpp-live commented 2 years ago

すでに merge 済み、breaking change のドキュメントも整備済みの変更予定

Delegate f = var () => 1; // これ 17.1 p1 とかで多分禁止に
Delegate f1 = @var () => 1; // C# 11 以降はこう書いてくれという例

struct var
{
    public static implicit operator var(int x) => default;
}
ufcpp-live commented 2 years ago
class C
{
    public int X { get => field; set; } // これの話が semi-auto property
}
ufcpp-live commented 2 years ago
class C
{
    // 片方だけの semi-auto も可能
    public int X { get => field; set; }
    public int Y { get; set => field = value; }
}
ufcpp-live commented 2 years ago
class C
{
    public int X { get; set => r = ref field; }
    private ref int r; // (別提案) ref field が入った暁にはもしや…
}
ufcpp-live commented 2 years ago
class C
{
    // これはどうなるんだろう?
    // 認められない気もする。
    // 現状も、ref 戻り値の時点で auto-property 不可。
    public int _x;
    public ref int X { get => ref field; }
}
ufcpp-live commented 2 years ago

value の扱い、キーワードじゃないんだ…

var c = new C();
c.X = 1;
Console.WriteLine(c.A);
Console.WriteLine(nameof(int));//行けない
Console.WriteLine(nameof(System.Int32));//いける

class C
{
    public string A;
    public int X { get => 0; set => A = nameof(value); }//行けるの?!!
    public void M()
    {
        A = nameof(this); //だめ!
    }
}
ufcpp-live commented 2 years ago

キーワードなのか暗黙のパラメーターなのかどっちつかずな存在。

image

ufcpp-live commented 2 years ago
var x = 1; // これを常に型推論の var 扱いしたいという話もあり。

record var();
ufcpp-live commented 2 years ago
record var(); // 全部小文字の型名は警告にレベルが上がるかも
record @var(); // 警告消したきゃ @ 付けとけ
class @class { }
ufcpp-live commented 2 years ago
// lowlevelhackathon とかいう不穏な名前のブランチでの出来事なので、
// まだ main に merge されるとは限らない話。
using System.Runtime.CompilerServices;

m("a", "b", "c");

//↓こうなる予定
Span<string> s = RuntimeHelpers.StackAlloc<string>(3); // intrinsic method
s[0] = "a";
s[1] = "b";
s[2] = "c";
m(s);

void m(params Span<string> spans) // ROS も OK。(Memory は自信ない。)
{
}

// ずっと、StackAlloc のところだけがネック
// 懸念: GC 負担大丈夫?
ufcpp-live commented 2 years ago
// これはこれでほしい
// params Span とは別提案
// やるとしたら多分 immutable collection initializer が先
void m(params ImmutableArray<string> spans)
{
}
ufcpp-live commented 2 years ago
// 今までも最適かかかる(確か C# 7.2 のころくらいから)
// アロケーションが消える。
// というか、 new ReadOnlySpan<byte>(byte*, 4); だけ呼ばれる。
ReadOnlySpan<byte> b = new byte[] { 1, 2, 3, 4 };

// .NET 5 くらいから同じ理屈でこれも最適化かかってアロケーション消えてそう。
// (これは C# レベルじゃなくて JIT レベル)
ReadOnlySpan<char> c = "abcd";

// low level hackathon での議題。
// これのアロケーションも消したい。
// Big-Endian がネック…
// その機能付きの CreateSpan を足すみたい?
ReadOnlySpan<int> i = new int[] { 1, 2, 3, 4 };
ufcpp-live commented 2 years ago
int getOffsetX0(Direction dir)
{
    switch (dir)
    {
        case Direction.Up: return 0;
        case Direction.Down: return 0;
        case Direction.Left: return -1;
        case Direction.Right: return 1;
        default: return 0;
    }
}

int getOffsetXダメな例(Direction dir)
{
    var table = new[] { 0, 0, -1, 1 }; // ここでアロケーションがやばいww
    return table[(int)dir];
}

int getOffsetXこれなら大丈夫な例(Direction dir)
{
    ReadOnlySpan<sbyte> table = new sbyte[] { 0, 0, -1, 1 }; // こうすると早くなる。アロケーション消える
    return table[(int)dir];
}

enum Direction
{
    Up,
    Down,
    Left,
    Right,
    // もしくは東西南北
}
ufcpp-live commented 2 years ago
var f = static () => C.State++;

Console.WriteLine(f());
Console.WriteLine(f());
Console.WriteLine(f());

class C
{
    public static int State; // mutable static が地雷(元から)
}
ufcpp-live commented 2 years ago

これはさすがにハッカソンレベルで止まると個人的には思っているものの…

image

(本格的にジェネリック型引数の制限の方を取っ払ってほしい)

ufcpp-live commented 2 years ago

https://github.com/dotnet/runtime/tree/feature/lowlevelhackathon/ このブランチヤバイ。