Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAST-321: Fix that array size passing is too eager with assignments #111

Merged
merged 7 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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