/// <summary>
        /// Eliminates all conjugations from the given compilation by replacing them with the corresponding implementations (i.e. inlining them).
        /// The generation of the adjoint for the outer block is subject to the same limitation as any adjoint auto-generation.
        /// In particular, it is only guaranteed to be valid if operation calls only occur within expression statements, and
        /// throws an InvalidOperationException if the outer block contains while-loops.
        /// Any thrown exception is logged using the given onException action and silently ignored if onException is not specified or null.
        /// Returns true if the transformation succeeded without throwing an exception, and false otherwise.
        /// </summary>
        public static bool InlineConjugations(this QsCompilation compilation, out QsCompilation inlined, Action <Exception>?onException = null)
        {
            var inline     = new InlineConjugations(onException);
            var namespaces = compilation.Namespaces.Select(inline.Namespaces.OnNamespace).ToImmutableArray();

            inlined = new QsCompilation(namespaces, compilation.EntryPoints);
            return(inline.SharedState.Success);
        }
Example #2
0
        /// <summary>
        /// Eliminates all conjugations from the given compilation by replacing them with the corresponding implementations (i.e. inlining them).
        /// The generation of the adjoint for the outer block is subject to the same limitation as any adjoint auto-generation.
        /// In particular, it is only guaranteed to be valid if operation calls only occur within expression statements, and
        /// throws an InvalidOperationException if the outer block contains while-loops.
        /// Any thrown exception is logged using the given onException action and silently ignored if onException is not specified or null.
        /// Returns true if the transformation succeeded without throwing an exception, and false otherwise.
        /// Throws an ArgumentNullException (that is not logged or ignored) if the given compilation is null.
        /// </summary>
        public static bool InlineConjugations(this QsCompilation compilation, out QsCompilation inlined, Action <Exception> onException = null)
        {
            if (compilation == null)
            {
                throw new ArgumentNullException(nameof(compilation));
            }
            var inline     = new InlineConjugations(onException);
            var namespaces = compilation.Namespaces.Select(inline.Transform).ToImmutableArray();

            inlined = new QsCompilation(namespaces, compilation.EntryPoints);
            return(inline.Success);
        }