Skip to content

Commit

Permalink
more PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
VSadov committed Mar 5, 2018
1 parent d0bb51d commit b13c65c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/Compilers/CSharp/Portable/CodeGen/EmitConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,21 @@ private void EmitConversionExpression(BoundConversion conversion, bool used)

private void EmitSpecialUserDefinedConversion(BoundConversion conversion, bool used, BoundExpression operand)
{
var typeTo = conversion.Type;
var typeTo = (NamedTypeSymbol)conversion.Type;

Debug.Assert((operand.Type.IsArray()) &&
this._module.Compilation.IsReadOnlySpanType(typeTo),
"only special kinds of conversions involvling ReadOnlySpan may be handled in emit");
"only special kinds of conversions involving ReadOnlySpan may be handled in emit");

if (!TryEmitReadonlySpanAsBlobWrapper((NamedTypeSymbol)typeTo, operand, used, inPlace: false))
if (!TryEmitReadonlySpanAsBlobWrapper(typeTo, operand, used, inPlace: false))
{
// there are several reasons that could prevent us from emitting a wrapper
// in such case we just emit the operand and then invoke the conversion method
EmitExpression(operand, used);
if (used)
{
_builder.EmitOpCode(ILOpCode.Call, 0);
// consumes 1 argument (array) and produces one result (span)
_builder.EmitOpCode(ILOpCode.Call, stackAdjustment: 0);
EmitSymbolToken(conversion.SymbolOpt, conversion.Syntax, optArgList: null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1016,10 +1016,9 @@ private BoundExpression RewriteUserDefinedConversion(

// do not rewrite user defined conversion
// - in expression trees or
// - special situations when converting to ReadOnlySpan, which has special support in codegen
var doNotLowerToCall = _inExpressionLambda ||
(rewrittenOperand.Type.IsArray()) &&
_compilation.IsReadOnlySpanType(rewrittenType);
// - special situations when converting from array to ReadOnlySpan, which has special support in codegen
bool doNotLowerToCall = _inExpressionLambda ||
(rewrittenOperand.Type.IsArray()) && _compilation.IsReadOnlySpanType(rewrittenType);

BoundExpression result =
doNotLowerToCall
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,9 +1343,9 @@ public ref readonly T Current
}
}
public static implicit operator ReadOnlySpan<T>(T[] array) => array == null? default: new ReadOnlySpan<T>(array);
public static implicit operator ReadOnlySpan<T>(T[] array) => array == null ? default : new ReadOnlySpan<T>(array);
public static implicit operator ReadOnlySpan<T>(string stringValue) => string.IsNullOrEmpty(stringValue)? default: new ReadOnlySpan<T>((T[])(object)stringValue.ToCharArray());
public static implicit operator ReadOnlySpan<T>(string stringValue) => string.IsNullOrEmpty(stringValue) ? default : new ReadOnlySpan<T>((T[])(object)stringValue.ToCharArray());
}
public readonly ref struct SpanLike<T>
Expand Down

0 comments on commit b13c65c

Please sign in to comment.