Skip to content

Commit

Permalink
fix: ensure extern signature map is publicly accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
erichulburd committed Oct 4, 2024
1 parent 3a29e62 commit 54756ae
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions quil-rs/src/instruction/extern_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl ExternSignature {
const EXPECTED_PRAGMA_EXTERN_STRUCTURE: &str = "PRAGMA EXTERN {name} \"{scalar type}? (\\(({parameter name} : mut? {parameter type}) (, {parameter name} : mut? {parameter type})*\\))?\"";

/// An error that can occur when parsing an extern signature.
#[derive(Debug, thiserror::Error, PartialEq)]
#[derive(Debug, thiserror::Error, PartialEq, Clone)]
pub enum ExternError {
/// An error occurred while parsing the contents of the extern signature.
#[error(
Expand Down Expand Up @@ -692,7 +692,7 @@ pub enum CallSignatureError {

/// An error that can occur when resolving a call instruction, given a complete
/// [`ExternPragmaMap`] for the [`crate::program::Program`].
#[derive(Debug, thiserror::Error, PartialEq)]
#[derive(Debug, thiserror::Error, PartialEq, Clone)]
pub enum CallResolutionError {
/// A matching extern instruction was found, but signature validation failed.
#[error("call found matching extern instruction for {name}, but signature validation failed: {error:?}")]
Expand Down
2 changes: 1 addition & 1 deletion quil-rs/src/program/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ macro_rules! set_from_memory_references {
};
}

#[derive(thiserror::Error, Debug, PartialEq)]
#[derive(thiserror::Error, Debug, PartialEq, Clone)]
pub enum MemoryAccessesError {
#[error(transparent)]
CallResolution(#[from] CallResolutionError),
Expand Down
20 changes: 16 additions & 4 deletions quil-rs/src/program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ use ndarray::Array2;
use nom_locate::LocatedSpan;

use crate::instruction::{
Arithmetic, ArithmeticOperand, ArithmeticOperator, Call, Declaration, ExternPragmaMap,
FrameDefinition, FrameIdentifier, GateDefinition, GateError, Instruction, InstructionHandler,
Jump, JumpUnless, Label, Matrix, MemoryReference, Move, Qubit, QubitPlaceholder, ScalarType,
Target, TargetPlaceholder, Vector, Waveform, WaveformDefinition, RESERVED_PRAGMA_EXTERN,
Arithmetic, ArithmeticOperand, ArithmeticOperator, Call, Declaration, ExternError,
ExternPragmaMap, ExternSignatureMap, FrameDefinition, FrameIdentifier, GateDefinition,
GateError, Instruction, InstructionHandler, Jump, JumpUnless, Label, Matrix, MemoryReference,
Move, Pragma, Qubit, QubitPlaceholder, ScalarType, Target, TargetPlaceholder, Vector, Waveform,
WaveformDefinition, RESERVED_PRAGMA_EXTERN,
};
use crate::parser::{lex, parse_instructions, ParseError};
use crate::quil::Quil;
Expand Down Expand Up @@ -668,6 +669,17 @@ impl Program {
pub fn get_instruction(&self, index: usize) -> Option<&Instruction> {
self.instructions.get(index)
}

/// Convert the [`Program::extern_pragma_map`] into an [`ExternSignatureMap`].
///
/// This will parse all `PRAGMA EXTERN` instructions in the program. If the
/// conversion of any [`Pragma`] fails, the [`ExternError`] is returned along
/// with the offending [`Pragma`].
pub fn try_extern_signature_map_from_pragma_map(
&self,
) -> std::result::Result<ExternSignatureMap, (Pragma, ExternError)> {
ExternSignatureMap::try_from(self.extern_pragma_map.clone())
}
}

impl Quil for Program {
Expand Down

0 comments on commit 54756ae

Please sign in to comment.