Skip to content

Commit

Permalink
LLVM optimisation and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
SkymanOne committed Oct 27, 2022
1 parent 0f8abd1 commit b5e99fe
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions crates/ink/src/codegen/dispatch/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@ where
);
Ok(())
}
Err(_) => {
Err(error) => {
// Constructor is fallible and failed.
//
// We need to revert the state of the transaction.
ink_env::return_value::<
<private::Seal<R> as ConstructorReturnType<Contract>>::Error,
>(
ReturnFlags::default().set_reverted(true),
result.error_value(),
)
>(ReturnFlags::default().set_reverted(true), error)
}
}
}
Expand Down Expand Up @@ -125,47 +122,25 @@ pub trait ConstructorReturnType<C>: private::Sealed {
///
/// For infallible constructor returns this always yields `Ok`.
fn as_result(&self) -> Result<&C, &Self::Error>;

/// Returns the actual return value of the constructor.
///
/// # Note
///
/// For infallible constructor returns this always yields `()`
/// and is basically ignored since this does not get called
/// if the constructor did not fail.
fn error_value(&self) -> &Self::Error;
}

impl<C> ConstructorReturnType<C> for private::Seal<C> {
type Error = ();

#[inline]
#[inline(always)]
fn as_result(&self) -> Result<&C, &Self::Error> {
Ok(&self.0)
}

#[inline]
fn error_value(&self) -> &Self::Error {
&()
}
}

impl<C, E> ConstructorReturnType<C> for private::Seal<Result<C, E>> {
const IS_RESULT: bool = true;
type Error = E;

#[inline]
#[inline(always)]
fn as_result(&self) -> Result<&C, &Self::Error> {
self.0.as_ref()
}

#[inline]
fn error_value(&self) -> &Self::Error {
self.0
.as_ref()
.err()
.expect("value returned only when error occurs. qed")
}
}

/// Trait used to convert return types of contract initializer routines.
Expand Down

0 comments on commit b5e99fe

Please sign in to comment.