Skip to content

Commit

Permalink
Remove sandbox types for execution and compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Oct 23, 2023
1 parent bc6ca26 commit 2c54acd
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 364 deletions.
194 changes: 0 additions & 194 deletions ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,6 @@ enum Error {
},

// Remove at a later point. From here ...
#[snafu(display("The value {:?} is not a valid target", value))]
InvalidTarget { value: String },
#[snafu(display("The value {:?} is not a valid assembly flavor", value))]
InvalidAssemblyFlavor { value: String },
#[snafu(display("The value {:?} is not a valid demangle option", value))]
InvalidDemangleAssembly { value: String },
#[snafu(display("The value {:?} is not a valid assembly processing option", value))]
InvalidProcessAssembly { value: String },
#[snafu(display("The value {:?} is not a valid channel", value,))]
InvalidChannel { value: String },
#[snafu(display("The value {:?} is not a valid mode", value))]
InvalidMode { value: String },
#[snafu(display("The value {:?} is not a valid edition", value))]
InvalidEdition { value: String },
#[snafu(display("The value {:?} is not a valid crate type", value))]
Expand Down Expand Up @@ -429,86 +417,6 @@ struct EvaluateResponse {
error: Option<String>,
}

impl TryFrom<CompileRequest> for sandbox::CompileRequest {
type Error = Error;

fn try_from(me: CompileRequest) -> Result<Self> {
let target = parse_target(&me.target)?;
let assembly_flavor = match me.assembly_flavor {
Some(f) => Some(parse_assembly_flavor(&f)?),
None => None,
};

let demangle = match me.demangle_assembly {
Some(f) => Some(parse_demangle_assembly(&f)?),
None => None,
};

let process_assembly = match me.process_assembly {
Some(f) => Some(parse_process_assembly(&f)?),
None => None,
};

let target = match (target, assembly_flavor, demangle, process_assembly) {
(
sandbox::CompileTarget::Assembly(_, _, _),
Some(flavor),
Some(demangle),
Some(process),
) => sandbox::CompileTarget::Assembly(flavor, demangle, process),
_ => target,
};

Ok(sandbox::CompileRequest {
target,
channel: parse_channel(&me.channel)?,
mode: parse_mode(&me.mode)?,
edition: parse_edition(&me.edition)?,
crate_type: parse_crate_type(&me.crate_type)?,
tests: me.tests,
backtrace: me.backtrace,
code: me.code,
})
}
}

impl From<sandbox::CompileResponse> for CompileResponse {
fn from(me: sandbox::CompileResponse) -> Self {
CompileResponse {
success: me.success,
code: me.code,
stdout: me.stdout,
stderr: me.stderr,
}
}
}

impl TryFrom<ExecuteRequest> for sandbox::ExecuteRequest {
type Error = Error;

fn try_from(me: ExecuteRequest) -> Result<Self> {
Ok(sandbox::ExecuteRequest {
channel: parse_channel(&me.channel)?,
mode: parse_mode(&me.mode)?,
edition: parse_edition(&me.edition)?,
crate_type: parse_crate_type(&me.crate_type)?,
tests: me.tests,
backtrace: me.backtrace,
code: me.code,
})
}
}

impl From<sandbox::ExecuteResponse> for ExecuteResponse {
fn from(me: sandbox::ExecuteResponse) -> Self {
ExecuteResponse {
success: me.success,
stdout: me.stdout,
stderr: me.stderr,
}
}
}

impl TryFrom<FormatRequest> for sandbox::FormatRequest {
type Error = Error;

Expand Down Expand Up @@ -630,108 +538,6 @@ impl From<gist::Gist> for MetaGistResponse {
}
}

impl TryFrom<EvaluateRequest> for sandbox::ExecuteRequest {
type Error = Error;

fn try_from(me: EvaluateRequest) -> Result<Self> {
Ok(sandbox::ExecuteRequest {
channel: parse_channel(&me.version)?,
mode: if me.optimize != "0" {
sandbox::Mode::Release
} else {
sandbox::Mode::Debug
},
edition: parse_edition(&me.edition)?,
crate_type: sandbox::CrateType::Binary,
tests: me.tests,
backtrace: false,
code: me.code,
})
}
}

impl From<sandbox::ExecuteResponse> for EvaluateResponse {
fn from(me: sandbox::ExecuteResponse) -> Self {
// The old playground didn't use Cargo, so it never had the
// Cargo output ("Compiling playground...") which is printed
// to stderr. Since this endpoint is used to inline results on
// the page, don't include the stderr unless an error
// occurred.
if me.success {
EvaluateResponse {
result: me.stdout,
error: None,
}
} else {
// When an error occurs, *some* consumers check for an
// `error` key, others assume that the error is crammed in
// the `result` field and then they string search for
// `error:` or `warning:`. Ew. We can put it in both.
let result = me.stderr + &me.stdout;
EvaluateResponse {
result: result.clone(),
error: Some(result),
}
}
}
}

