Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[Serializable, AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public sealed class AsyncStateMachineAttribute : StateMachineAttribute
{
public AsyncStateMachineAttribute(Type stateMachineType)
: base(stateMachineType)
{
}
}
}

View File

@@ -0,0 +1,18 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public sealed class CallerFilePathAttribute : Attribute
{
public CallerFilePathAttribute()
{
}
}
}

View File

@@ -0,0 +1,18 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public sealed class CallerLineNumberAttribute : Attribute
{
public CallerLineNumberAttribute()
{
}
}
}

View File

@@ -0,0 +1,18 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public sealed class CallerMemberNameAttribute : Attribute
{
public CallerMemberNameAttribute()
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,30 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
//
// IAsyncStateMachine.cs
//
// <OWNER>[....]</OWNER>
//
// Represents state machines generated for asynchronous methods.
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
namespace System.Runtime.CompilerServices
{
/// <summary>
/// Represents state machines generated for asynchronous methods.
/// This type is intended for compiler use only.
/// </summary>
public interface IAsyncStateMachine
{
/// <summary>Moves the state machine to its next state.</summary>
void MoveNext();
/// <summary>Configures the state machine with a heap-allocated replica.</summary>
/// <param name="stateMachine">The heap-allocated replica.</param>
void SetStateMachine(IAsyncStateMachine stateMachine);
}
}

View File

@@ -0,0 +1,43 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
//
// INotifyCompletion.cs
//
// <OWNER>[....]</OWNER>
//
// Interfaces used to represent instances that notify listeners of their completion via continuations.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
using System;
using System.Security;
namespace System.Runtime.CompilerServices
{
/// <summary>
/// Represents an operation that will schedule continuations when the operation completes.
/// </summary>
public interface INotifyCompletion
{
/// <summary>Schedules the continuation action to be invoked when the instance completes.</summary>
/// <param name="continuation">The action to invoke when the operation completes.</param>
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
void OnCompleted(Action continuation);
}
/// <summary>
/// Represents an awaiter used to schedule continuations when an await operation completes.
/// </summary>
public interface ICriticalNotifyCompletion : INotifyCompletion
{
/// <summary>Schedules the continuation action to be invoked when the instance completes.</summary>
/// <param name="continuation">The action to invoke when the operation completes.</param>
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
/// <remarks>Unlike OnCompleted, UnsafeOnCompleted need not propagate ExecutionContext information.</remarks>
[SecurityCritical]
void UnsafeOnCompleted(Action continuation);
}
}

View File

@@ -0,0 +1,19 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[Serializable, AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public sealed class IteratorStateMachineAttribute : StateMachineAttribute
{
public IteratorStateMachineAttribute(Type stateMachineType)
: base(stateMachineType)
{
}
}
}

View File

@@ -0,0 +1,40 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Attribute: ReferenceAssemblyAttribute
**
** Purpose: Identifies an assembly as being a "reference
** assembly", meaning it contains public surface area but
** no usable implementation. Reference assemblies
** should be loadable for introspection, but not execution.
**
============================================================*/
namespace System.Runtime.CompilerServices
{
using System;
[Serializable]
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=false)]
public sealed class ReferenceAssemblyAttribute : Attribute
{
private String _description; // Maybe ".NET FX v4.0 SP1, partial trust"?
public ReferenceAssemblyAttribute()
{
}
public ReferenceAssemblyAttribute(String description)
{
_description = description;
}
public String Description
{
get { return _description; }
}
}
}

View File

@@ -0,0 +1,50 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*=============================================================================
**
** Class: RuntimeCompatibilityAttribute
**
**
** Purpose: Mark up the program to indicate various legacy or new opt-in behaviors.
**
**
=============================================================================*/
namespace System.Runtime.CompilerServices
{
using System;
[Serializable]
[AttributeUsage(AttributeTargets.Assembly, Inherited=false, AllowMultiple=false)]
public sealed class RuntimeCompatibilityAttribute : Attribute
{
// fields
private bool m_wrapNonExceptionThrows;
// constructors
public RuntimeCompatibilityAttribute() {
// legacy behavior is the default, and m_wrapNonExceptionThrows is implicitly
// false thanks to the CLR's guarantee of zeroed memory.
}
// properties
// If a non-CLSCompliant exception (i.e. one that doesn't derive from System.Exception) is
// thrown, should it be wrapped up in a System.Runtime.CompilerServices.RuntimeWrappedException
// instance when presented to catch handlers?
public bool WrapNonExceptionThrows {
get {
return m_wrapNonExceptionThrows;
}
set {
m_wrapNonExceptionThrows = value;
}
}
}
}

View File

@@ -0,0 +1,54 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*=============================================================================
**
** Class: RuntimeWrappedException
**
**
** Purpose: The exception class uses to wrap all non-CLS compliant exceptions.
**
**
=============================================================================*/
namespace System.Runtime.CompilerServices {
using System;
using System.Runtime.Serialization;
using System.Runtime.Remoting;
using System.Security.Permissions;
using System.Diagnostics.Contracts;
[Serializable]
public sealed class RuntimeWrappedException : Exception
{
private RuntimeWrappedException(Object thrownObject)
: base(Environment.GetResourceString("RuntimeWrappedException")) {
SetErrorCode(System.__HResults.COR_E_RUNTIMEWRAPPED);
m_wrappedException = thrownObject;
}
public Object WrappedException {
get { return m_wrappedException; }
}
private Object m_wrappedException;
[System.Security.SecurityCritical] // auto-generated_required
public override void GetObjectData(SerializationInfo info, StreamingContext context) {
if (info==null) {
throw new ArgumentNullException("info");
}
Contract.EndContractBlock();
base.GetObjectData(info, context);
info.AddValue("WrappedException", m_wrappedException, typeof(Object));
}
internal RuntimeWrappedException(SerializationInfo info, StreamingContext context)
: base(info, context) {
m_wrappedException = info.GetValue("WrappedException", typeof(Object));
}
}
}

View File

@@ -0,0 +1,21 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Runtime.CompilerServices
{
[Serializable, AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public class StateMachineAttribute : Attribute
{
public Type StateMachineType { get; private set; }
public StateMachineAttribute(Type stateMachineType)
{
this.StateMachineType = stateMachineType;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,36 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)]
public sealed class TypeForwardedFromAttribute : Attribute
{
string assemblyFullName;
private TypeForwardedFromAttribute()
{
// Disallow default constructor
}
public TypeForwardedFromAttribute(string assemblyFullName)
{
if (String.IsNullOrEmpty(assemblyFullName))
{
throw new ArgumentNullException("assemblyFullName");
}
this.assemblyFullName = assemblyFullName;
}
public string AssemblyFullName
{
get {
return assemblyFullName;
}
}
}
}

View File

@@ -0,0 +1,48 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
using System.Reflection;
namespace System.Runtime.CompilerServices
{
using System;
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true, Inherited=false)]
public sealed class TypeForwardedToAttribute : Attribute
{
private Type _destination;
public TypeForwardedToAttribute(Type destination)
{
_destination = destination;
}
public Type Destination
{
get {
return _destination;
}
}
#if false
[System.Security.SecurityCritical]
internal static TypeForwardedToAttribute[] GetCustomAttribute(RuntimeAssembly assembly)
{
Type[] types = null;
RuntimeAssembly.GetForwardedTypes(assembly.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types));
TypeForwardedToAttribute[] attributes = new TypeForwardedToAttribute[types.Length];
for (int i = 0; i < types.Length; ++i)
attributes[i] = new TypeForwardedToAttribute(types[i]);
return attributes;
}
#endif
}
}

View File

@@ -0,0 +1,166 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
//
// YieldAwaitable.cs
//
// <OWNER>[....]</OWNER>
//
// Compiler-targeted type for switching back into the current execution context, e.g.
//
// await Task.Yield();
// =====================
// var $awaiter = Task.Yield().GetAwaiter();
// if (!$awaiter.IsCompleted)
// {
// $builder.AwaitUnsafeOnCompleted(ref $awaiter, ref this);
// return;
// Label:
// }
// $awaiter.GetResult();
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
using System;
using System.Security;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Diagnostics.Tracing;
using System.Threading;
using System.Threading.Tasks;
using System.Security.Permissions;
namespace System.Runtime.CompilerServices
{
// NOTE: YieldAwaitable currently has no state; while developers are encouraged to use Task.Yield() to produce one,
// no validation is performed to ensure that the developer isn't doing "await new YieldAwaitable()". Such validation
// would require additional, useless state to be stored, and as this is a type in the CompilerServices namespace, and
// as the above example isn't harmful, we take the cheaper approach of not validating anything.
/// <summary>Provides an awaitable context for switching into a target environment.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
public struct YieldAwaitable
{
/// <summary>Gets an awaiter for this <see cref="YieldAwaitable"/>.</summary>
/// <returns>An awaiter for this awaitable.</returns>
/// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
public YieldAwaiter GetAwaiter() { return new YieldAwaiter(); }
/// <summary>Provides an awaiter that switches into a target environment.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
[HostProtection(Synchronization = true, ExternalThreading = true)]
public struct YieldAwaiter : ICriticalNotifyCompletion
{
/// <summary>Gets whether a yield is not required.</summary>
/// <remarks>This property is intended for compiler user rather than use directly in code.</remarks>
public bool IsCompleted { get { return false; } } // yielding is always required for YieldAwaiter, hence false
/// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
/// <param name="continuation">The action to invoke asynchronously.</param>
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
[SecuritySafeCritical]
public void OnCompleted(Action continuation)
{
QueueContinuation(continuation, flowContext: true);
}
/// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
/// <param name="continuation">The action to invoke asynchronously.</param>
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
[SecurityCritical]
public void UnsafeOnCompleted(Action continuation)
{
QueueContinuation(continuation, flowContext: false);
}
/// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
/// <param name="continuation">The action to invoke asynchronously.</param>
/// <param name="flowContext">true to flow ExecutionContext; false if flowing is not required.</param>
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
[SecurityCritical]
private static void QueueContinuation(Action continuation, bool flowContext)
{
// Validate arguments
if (continuation == null) throw new ArgumentNullException("continuation");
Contract.EndContractBlock();
#if !FEATURE_PAL && !FEATURE_CORECLR // PAL and CoreClr don't support eventing
if (TplEtwProvider.Log.IsEnabled())
{
continuation = OutputCorrelationEtwEvent(continuation);
}
#endif
// Get the current SynchronizationContext, and if there is one,
// post the continuation to it. However, treat the base type
// as if there wasn't a SynchronizationContext, since that's what it
// logically represents.
var syncCtx = SynchronizationContext.CurrentNoFlow;
if (syncCtx != null && syncCtx.GetType() != typeof(SynchronizationContext))
{
syncCtx.Post(s_sendOrPostCallbackRunAction, continuation);
}
else
{
// If we're targeting the default scheduler, queue to the thread pool, so that we go into the global
// queue. As we're going into the global queue, we might as well use QUWI, which for the global queue is
// just a tad faster than task, due to a smaller object getting allocated and less work on the execution path.
TaskScheduler scheduler = TaskScheduler.Current;
if (scheduler == TaskScheduler.Default)
{
if (flowContext)
{
ThreadPool.QueueUserWorkItem(s_waitCallbackRunAction, continuation);
}
else
{
ThreadPool.UnsafeQueueUserWorkItem(s_waitCallbackRunAction, continuation);
}
}
// We're targeting a custom scheduler, so queue a task.
else
{
Task.Factory.StartNew(continuation, default(CancellationToken), TaskCreationOptions.PreferFairness, scheduler);
}
}
}
#if !FEATURE_PAL && !FEATURE_CORECLR // PAL and CoreClr don't support eventing
private static Action OutputCorrelationEtwEvent(Action continuation)
{
int continuationId = Task.NewId();
Task currentTask = Task.InternalCurrent;
// fire the correlation ETW event
TplEtwProvider.Log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id, (currentTask != null) ? currentTask.Id : 0, continuationId);
return AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, () =>
{
// ETW event for Task Wait End.
Guid prevActivityId = new Guid();
// Ensure the continuation runs under the correlated activity ID generated above
EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(continuationId), out prevActivityId);
// Invoke the original continuation provided to OnCompleted.
continuation();
// Restore activity ID
EventSource.SetCurrentThreadActivityId(prevActivityId);
});
}
#endif
/// <summary>WaitCallback that invokes the Action supplied as object state.</summary>
private static readonly WaitCallback s_waitCallbackRunAction = RunAction;
/// <summary>SendOrPostCallback that invokes the Action supplied as object state.</summary>
private static readonly SendOrPostCallback s_sendOrPostCallbackRunAction = RunAction;
/// <summary>Runs an Action delegate provided as state.</summary>
/// <param name="state">The Action delegate to invoke.</param>
private static void RunAction(object state) { ((Action)state)(); }
/// <summary>Ends the await operation.</summary>
public void GetResult() {} // Nop. It exists purely because the compiler pattern demands it.
}
}
}

