ufcpp-live / UfcppLiveAgenda

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

Visual Studio 17.1.0 / 17.2 Preview 1, .NET 7 Preveiw 1 #54

Closed ufcpp closed 2 years ago

ufcpp commented 2 years ago

配信URL: https://www.youtube.com/watch?v=LLJVu161eVM

Visual Studio の方が先に出た

.NET 7 も出た

https://twitter.com/ufcpp/status/1493745221384822784

lang=json と raw string literal。 utf8 string literal はまだっぽい。

image

raw string literal、Preview 1 時点では IDE 側の対応が微妙に間に合ってなさげ。 リテラル内、 ctrl+矢印 移動の挙動がちょいへん。 リテラル内のインデントが狂う。 lang= 効いてない。

ufcpp commented 2 years ago
Console.WriteLine("""
    a
""".Length); // これが長さ5になってる。仕様変わった?それかまだ実装してないだけ?

その後見つけた挙動。バグっぽい。

var raw = """
    a
    """;

Console.WriteLine(raw.Length); // 1

Console.WriteLine("""
    a
""".Length); // 5
ufcpp commented 2 years ago

17.2p1 時点、StringSyntax 認識してなくない?

image

using System.Net;
using System.Text.Json;
using System.Text.RegularExpressions;

JsonDocument.Parse(@"
{
    ""id"": 123,
    ""name"": ""abc"",
    ""data"": [ true, null, 1.23 ]
}
");

Regex.Match("", @"\w+?"); // OK (昔からある特殊対応)

_ = new WebProxy("", true, new[] { @"\w+?" }); // 属性付いたのに

partial class R
{
    [RegexGenerator(@"\w+?")] // 属性付いてるのに
    public static partial Regex Digit3();
}
ufcpp commented 2 years ago

属性

ufcpp commented 2 years ago
本日の書き捨てコード ```cs using System.Net; using System.Numerics; using System.Text.Json; using System.Text.RegularExpressions; var v = new Vector3(1, 2, 3); //if (v is [ 1, 2, 3]) ; JsonDocument.Parse(@" { ""id"": 123, ""name"": ""abc"", ""data"": [ true, null, 1.23 ] } "); var rawString = """ { "id": 123, "name": "abc", "data": [ true, null, 1.23 ] } """; Console.WriteLine(rawString); //RegexOptions.NonBacktracking Regex.Match("", @"\d{3}"); // OK (昔からある特殊対応) _ = new WebProxy("", true, new[] { @"\d{3}" }); // 属性付いたのに partial class R { [RegexGenerator(@"\d{3}")] // 属性付いてるのに public static partial Regex Digit3(); } ```
ufcpp commented 2 years ago
噂の RegexGenerator NonBacktracking 遅い。 NonBacktracking は RegexGenerator まだ対応してないみたい(今作業中)。 対応してないと、単に `new Regex(pattern, options)` への丸投げが生成されてそう。 ```cs using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; using System.Text.RegularExpressions; BenchmarkRunner.Run(); partial class Reg { //lang=regex private const string _pattern = @"\d+$"; public static Regex Backtracking = new(_pattern); public static Regex NoBacktracking = new(_pattern, RegexOptions.NonBacktracking); public static Regex CompiledBacktracking = new(_pattern, RegexOptions.Compiled); public static Regex CompiledNoBacktracking = new(_pattern, RegexOptions.NonBacktracking | RegexOptions.Compiled); [RegexGenerator(_pattern)] public static partial Regex SourceGenBacktracking(); [RegexGenerator(_pattern, RegexOptions.NonBacktracking)] public static partial Regex SourceGenNoBacktracking(); } public class RegexBenchmark { private const string _input = "12345678987654321345432123456789098765432345678900987654345432123456765434567" + "12345678987654321345432123456789098765432345678900987654345432123456765434567" + "12345678987654321345432123456789098765432345678900987654345432123456765434567" + "12345678987654321345432123456789098765432345678900987654345432123456765434567" + "12345678987654321345432123456789098765432345678900987654345432123456765434567" + "12345678987654321345432123456789098765432345678900987654345432123456765434567" + "12345678987654321345432123456789098765432345678900987654345432123456765434567" + "12345678987654321345432123456789098765432345678900987654345432123456765434567" + "a"; [Benchmark] public bool Backtracking() => Reg.Backtracking.Match(_input).Success; [Benchmark] public bool NoBacktracking() => Reg.NoBacktracking.Match(_input).Success; [Benchmark] public bool CompiledBacktracking() => Reg.CompiledBacktracking.Match(_input).Success; [Benchmark] public bool CompiledNoBacktracking() => Reg.CompiledNoBacktracking.Match(_input).Success; [Benchmark] public bool SourceGenBacktracking() => Reg.SourceGenBacktracking().Match(_input).Success; [Benchmark] public bool SourceGenNoBacktracking() => Reg.SourceGenNoBacktracking().Match(_input).Success; } ```
ufcpp commented 2 years ago

17.2p1 どころか、17.1 リリース版でも、

image

ufcpp-live commented 2 years ago
JsonDocument.Parse(@"
{
    ""id"": 123,
    ""name"": ""abc"",
    ""data"": [ true, null, 1.23 ],
}
} // ここ OK になっちゃう。1個しか警告出ない疑惑
}
}
");
ufcpp-live commented 2 years ago

パースできるくせに警告だすんかいw

image

ufcpp-live commented 2 years ago
#pragma warning disable JSON001 // これ効き目あり

JsonDocument.Parse(@"
{
    ""id"": 123,
    ""name"": ""abc"",
    ""data"": [ true, null, 1.23 ],
}
");
ufcpp-live commented 2 years ago

ほしい(ない)

//lang=xml
var xml = @"<xml />";

//lang=csharp
var generated = $$"""
    class {{name}}
    {
        public int {{prop}} { get; init; }
    }
    """;
ufcpp-live commented 2 years ago

効いた。

image

ufcpp-live commented 2 years ago

implicit cast OK らしい。

m("[true, null]");
void m([StringSyntax("Json")] XNamespace r) { }
ufcpp-live commented 2 years ago
// 夢広がる?
m("[true, null]");
void m([StringSyntax("Json")] MyJsonShim r) { }

class MyJsonShim
{
    public static implicit operator MyJsonShim(string s) { }
    public static implicit operator JsonObject(MyJsonShim s) { }
}
ufcpp-live commented 2 years ago
// 未対応だけど、はよ
//lang=json
var rawString = $$"""
    {
        "id": {{id}},
        "name": "abc",
        "data": [ true, null, 1.23 ]
    }
    """;
ufcpp-live commented 2 years ago
Console.WriteLine("""
    a
""".Length); // 5 になるんだけどバグか?

// ちなみに、自分のミス。
// 正しくはこう。
Console.WriteLine("""
    a
    """.Length); // ここのインデント必要。これなら1
ufcpp-live commented 2 years ago

image

ufcpp-live commented 2 years ago

image

ufcpp-live commented 2 years ago

image

ufcpp-live commented 2 years ago
Console.WriteLine("""

    """.Length); // これが empty ということは…

Console.WriteLine("""
    """.Length); // これはエラー。
ufcpp-live commented 2 years ago
    // この2行は同じ結果になってそう
    [RegexGenerator(_pattern)]
    public static partial Regex A();

    [RegexGenerator(_pattern, RegexOptions.Compiled)]
    public static partial Regex B();
ufcpp-live commented 2 years ago

remove unnecessary lambda expression は↓こういう話。

image

ufcpp-live commented 2 years ago
using System.Numerics;

var v = new Vector3(1, 2, 3);

Console.WriteLine(v[0]);
Console.WriteLine(v[1]);
Console.WriteLine(v[2]);

Console.WriteLine(v.Length()); // √14

if (v is [1, 2, 3]) ; // コンパイルエラーになったよかった。
ufcpp-live commented 2 years ago

System.Drawing 非 Windows 退役 ↓ Microsoft.Maui.Graphics が後継候補