fn parse_target(s: &str) -> Result<sandbox::CompileTarget> {
Ok(match s {
"asm" => sandbox::CompileTarget::Assembly(
sandbox::AssemblyFlavor::Att,
sandbox::DemangleAssembly::Demangle,
sandbox::ProcessAssembly::Filter,
),
"llvm-ir" => sandbox::CompileTarget::LlvmIr,
"mir" => sandbox::CompileTarget::Mir,
"hir" => sandbox::CompileTarget::Hir,
"wasm" => sandbox::CompileTarget::Wasm,
value => InvalidTargetSnafu { value }.fail()?,
})
}

fn parse_assembly_flavor(s: &str) -> Result<sandbox::AssemblyFlavor> {
Ok(match s {
"att" => sandbox::AssemblyFlavor::Att,
"intel" => sandbox::AssemblyFlavor::Intel,
value => InvalidAssemblyFlavorSnafu { value }.fail()?,
})
}

fn parse_demangle_assembly(s: &str) -> Result<sandbox::DemangleAssembly> {
Ok(match s {
"demangle" => sandbox::DemangleAssembly::Demangle,
"mangle" => sandbox::DemangleAssembly::Mangle,
value => InvalidDemangleAssemblySnafu { value }.fail()?,
})
}

fn parse_process_assembly(s: &str) -> Result<sandbox::ProcessAssembly> {
Ok(match s {
"filter" => sandbox::ProcessAssembly::Filter,
"raw" => sandbox::ProcessAssembly::Raw,
value => InvalidProcessAssemblySnafu { value }.fail()?,
})
}

fn parse_channel(s: &str) -> Result<sandbox::Channel> {
Ok(match s {
"stable" => sandbox::Channel::Stable,
"beta" => sandbox::Channel::Beta,
"nightly" => sandbox::Channel::Nightly,
value => InvalidChannelSnafu { value }.fail()?,
})
}

fn parse_mode(s: &str) -> Result<sandbox::Mode> {
Ok(match s {
"debug" => sandbox::Mode::Debug,
"release" => sandbox::Mode::Release,
value => InvalidModeSnafu { value }.fail()?,
})
}

fn parse_edition(s: &str) -> Result<Option<sandbox::Edition>> {
Ok(match s {
"" => None,
Expand Down
67 changes: 0 additions & 67 deletions ui/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,61 +197,6 @@ where
}
}

impl GenerateLabels for sandbox::CompileRequest {
fn generate_labels(&self, outcome: Outcome) -> Labels {
let Self {
target,
channel,
crate_type,
mode,
edition,
tests,
backtrace,
code: _,
} = *self;

Labels {
endpoint: Endpoint::Compile,
outcome,

target: Some(target),
channel: Some(channel),
mode: Some(mode),
edition: Some(edition),
crate_type: Some(crate_type),
tests: Some(tests),
backtrace: Some(backtrace),
}
}
}

impl GenerateLabels for sandbox::ExecuteRequest {
fn generate_labels(&self, outcome: Outcome) -> Labels {
let Self {
channel,
mode,
edition,
crate_type,
tests,
backtrace,
code: _,
} = *self;

Labels {
endpoint: Endpoint::Execute,
outcome,

target: None,
channel: Some(channel),
mode: Some(mode),
edition: Some(edition),
crate_type: Some(crate_type),
tests: Some(tests),
backtrace: Some(backtrace),
}
}
}

impl GenerateLabels for sandbox::FormatRequest {
fn generate_labels(&self, outcome: Outcome) -> Labels {
let Self { edition, code: _ } = *self;
Expand Down Expand Up @@ -368,18 +313,6 @@ fn common_success_details(success: bool, stderr: &str) -> Outcome {
}
}

impl SuccessDetails for sandbox::CompileResponse {
fn success_details(&self) -> Outcome {
common_success_details(self.success, &self.stderr)
}
}

impl SuccessDetails for sandbox::ExecuteResponse {
fn success_details(&self) -> Outcome {
common_success_details(self.success, &self.stderr)
}
}

impl SuccessDetails for sandbox::FormatResponse {
fn success_details(&self) -> Outcome {
common_success_details(self.success, &self.stderr)
Expand Down
Loading

0 comments on commit 2c54acd

Please sign in to comment.