Skip to content

Instantly share code, notes, and snippets.

View svick's full-sized avatar

Petr Onderka svick

View GitHub Profile

Expression variables in query expressions (version 4)

An expression variable is considered to be a promoted expression variable, when it's declared in the expression of a second or subsequent from clause, a let clause or a where clause and it's also referenced in one or more following clauses of the same query (but not across an into clause). Such expression variables are promoted into range variables.

Expression variables are allowed in all query clauses, but they affect how the query is translated only if they are promoted expression variables.

Translation

For an expression e with one or more promoted expression variables v1, ..., vn, its expanded form ee is the anonymous object creation expression fragment eo = e, v1, ... vn, where eo is a compiler generated identifier that is invisible and inaccessible, except when mentioned in this section.

Option Strict On
Imports System
Imports Microsoft.CodeAnalysis.CSharp.Scripting
Module Program
Sub Main()
Dim hashCode As Byte = 42
Dim data As Byte() = { 1, 2, 3 }
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.10.11" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.6.1" />
</ItemGroup>
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Running;
[Config(typeof(Config))]
public class Program
{
public class Config : ManualConfig
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
using Microsoft.CodeAnalysis;
// based on https://github.com/dotnet/corefx/blob/389d7ee/src/System.Memory/tests/Memory/CustomMemoryForTest.cs
unsafe class HGlobalMemory : OwnedMemory<byte>
{
private bool _disposed;
private int _referenceCount;
private byte* _buffer;
private int _length;
public HGlobalMemory(int length)
{
M1:
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: ldarg.3
IL_0003: ldelem.i4
IL_0004: ldarg.2
IL_0005: ldarg.3
IL_0006: ldelem.i4
IL_0007: call Select<Int32>
IL_000C: ret
Microsoft.CodeAnalysis.CSharp.UnitTests.ColorColorTests.VersionUnificationConstColorColorEnum FAILED:
Exception type: 'Xunit.Sdk.TrueException', number: '0', parent: '-1'
Exception message:
Expected:
Diagnostic(ErrorCode.WRN_UnifyReferenceMajMin).WithArguments("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "RefLib", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "mscorlib"),
Diagnostic(ErrorCode.WRN_UnifyReferenceMajMin).WithArguments("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "RefLib", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "mscorlib"),
Diagnostic(ErrorCode.WRN_UnifyReferenceMajMin).WithArguments("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "RefLib", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "mscorlib"),
Diagnostic(ErrorCode.WRN_UnifyR
using System;
using System.Runtime.CompilerServices;
class Program
{
static void Main()
{
var c = new C();
Today(c);
Tomorrow(c);
<?xml version="1.0" encoding="utf-8"?>
<Types>
<Type TypeName="System.Collections.Generic.Dictionary`2" Kind="other" Allocs="920661" Bytes="73652880" />
<Type TypeName="System.Collections.Generic.Dictionary`2.Entry[]" Kind="other" Allocs="505418" Bytes="72721400" />
<Type TypeName="System.Char[]" Kind="other" Allocs="381972" Bytes="71627444" />
<Type TypeName="System.String" Kind="other" Allocs="945578" Bytes="71515882" />
<Type TypeName="System.Byte[]" Kind="other" Allocs="667362" Bytes="65043982" />
<Type TypeName="System.Collections.Generic.KeyValuePair`2[]" Kind="other" Allocs="750010" Bytes="57476416" />
<Type TypeName="System.Data.SqlClient.TdsParserStateObject.StateSnapshot" Kind="other" Allocs="471968" Bytes="49084672" />
<Type TypeName="System.Collections.Generic.List`1" Kind="other" Allocs="1225122" Bytes="49004880" />