Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Conversation

@bettinaheim
Copy link
Contributor

@bettinaheim bettinaheim commented Mar 8, 2021

This PR implements implements generating an entry point wrapper during QIR emission that has a signature that does not rely on any QIR specific/opaque types. Generating this wrapper allows to decouple e.g. the command line processing or other driver code from the runtime implementation. The generated wrapper itself relies on the existence of a malloc function (__quantum_rt__memory_allocate) in the runtime.

More tests will follow shortly.
If the e2e build fails, that would be a good sign: The e2e should currently fail if it is properly running the runtime tests against the compiler edits, since I finally adjusted the string creation signature to match the specs.

This PR also contains

  • a bug fix that the declarations for monomorphized functions that are implemented either directly in llvm or via a call to a runtime function were not properly stripped (see OriginalNameFromMonomorphized)
  • fixes an issue for when discarding the loop variable in for-loops over ranges (in StatementTransformation.cs)
  • replaces the call to __quantum__rt__int_power with suitable casts and an invokation to llvm.powi instead
    Sorry for not properly splitting out those changes - we have I think at least 3 more PRs queued up and it is getting a bit cumbersome to coordinate. We need to unify all of that and then working against main should facilitate keeping a proper structure for PRs...

Additional infos to facilitate review:
For this PR, the changes that contain the core of the functionality outlined in the description are in Interop.cs. The changes in particular are in the generation of the wrapper function for the entry point. The method GenerateWrapper generates that wrapper. MapToInteropType defines how QIR types in entry point signatures are replaced in the entry point wrapper. ProcessArguments does that replacement for argument; i.e. it maps "generic types" -> QIR types. ProcessReturnValue does that replacement for the return value; i.e. it maps QIR types -> "generic types". Having one general purpose function doing both, i.e. one function to map types A <-> types B, with the types A and B fully configurable would be nice, but makes the code really tedious both to write, read and maintain, so I decided to favor the two separate functions in this case.

Configuration.cs has been removed. While it might in general be valuable to allow to configure the QIR emission, the only configuration options that were available so far was the names of the types that the QIR runtime uses to represent the opaque QIR types and other QIR pointer types. Having thought a bit about how to package everything, I believe it is a better approach not to use those in the wrapper to decouple the dependency on the runtime from the entry point driver (C++ or other native code calling into QIR) and command line handling. I believe this should save us some packaging grievances. This comes at the cost of needing the runtime to provide something like a malloc function (__quantum__rt__memory_allocate).

bamarsha and others added 30 commits January 26, 2021 12:16
* Use RuntimeCapability type in qsc/LS

* Update capability names in SDK
* Continue on error in check style step

* Test bad formatting

* Use separate job for check style

* Fix WrapUp job name

* Fix initialize job steps

* Run init/steps/wrap-up in same job

* Remove dependsOn

* Revert some changes

* Revert "Test bad formatting"

This reverts commit a59e4f7.
* Hide internal, ```Q# → ```qsharp, and fix ms.topic.

* Update src/Documentation/DocumentationGenerator/ProcessDocComments.cs

Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com>

* Update src/Documentation/DocumentationGenerator/ProcessDocComments.cs

Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com>

* Added missing using statement.

Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com>
* Update global.json and use .NET 5 in CI

* Fix .NET version

* Use 3.1 runtime

* Use 3.1 SDK instead of runtime
Added template README file.
This change updates yeoman-environment package version from 2.9.6 to 2.10.3, back to the configuration used in the QDK version 0.14.2011120240.
Updated Interpolated String Delimiter Logic for Code Lines.
* Add Q# source code formatter

* Add formatter to build scripts

* Formatting

* Add docs to Discoverer.fs

* Add links to original language spec grammars

* Add copyright headers

* Update README

* Clean up Parser.csproj a little

* Add properties for ANTLR version and JAR name

* Add quotes in command line

* Use AntlrInput variable for ANTLR command

* Update command line interface

* Use inferred type

* Add CLI tests

* Formatting

* Add (skipped) identity tests

* Don't format if there are syntax errors

* Remove error token hiding

* Add error tests

* Filter out test cases with invalid syntax

* Use Microsoft.Quantum namespace prefix

* Update README

* Add comments to Program.fs

* Fix duplicate error messages

* Add IO exception handlers

* Replace several facts with theories

* Remove nameof

* Add limitations to readme

* Remove whitespace/comment types

* Add TODO to CallableDeclaration

* Add signature files

* Remove redundant access modifiers

* Rename Formatter to QsFmt

* Update solution name in scripts
…ax tree (#835)

* Use Public instead of DefaultAccess

* Deprecate AccessModifier and Modifiers

* Formatting

* Comment out reference to Example project

* Skip execution tests

* Update variable names in doc generator

* Update tuple item names in CompilationUnit

* Update more names/functions to visibility

* Update terminology in Namespace.fs

* Update terminology in NamespaceManager.fs

* Deprecate QsNullable<T>.FromOption

* Update Monomorphization.cs

* Update more terminology

* Add doc comments

* Hide records

* Re-enable execution tests

* Update runtime packages

* Minor version 15

* Update ProcessDocComments.cs

* Remove unused using

* Rename Visibility to Access

* IsVisible -> IsAccessible

* Visibility -> accessibility

* Disable execution tests

* More general name

* Revert "Disable execution tests"

This reverts commit 7c8a675.

* Update runtime packages

* Add backwards compatible Modifiers properties
Copy link
Contributor

@kuzminrobin kuzminrobin left a comment

Choose a reason for hiding this comment

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

I was mostly looking at .lls and .qss. I don't understand most of the other (.cs, .fs) files.
What I looked at seems good to me.

@bettinaheim bettinaheim changed the base branch from feature/qir to swernli/standalone-llvm-2 March 11, 2021 02:12
Copy link
Contributor

@cesarzc cesarzc left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@bettinaheim bettinaheim changed the base branch from swernli/standalone-llvm-2 to feature/qir March 12, 2021 02:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants