Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to specify aliasing model for Miri #1074

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/base/cargo-miri-playground
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
set -eu

export MIRI_SYSROOT=~/.cache/miri
export MIRIFLAGS="-Zmiri-disable-isolation"
export MIRIFLAGS="${MIRIFLAGS:-} -Zmiri-disable-isolation"
exec cargo miri run
15 changes: 14 additions & 1 deletion compiler/base/orchestrator/src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ pub enum Channel {
Nightly,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum AliasingModel {
Stacked,
Tree,
}

impl Channel {
#[cfg(test)]
pub(crate) const ALL: [Self; 3] = [Self::Stable, Self::Beta, Self::Nightly];
Expand Down Expand Up @@ -656,6 +662,7 @@ pub struct MiriRequest {
pub channel: Channel,
pub crate_type: CrateType,
pub edition: Edition,
pub aliasing_model: AliasingModel,
pub code: String,
}

Expand All @@ -672,7 +679,12 @@ impl MiriRequest {
ExecuteCommandRequest {
cmd: "cargo".to_owned(),
args: vec!["miri-playground".to_owned()],
envs: Default::default(),
envs: match self.aliasing_model {
AliasingModel::Stacked => Default::default(),
AliasingModel::Tree => [("MIRIFLAGS".to_owned(), "-Zmiri-tree-borrows".to_owned())]
.into_iter()
.collect(),
},
cwd: None,
}
}
Expand Down Expand Up @@ -3869,6 +3881,7 @@ mod tests {
channel: Channel::Nightly,
crate_type: CrateType::Binary,
edition: Edition::Rust2021,
aliasing_model: AliasingModel::Stacked,
code: String::new(),
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -euv -o pipefail

Expand Down
2 changes: 1 addition & 1 deletion compiler/fetch.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -euv -o pipefail

Expand Down
15 changes: 14 additions & 1 deletion ui/frontend/AdvancedOptionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import * as config from './reducers/configuration';
import { Either as EitherConfig, Select as SelectConfig } from './ConfigElement';
import MenuGroup from './MenuGroup';
import * as selectors from './selectors';
import { Backtrace, Channel, Edition } from './types';
import { Backtrace, Channel, Edition, AliasingModel } from './types';
import { useAppDispatch, useAppSelector } from './hooks';

const AdvancedOptionsMenu: React.FC = () => {
const isEditionDefault = useAppSelector(selectors.isEditionDefault);
const edition = useAppSelector((state) => state.configuration.edition);
const isBacktraceSet = useAppSelector(selectors.getBacktraceSet);
const backtrace = useAppSelector((state) => state.configuration.backtrace);
const isAliasingModelDefault = useAppSelector(selectors.isAliasingModelDefault);
const aliasingModel = useAppSelector((state) => state.configuration.aliasingModel);

const dispatch = useAppDispatch();

const changeEdition = useCallback((e: Edition) => dispatch(config.changeEdition(e)), [dispatch]);
const changeBacktrace = useCallback((b: Backtrace) => dispatch(config.changeBacktrace(b)), [dispatch]);
const changeAliasingModel = useCallback((b: AliasingModel) => dispatch(config.changeAliasingModel(b)), [dispatch]);

const channel = useAppSelector((state) => state.configuration.channel);
const switchText = (channel !== Channel.Nightly) ? ' (will select nightly Rust)' : '';
Expand All @@ -43,6 +46,16 @@ const AdvancedOptionsMenu: React.FC = () => {
value={backtrace}
isNotDefault={isBacktraceSet}
onChange={changeBacktrace} />

<EitherConfig
id="aliasingModel"
name="Aliasing model"
a={AliasingModel.Stacked}
b={AliasingModel.Tree}
value={aliasingModel}
isNotDefault={!isAliasingModelDefault}
onChange={changeAliasingModel} />

</MenuGroup>
);
};
Expand Down
8 changes: 8 additions & 0 deletions ui/frontend/reducers/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Channel,
DemangleAssembly,
Edition,
AliasingModel,
Editor,
Mode,
Orientation,
Expand Down Expand Up @@ -35,6 +36,7 @@ interface State {
mode: Mode;
edition: Edition;
backtrace: Backtrace;
aliasingModel: AliasingModel;
}

const initialState: State = {
Expand All @@ -56,6 +58,7 @@ const initialState: State = {
mode: Mode.Debug,
edition: Edition.Rust2021,
backtrace: Backtrace.Disabled,
aliasingModel: AliasingModel.Stacked,
};

const slice = createSlice({
Expand All @@ -74,6 +77,10 @@ const slice = createSlice({
state.backtrace = action.payload;
},

changeAliasingModel: (state, action: PayloadAction<AliasingModel>) => {
state.aliasingModel = action.payload;
},

changeChannel: (state, action: PayloadAction<Channel>) => {
state.channel = action.payload;
},
Expand Down Expand Up @@ -124,6 +131,7 @@ export const {
changeAceTheme,
changeAssemblyFlavor,
changeBacktrace,
changeAliasingModel,
changeChannel,
changeDemangleAssembly,
changeEditionRaw,
Expand Down
2 changes: 2 additions & 0 deletions ui/frontend/reducers/output/miri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as z from 'zod';
import { jsonPost, routes } from '../../api';
import { State as RootState } from '../../reducers';
import { miriRequestSelector } from '../../selectors';
import { AliasingModel } from '../../types';

const sliceName = 'output/miri';

Expand All @@ -21,6 +22,7 @@ interface State {
interface MiriRequestBody {
code: string;
edition: string;
aliasingModel: AliasingModel,
}

const MiriResponseBody = z.object({
Expand Down
10 changes: 9 additions & 1 deletion ui/frontend/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Backtrace,
Channel,
Edition,
AliasingModel,
Focus,
Orientation,
PrimaryActionAuto,
Expand Down Expand Up @@ -147,6 +148,7 @@ export const rustfmtVersionDetailsText = createSelector(getRustfmt, versionDetai
export const miriVersionDetailsText = createSelector(getMiri, versionDetails);

const editionSelector = (state: State) => state.configuration.edition;
export const aliasingModelSelector = (state: State) => state.configuration.aliasingModel;

export const isNightlyChannel = createSelector(
channelSelector,
Expand Down Expand Up @@ -175,6 +177,11 @@ export const isEditionDefault = createSelector(
edition => edition == Edition.Rust2021,
);

export const isAliasingModelDefault = createSelector(
aliasingModelSelector,
aliasingModel => aliasingModel == AliasingModel.Stacked,
);

export const getBacktraceSet = (state: State) => (
state.configuration.backtrace !== Backtrace.Disabled
);
Expand Down Expand Up @@ -388,7 +395,8 @@ export const formatRequestSelector = createSelector(
export const miriRequestSelector = createSelector(
editionSelector,
codeSelector,
(edition, code) => ({ edition, code }),
aliasingModelSelector,
(edition, code, aliasingModel) => ({ edition, code, aliasingModel }),
);

export const macroExpansionRequestSelector = createSelector(
Expand Down
5 changes: 5 additions & 0 deletions ui/frontend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ export enum Backtrace {
Enabled = 'enabled',
}

export enum AliasingModel {
Stacked = 'stacked',
Tree = 'tree',
}

export enum Focus {
Clippy = 'clippy',
Miri = 'miri',
Expand Down
2 changes: 2 additions & 0 deletions ui/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ impl HasLabelsCore for coordinator::MiriRequest {
channel,
crate_type,
edition,
// REVIEW: should I add aliasing_model to `LabelsCore`?
aliasing_model: _,
code: _,
} = *self;

Expand Down
2 changes: 2 additions & 0 deletions ui/src/public_http_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ pub(crate) struct MiriRequest {
pub(crate) code: String,
#[serde(default)]
pub(crate) edition: String,
#[serde(default, rename = "aliasingModel")]
pub(crate) aliasing_model: String,
}

#[derive(Debug, Clone, Serialize)]
Expand Down
19 changes: 18 additions & 1 deletion ui/src/server_axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,12 +1479,13 @@ pub(crate) mod api_orchestrator_integration_impls {
type Error = ParseMiriRequestError;

fn try_from(other: api::MiriRequest) -> std::result::Result<Self, Self::Error> {
let api::MiriRequest { code, edition } = other;
let api::MiriRequest { code, edition, aliasing_model } = other;

Ok(MiriRequest {
channel: Channel::Nightly, // TODO: use what user has submitted
crate_type: CrateType::Binary, // TODO: use what user has submitted
edition: parse_edition(&edition)?,
aliasing_model: parse_aliasing_model(&aliasing_model)?,
code,
})
}
Expand All @@ -1494,6 +1495,8 @@ pub(crate) mod api_orchestrator_integration_impls {
pub(crate) enum ParseMiriRequestError {
#[snafu(transparent)]
Edition { source: ParseEditionError },
#[snafu(transparent)]
AliasingMode { source: ParseAliasingModelError },
}

impl From<WithOutput<MiriResponse>> for api::MiriResponse {
Expand Down Expand Up @@ -1709,12 +1712,26 @@ pub(crate) mod api_orchestrator_integration_impls {
})
}

pub(crate) fn parse_aliasing_model(s: &str) -> Result<AliasingModel, ParseAliasingModelError> {
Ok(match s {
"stacked" => AliasingModel::Stacked,
"tree" => AliasingModel::Tree,
value => return ParseAliasingModelSnafu { value }.fail(),
})
}

#[derive(Debug, Snafu)]
#[snafu(display("'{value}' is not a valid edition"))]
pub(crate) struct ParseEditionError {
value: String,
}

#[derive(Debug, Snafu)]
#[snafu(display("'{value}' is not a valid aliasing model"))]
pub(crate) struct ParseAliasingModelError {
value: String,
}

impl From<gist::Gist> for api::MetaGistResponse {
fn from(me: gist::Gist) -> Self {
api::MetaGistResponse {
Expand Down