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

feat: Add initial codegen extension for prelude #29

Merged
merged 4 commits into from
Jun 18, 2024
Merged

Conversation

doug-q
Copy link
Collaborator

@doug-q doug-q commented Jun 17, 2024

Note that this extension is not intended to be complete, just enough to get started.

We include some simplification of test infrastructure, although it is not strictly necessary. An earlier approach required these changes.

@doug-q
Copy link
Collaborator Author

doug-q commented Jun 17, 2024

Note that this PR is based on #26 for some of it's testing changes. That is why CI is not currently running. Please do not merge until that PR is merged and this one is rebased on main.

/// default implementations.
///
/// One should use either [PreludeCodegenExtension::new], or
/// [CodegenExtsMap::add_prelude_extensions] to work with the

Choose a reason for hiding this comment

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

So, if for some reason we wanted to tweak code generation for prelude constructs for different targets, we have the flexibility of defining code generation for this new target by implementing the PreludeCodegen trait? That seems very useful if we want to create custom lowering to QIR for other targets that is spec compliant.

@@ -70,8 +71,7 @@ pub struct TestContext {

impl TestContext {
fn new(
ext_builder: impl for<'a> Fn(CodegenExtsMap<'a, THugrView>) -> CodegenExtsMap<'a, THugrView>
+ 'static,
ext_builder: impl for<'a> Fn(&'a Context) -> CodegenExtsMap<'a, THugrView> + 'static,

Choose a reason for hiding this comment

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

Not necessary for me to approve the PR but can you explain the for<'a> notation to me? I haven't seen it, and I can't really tell what it is necessary for the signature.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This explains it better than I can: https://doc.rust-lang.org/nomicon/hrtb.html

The signature needs to convey that the lifetime of the incoming Context and outgoing CodegenExtsMap are the same, so the liftetime needs a name.

Copy link

@peter-campora peter-campora left a comment

Choose a reason for hiding this comment

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

LGTM

Base automatically changed from doug/cfg to main June 18, 2024 12:14
Note that this extension is not intended to be complete, just enough to
get started.

We include some simplification of test infrastructure, although it is
not strictly necessary. An earlier approach required these changes.
@doug-q doug-q added this pull request to the merge queue Jun 18, 2024
Merged via the queue into main with commit 4b51a4c Jun 18, 2024
10 checks passed
@doug-q doug-q deleted the doug/init-prelude branch June 18, 2024 12:35
@hugrbot hugrbot mentioned this pull request Jun 26, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 10, 2024
## 🤖 New release
* `hugr-llvm`: 0.1.0

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.1.0](https://github.com/CQCL/hugr-llvm/releases/tag/v0.1.0) -
2024-07-10

### Bug Fixes
- Syntax error
- sum type tag elision logic reversed
- [**breaking**] Allow Const and FuncDecl as children of Modules,
Dataflow Parents, and CFG nodes
([#46](#46))

### Documentation
- fix bad grammar ([#34](#34))

### New Features
- Emission for Call nodes
- Support  values
- add `get_extern_func`
([#28](#28))
- lower CFGs ([#26](#26))
- Add initial codegen extension for `prelude`
([#29](#29))
- [**breaking**] `Namer` optionally appends node index to mangled names.
([#32](#32))
- Implement lowerings for ieq,ilt_s,sub in int codegen extension
([#33](#33))
- Add initial `float` extension
([#31](#31))
- Emit more int comparison operators
([#47](#47))

### Refactor
- clean up fat.rs ([#38](#38))

### Testing
- add a test for sum type tags
- Add integration tests lowering guppy programs
([#35](#35))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).

---------

Co-authored-by: Douglas Wilson <douglas.wilson@quantinuum.com>
@hugrbot hugrbot mentioned this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants