Skip to content

Commit

Permalink
Remove now-obsolete ValdiationContext
Browse files Browse the repository at this point in the history
We've been whittling away at this type for quite some time now, and now
it's no longer necessary!
  • Loading branch information
alexcrichton committed Jan 25, 2019
1 parent 560ff0f commit c284bec
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 236 deletions.
102 changes: 0 additions & 102 deletions src/chunk_list.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![deny(missing_docs)]

mod arena_set;
mod chunk_list;
pub mod const_value;
pub mod dot;
mod emit;
Expand All @@ -14,4 +13,3 @@ pub mod module;
mod parse;
pub mod passes;
pub mod ty;
pub mod validation_context;
18 changes: 0 additions & 18 deletions src/module/functions/local_function/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::module::functions::{FunctionId, LocalFunction};
use crate::module::Module;
use crate::parse::IndicesToIds;
use crate::ty::ValType;
use crate::validation_context::ValidationContext;
use failure::Fail;

#[derive(Debug)]
Expand Down Expand Up @@ -55,9 +54,6 @@ pub struct FunctionContext<'a> {
/// The function being validated/constructed.
pub func: &'a mut LocalFunction,

/// The context under which the function is being validated/constructed.
pub validation: &'a ValidationContext<'a>,

/// The operands stack.
pub operands: &'a mut OperandStack,

Expand All @@ -72,7 +68,6 @@ impl<'a> FunctionContext<'a> {
indices: &'a IndicesToIds,
func_id: FunctionId,
func: &'a mut LocalFunction,
validation: &'a ValidationContext<'a>,
operands: &'a mut OperandStack,
controls: &'a mut ControlStack,
) -> FunctionContext<'a> {
Expand All @@ -81,24 +76,11 @@ impl<'a> FunctionContext<'a> {
indices,
func_id,
func,
validation,
operands,
controls,
}
}

pub fn nested<'b>(&'b mut self, validation: &'b ValidationContext<'b>) -> FunctionContext<'b> {
FunctionContext {
module: self.module,
indices: self.indices,
func_id: self.func_id,
func: self.func,
validation,
operands: self.operands,
controls: self.controls,
}
}

pub fn push_operand<E>(&mut self, op: Option<ValType>, expr: E)
where
E: Copy + Into<ExprId>,
Expand Down
35 changes: 6 additions & 29 deletions src/module/functions/local_function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::module::locals::ModuleLocals;
use crate::module::Module;
use crate::parse::IndicesToIds;
use crate::ty::{TypeId, ValType};
use crate::validation_context::ValidationContext;
use failure::{bail, Fail, ResultExt};
use id_arena::{Arena, Id};
use parity_wasm::elements;
Expand Down Expand Up @@ -53,11 +52,8 @@ impl LocalFunction {
indices: &mut IndicesToIds,
id: FunctionId,
ty: TypeId,
validation: &ValidationContext,
body: wasmparser::FunctionBody,
) -> Result<LocalFunction> {
let validation = validation.for_function(&module.types.get(ty));

// First up, implicitly add locals for all function arguments. We also
// record these in the function itself for later processing.
let mut args = Vec::new();
Expand Down Expand Up @@ -108,7 +104,6 @@ impl LocalFunction {
indices,
id,
&mut func,
&validation,
operands,
controls,
);
Expand Down Expand Up @@ -719,31 +714,24 @@ fn validate_instruction(
}
Operator::Block { ty } => {
let results = ValType::from_block_ty(ty)?;
let validation = ctx.validation.for_block(results.clone());
let mut ctx = ctx.nested(&validation);
ctx.push_control(BlockKind::Block, results.clone(), results);
validate_instruction_sequence_until_end(&mut ctx, ops)?;
validate_end(&mut ctx)?;
validate_instruction_sequence_until_end(ctx, ops)?;
validate_end(ctx)?;
}
Operator::Loop { ty } => {
let validation = ctx.validation.for_loop();
let mut ctx = ctx.nested(&validation);
let t = ValType::from_block_ty(ty)?;
ctx.push_control(BlockKind::Loop, vec![].into_boxed_slice(), t);
validate_instruction_sequence_until_end(&mut ctx, ops)?;
validate_end(&mut ctx)?;
validate_instruction_sequence_until_end(ctx, ops)?;
validate_end(ctx)?;
}
Operator::If { ty } => {
let ty = ValType::from_block_ty(ty)?;
let validation = ctx.validation.for_if_else(ty.clone());
let mut ctx = ctx.nested(&validation);

let (_, condition) = ctx.pop_operand_expected(Some(ValType::I32))?;

let consequent = ctx.push_control(BlockKind::IfElse, ty.clone(), ty.clone());

let mut else_found = false;
validate_instruction_sequence_until(&mut ctx, ops, |i| match i {
validate_instruction_sequence_until(ctx, ops, |i| match i {
Operator::Else => {
else_found = true;
true
Expand All @@ -756,7 +744,7 @@ fn validate_instruction(
let alternative = ctx.push_control(BlockKind::IfElse, results.clone(), results);

if else_found {
validate_instruction_sequence_until_end(&mut ctx, ops)?;
validate_instruction_sequence_until_end(ctx, ops)?;
}
let (results, _block) = ctx.pop_control()?;

Expand All @@ -778,10 +766,6 @@ fn validate_instruction(
.into());
}
Operator::Br { relative_depth } => {
ctx.validation
.label(relative_depth)
.context("`br` to out-of-bounds block")?;

let n = relative_depth as usize;
let expected = ctx.control(n)?.label_types.clone();
let args = ctx.pop_operands(&expected)?.into_boxed_slice();
Expand All @@ -794,10 +778,6 @@ fn validate_instruction(
ctx.unreachable(expr);
}
Operator::BrIf { relative_depth } => {
ctx.validation
.label(relative_depth)
.context("`br_if` to out-of-bounds block")?;

let n = relative_depth as usize;
let (_, condition) = ctx.pop_operand_expected(Some(ValType::I32))?;

Expand All @@ -822,9 +802,6 @@ fn validate_instruction(
Some(n) => n,
None => bail!("malformed `br_table"),
};
ctx.validation
.label(n)
.context("`br_table` with out-of-bounds block")?;
let control = ctx.control(n as usize)?;
match label_types {
None => label_types = Some(&control.label_types),
Expand Down
4 changes: 1 addition & 3 deletions src/module/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::module::imports::ImportId;
use crate::module::Module;
use crate::parse::IndicesToIds;
use crate::ty::TypeId;
use crate::validation_context::ValidationContext;
use failure::bail;
use id_arena::{Arena, Id};
use parity_wasm::elements;
Expand Down Expand Up @@ -212,7 +211,6 @@ impl Module {
bail!("code and function sections must have same number of entries")
}
let num_imports = self.funcs.arena.len() - (amt as usize);
let validation = ValidationContext::new();

for (i, body) in section.into_iter().enumerate() {
let body = body?;
Expand All @@ -223,7 +221,7 @@ impl Module {
_ => unreachable!(),
};

let local = LocalFunction::parse(self, indices, id, ty, &validation, body)?;
let local = LocalFunction::parse(self, indices, id, ty, body)?;
self.funcs.arena[id] = Function {
id,
kind: FunctionKind::Local(local),
Expand Down
82 changes: 0 additions & 82 deletions src/validation_context.rs

This file was deleted.

0 comments on commit c284bec

Please sign in to comment.