Skip to content

Commit

Permalink
Merge pull request #111 from Lombiq/issue/HAST-321
Browse files Browse the repository at this point in the history
HAST-321: Fix that array size passing is too eager with assignments
  • Loading branch information
sarahelsaig authored Sep 22, 2023
2 parents aed9b6f + e97463d commit 49ab6d2
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 36 deletions.
4 changes: 2 additions & 2 deletions NuGetTest/Hast.NuGet.Console/Hast.NuGet.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hast.Algorithms" Version="2.1.0" />
<PackageReference Include="Hast.Layer" Version="2.1.0" />
<PackageReference Include="Hast.Algorithms" Version="2.1.1-alpha.0.hast-321" />
<PackageReference Include="Hast.Layer" Version="2.1.1-alpha.0.hast-321" />
<PackageReference Include="Hast.Vitis.HardwareFramework" Version="1.2.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ private void VerifyHardwareEntryPoints(SyntaxTree syntaxTree, ITypeDeclarationLo
{
var unsupportedMembers = type
.Members
.Where(member => member is FieldDeclaration || member is PropertyDeclaration || member.GetFullName().IsConstructorName());
.Where(member =>
(member is FieldDeclaration or PropertyDeclaration && !member.HasModifier(Modifiers.Const)) ||
member.GetFullName().IsConstructorName());
if (unsupportedMembers.Any())
{
throw new NotSupportedException(
Expand Down
8 changes: 4 additions & 4 deletions src/Hastlayer/Hast.Transformer/Models/IArraySizeHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public static IArraySize GetSizeOrThrow(this IArraySizeHolder arraySizeHolder, A
if (size == null)
{
throw new NotSupportedException(
"The length of the array holder " + arrayHolder.GetFullName() +
" couldn't be statically determined. Only arrays with dimensions defined at compile-time are " +
"supported. If the array size is actually static just Hastlayer can't figure it out for some " +
"reason then you can configure it manually via TransformerConfiguration.");
"The length of the array holder \"" + arrayHolder.GetFullName() + "\" couldn't be statically " +
"determined. Only arrays with dimensions defined at compile-time are supported. If the array size is " +
"actually static just Hastlayer can't figure it out for some reason then you can configure it " +
"manually via TransformerConfiguration by using the quoted full name.");
}

return size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ private void PassLengthOfArrayHolderToParent(AstNode arrayHolder, int arrayLengt
{
AssignmentHandler = assignmentExpression =>
{
// Only assignments where an array is assigned to another member/variable matters, not just any
// assignment where arrayHolder is on the right (excluding cases where e.g. the right side is a
// method call with an array as an argument).
if (assignmentExpression.Right != arrayHolder &&
assignmentExpression.Right is InvocationExpression invocationExpression &&
invocationExpression.Target != arrayHolder)
{
return;
}
if (assignmentExpression.Left is MemberReferenceExpression memberReferenceExpression)
{
_arraySizeHolder.SetSize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,10 @@ protected override void VisitChildren(AstNode node)
}
}

// Is this a const? Then we can just substitute it directly.
// Is this a const expression? Then we can just substitute it directly.
var resolveResult = node.GetResolveResult();
if (resolveResult?.IsCompileTimeConstant == true &&
if (node is Expression &&
resolveResult?.IsCompileTimeConstant == true &&
resolveResult.ConstantValue != null &&
node is not PrimitiveExpression)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup Condition="$(SolutionName) == 'Hastlayer.SDK.NuGet'">
<PackageReference Include="Hast.Algorithms" Version="2.1.0" />
<PackageReference Include="Hast.Layer" Version="2.1.0" />
<PackageReference Include="Hast.Algorithms" Version="2.1.1-alpha.0.hast-321" />
<PackageReference Include="Hast.Layer" Version="2.1.1-alpha.0.hast-321" />
<PackageReference Include="Lombiq.Arithmetics" Version="0.0.1-alpha.3.hast-175" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public Task StaticTestInputAssemblyMatchesApproved() =>
new[] { typeof(ArrayUsingCases).Assembly },
configuration =>
{
configuration.TransformerConfiguration().UseSimpleMemory = false;
var transformerConfiguration = configuration.TransformerConfiguration();
transformerConfiguration.UseSimpleMemory = false;
// This shouldn't be necessary: https://github.com/Lombiq/Hastlayer-SDK/issues/112.
transformerConfiguration.ArrayLengths.Add(
"System.Int32 Hast.TestInputs.Static.ArrayUsingCases+<>c::<PassArrayToTask>b__1_0(System.Object).arrayObject",
ArrayUsingCases.TaskArrayLength);
configuration
.TransformerConfiguration()
Expand Down
Loading

0 comments on commit 49ab6d2

Please sign in to comment.