View File

@@ -0,0 +1,32 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
namespace System.Runtime.CompilerServices
{
using System;
[AttributeUsage(AttributeTargets.Field)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class AccessedThroughPropertyAttribute : Attribute
{
private readonly string propertyName;
public AccessedThroughPropertyAttribute(string propertyName)
{
this.propertyName = propertyName;
}
public string PropertyName
{
get
{
return propertyName;
}
}
}
}

View File

@@ -0,0 +1,44 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace System.Runtime.CompilerServices {
using System;
// NOTE TO DEVELOPERS: These classes are used by ALink (the assembly linker).
// They're used for metadata tokens for making multi-module assemblies.
// Do not randomly touch these classes.
[System.Runtime.CompilerServices.FriendAccessAllowed]
internal sealed class AssemblyAttributesGoHere
{
internal AssemblyAttributesGoHere()
{
}
}
[System.Runtime.CompilerServices.FriendAccessAllowed]
internal sealed class AssemblyAttributesGoHereS
{
internal AssemblyAttributesGoHereS()
{
}
}
[System.Runtime.CompilerServices.FriendAccessAllowed]
internal sealed class AssemblyAttributesGoHereM
{
internal AssemblyAttributesGoHereM()
{
}
}
[System.Runtime.CompilerServices.FriendAccessAllowed]
internal sealed class AssemblyAttributesGoHereSM
{
internal AssemblyAttributesGoHereSM()
{
}
}
}

View File

@@ -0,0 +1,95 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace System.Runtime.CompilerServices
{
using System;
using System.Runtime.InteropServices;
/*
NGenHint is not supported in Whidbey
[Serializable]
public enum NGenHint
{
Default = 0x0000, // No preference specified
Eager = 0x0001, // NGen at install time
Lazy = 0x0002, // NGen after install time
Never = 0x0003, // Assembly should not be ngened
}
*/
[Serializable]
public enum LoadHint
{
Default = 0x0000, // No preference specified
Always = 0x0001, // Dependency is always loaded
Sometimes = 0x0002, // Dependency is sometimes loaded
//Never = 0x0003, // Dependency is never loaded
}
[Serializable]
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class DefaultDependencyAttribute : Attribute
{
private LoadHint loadHint;
public DefaultDependencyAttribute (
LoadHint loadHintArgument
)
{
loadHint = loadHintArgument;
}
public LoadHint LoadHint
{
get
{
return loadHint;
}
}
}
[Serializable]
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class DependencyAttribute : Attribute
{
private String dependentAssembly;
private LoadHint loadHint;
public DependencyAttribute (
String dependentAssemblyArgument,
LoadHint loadHintArgument
)
{
dependentAssembly = dependentAssemblyArgument;
loadHint = loadHintArgument;
}
public String DependentAssembly
{
get
{
return dependentAssembly;
}
}
public LoadHint LoadHint
{
get
{
return loadHint;
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More