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

Support MemRepTuple in the Nockma backend #2586

Merged
merged 4 commits into from
Jan 23, 2024
Merged

Support MemRepTuple in the Nockma backend #2586

merged 4 commits into from
Jan 23, 2024

Conversation

janmasrovira
Copy link
Collaborator

@janmasrovira janmasrovira commented Jan 22, 2024

We can represent Anoma types like resource as Juvix records.

The Nockma encoding of types uses Nockma 'tuples' where each component of the tuple holds a value of a field. So for Juvix->Anoma integration it is convenient to compile values of record types as Nockma tuples.

We already have the concept of representing constructors of inductive types that have only one non-zero-field constructor in the compiler, see MemRepTuple.

In this PR, as part of the Nockma step, we mark constructors that satisfy the requirements of the MemRepTuple translation as such. Then we use a tuple encoding for those constructors.

@@ -46,6 +46,7 @@ data ConstructorInfo = ConstructorInfo
_constructorTag :: Tag,
_constructorType :: Type,
_constructorArgNames :: [Maybe Text],
_constructorArgsNum :: Int,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_constructorArgsNum is always equal to length (typeArgs _constructorType), I guess? There should be a comment that this field is only a "cache" for this value.

mkConstructorInfo ci@Asm.ConstructorInfo {..} =
ConstructorInfo
{ _constructorInfoArity = fromIntegral _constructorArgsNum,
_constructorInfoMemRep = nockmaMemRep (memRep ci (getInductiveInfo (ci ^. Asm.constructorInductive)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but ultimately it would be good to have a (parameterised) transformation on JuvixTree which calculates the representations. It can only be used with the Nockma pipeline until the C code generation supports the representations, but later it could be re-used.

@lukaszcz lukaszcz merged commit 510490a into main Jan 23, 2024
4 checks passed
@lukaszcz lukaszcz deleted the nockma-memrep branch January 23, 2024 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants