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

[Compiler+VM POC] Add compilation for default functions #3727

Draft
wants to merge 4 commits into
base: feature/compiler
Choose a base branch
from

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented Jan 16, 2025

Description

The default functions are brought/copied over at AST level, so that compiler can treat them similar to any other function that is defined within a composite type.

This PR introduces a separate desugar phase for such AST modifications, to decouple the tree re-writing logic from the compiler phase.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@SupunS SupunS added the Feature label Jan 16, 2025
@SupunS SupunS self-assigned this Jan 16, 2025
Copy link

Cadence Benchstat comparison

This branch with compared with the base branch onflow:feature/compiler commit a24debb
The command for i in {1..N}; do go test ./... -run=XXX -bench=. -benchmem -shuffle=on; done was used.
Bench tests were run a total of 7 times on each branch.

Collapsed results for better readability

// Inherited functions are always from interfaces
interfaceType := member.ContainerType.(*sema.InterfaceType)

elaboration, err := d.config.ElaborationResolver(interfaceType.Location)
Copy link
Member Author

Choose a reason for hiding this comment

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

There is a caveat here: In order to make this work for all/complex cases, this "imported"/"brought-over" elaboration also needs to be stored (or may be merged with the current program's elaborations). Because the compiler need type-info to compile certain things, and for these copied-over functions, type information is only available in their original elaboration (not in current program's elaboration).

This needs to be handled properly (this PR does not handles this).

@SupunS SupunS changed the title [Compiler+VM POC] Support default functions compilation [Compiler+VM POC] Add compilation for default functions Jan 16, 2025
Comment on lines -1382 to -1386
// desugarTransaction Convert a transaction into a composite type declaration,
// so the code-gen would seamlessly work without having special-case anything in compiler/vm.
// Transaction parameters are converted into global variables.
// An initializer is generated to set parameters to above generated global variables.
func (c *Compiler[_]) desugarTransaction(transaction *ast.TransactionDeclaration) (
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to the new desugar phase

@SupunS SupunS marked this pull request as ready for review January 16, 2025 23:44
@SupunS SupunS requested a review from turbolent as a code owner January 16, 2025 23:44
@SupunS SupunS requested a review from jsproz January 16, 2025 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant