Add clippy suggestions (#6203)
* add clippy suggestions * revert &/ref change * Update cranelift/isle/isle/src/parser.rs Co-authored-by: Jamey Sharp <jamey@minilop.net> --------- Co-authored-by: Jamey Sharp <jamey@minilop.net>
This commit is contained in:
@@ -228,8 +228,8 @@ impl InstructionBuilder {
|
||||
}
|
||||
|
||||
fn build(self) -> Instruction {
|
||||
let operands_in = self.operands_in.unwrap_or_else(Vec::new);
|
||||
let operands_out = self.operands_out.unwrap_or_else(Vec::new);
|
||||
let operands_in = self.operands_in.unwrap_or_default();
|
||||
let operands_out = self.operands_out.unwrap_or_default();
|
||||
|
||||
let mut value_opnums = Vec::new();
|
||||
let mut imm_opnums = Vec::new();
|
||||
@@ -375,7 +375,7 @@ fn verify_polymorphic(
|
||||
if (free_typevar.is_some() && tv == &free_typevar.unwrap())
|
||||
|| tv.singleton_type().is_some()
|
||||
{
|
||||
match is_ctrl_typevar_candidate(tv, &operands_in, &operands_out) {
|
||||
match is_ctrl_typevar_candidate(tv, operands_in, operands_out) {
|
||||
Ok(_other_typevars) => {
|
||||
return Some(PolymorphicInfo {
|
||||
use_typevar_operand: true,
|
||||
@@ -410,7 +410,7 @@ fn verify_polymorphic(
|
||||
|
||||
// At this point, if the next unwrap() fails, it means the output type couldn't be used as a
|
||||
// controlling type variable either; panicking is the right behavior.
|
||||
is_ctrl_typevar_candidate(tv, &operands_in, &operands_out).unwrap();
|
||||
is_ctrl_typevar_candidate(tv, operands_in, operands_out).unwrap();
|
||||
|
||||
Some(PolymorphicInfo {
|
||||
use_typevar_operand: false,
|
||||
|
||||
@@ -50,10 +50,7 @@ impl Operand {
|
||||
}
|
||||
|
||||
pub fn is_value(&self) -> bool {
|
||||
match self.kind.fields {
|
||||
OperandKindFields::TypeVar(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind.fields, OperandKindFields::TypeVar(_))
|
||||
}
|
||||
|
||||
pub fn type_var(&self) -> Option<&TypeVar> {
|
||||
@@ -64,28 +61,25 @@ impl Operand {
|
||||
}
|
||||
|
||||
pub fn is_varargs(&self) -> bool {
|
||||
match self.kind.fields {
|
||||
OperandKindFields::VariableArgs => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind.fields, OperandKindFields::VariableArgs)
|
||||
}
|
||||
|
||||
/// Returns true if the operand has an immediate kind or is an EntityRef.
|
||||
pub fn is_immediate_or_entityref(&self) -> bool {
|
||||
match self.kind.fields {
|
||||
matches!(
|
||||
self.kind.fields,
|
||||
OperandKindFields::ImmEnum(_)
|
||||
| OperandKindFields::ImmValue
|
||||
| OperandKindFields::EntityRef => true,
|
||||
_ => false,
|
||||
}
|
||||
| OperandKindFields::ImmValue
|
||||
| OperandKindFields::EntityRef
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns true if the operand has an immediate kind.
|
||||
pub fn is_immediate(&self) -> bool {
|
||||
match self.kind.fields {
|
||||
OperandKindFields::ImmEnum(_) | OperandKindFields::ImmValue => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(
|
||||
self.kind.fields,
|
||||
OperandKindFields::ImmEnum(_) | OperandKindFields::ImmValue
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,18 +152,18 @@ impl OperandKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<OperandKind> for &TypeVar {
|
||||
fn into(self) -> OperandKind {
|
||||
impl From<&TypeVar> for OperandKind {
|
||||
fn from(type_var: &TypeVar) -> Self {
|
||||
OperandKind {
|
||||
rust_field_name: "value",
|
||||
rust_type: "ir::Value",
|
||||
fields: OperandKindFields::TypeVar(self.into()),
|
||||
fields: OperandKindFields::TypeVar(type_var.into()),
|
||||
doc: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Into<OperandKind> for &OperandKind {
|
||||
fn into(self) -> OperandKind {
|
||||
self.clone()
|
||||
impl From<&OperandKind> for OperandKind {
|
||||
fn from(kind: &OperandKind) -> Self {
|
||||
kind.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,14 +75,14 @@ pub(crate) enum PresetType {
|
||||
OtherPreset(PresetIndex),
|
||||
}
|
||||
|
||||
impl Into<PresetType> for BoolSettingIndex {
|
||||
fn into(self) -> PresetType {
|
||||
PresetType::BoolSetting(self)
|
||||
impl From<BoolSettingIndex> for PresetType {
|
||||
fn from(bool_setting_index: BoolSettingIndex) -> Self {
|
||||
PresetType::BoolSetting(bool_setting_index)
|
||||
}
|
||||
}
|
||||
impl Into<PresetType> for PresetIndex {
|
||||
fn into(self) -> PresetType {
|
||||
PresetType::OtherPreset(self)
|
||||
impl From<PresetIndex> for PresetType {
|
||||
fn from(value: PresetIndex) -> Self {
|
||||
PresetType::OtherPreset(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,13 +134,7 @@ impl SettingGroup {
|
||||
fn num_bool_settings(&self) -> u8 {
|
||||
self.settings
|
||||
.iter()
|
||||
.filter(|s| {
|
||||
if let SpecificSetting::Bool(_) = s.specific {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.filter(|s| matches!(s.specific, SpecificSetting::Bool(_)))
|
||||
.count() as u8
|
||||
}
|
||||
|
||||
@@ -184,14 +178,15 @@ pub(crate) enum PredicateNode {
|
||||
And(Box<PredicateNode>, Box<PredicateNode>),
|
||||
}
|
||||
|
||||
impl Into<PredicateNode> for BoolSettingIndex {
|
||||
fn into(self) -> PredicateNode {
|
||||
PredicateNode::OwnedBool(self)
|
||||
impl From<BoolSettingIndex> for PredicateNode {
|
||||
fn from(bool_setting_index: BoolSettingIndex) -> Self {
|
||||
PredicateNode::OwnedBool(bool_setting_index)
|
||||
}
|
||||
}
|
||||
impl<'a> Into<PredicateNode> for (BoolSettingIndex, &'a SettingGroup) {
|
||||
fn into(self) -> PredicateNode {
|
||||
let (index, group) = (self.0, self.1);
|
||||
|
||||
impl<'a> From<(BoolSettingIndex, &'a SettingGroup)> for PredicateNode {
|
||||
fn from(val: (BoolSettingIndex, &'a SettingGroup)) -> Self {
|
||||
let (index, group) = (val.0, val.1);
|
||||
let setting = &group.settings[index.0];
|
||||
PredicateNode::SharedBool(group.name, setting.name)
|
||||
}
|
||||
|
||||
@@ -491,10 +491,6 @@ impl ReferenceTypeIterator {
|
||||
impl Iterator for ReferenceTypeIterator {
|
||||
type Item = ReferenceType;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if let Some(r) = self.reference_iter.next() {
|
||||
Some(ReferenceType::from(r))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.reference_iter.next().map(ReferenceType::from)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,14 +279,14 @@ impl TypeVar {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<TypeVar> for &TypeVar {
|
||||
fn into(self) -> TypeVar {
|
||||
self.clone()
|
||||
impl From<&TypeVar> for TypeVar {
|
||||
fn from(type_var: &TypeVar) -> Self {
|
||||
type_var.clone()
|
||||
}
|
||||
}
|
||||
impl Into<TypeVar> for ValueType {
|
||||
fn into(self) -> TypeVar {
|
||||
TypeVar::new_singleton(self)
|
||||
impl From<ValueType> for TypeVar {
|
||||
fn from(value_type: ValueType) -> Self {
|
||||
TypeVar::new_singleton(value_type)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,7 +507,7 @@ impl TypeSet {
|
||||
self.dynamic_lanes
|
||||
.iter()
|
||||
.filter(|&&x| x < MAX_LANES)
|
||||
.map(|&x| x),
|
||||
.copied(),
|
||||
);
|
||||
copy.dynamic_lanes = NumSet::new();
|
||||
copy
|
||||
@@ -660,13 +660,7 @@ pub(crate) enum Interval {
|
||||
impl Interval {
|
||||
fn to_range(&self, full_range: Range, default: Option<RangeBound>) -> Option<Range> {
|
||||
match self {
|
||||
Interval::None => {
|
||||
if let Some(default_val) = default {
|
||||
Some(default_val..default_val)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Interval::None => default.map(|default_val| default_val..default_val),
|
||||
|
||||
Interval::All => Some(full_range),
|
||||
|
||||
@@ -683,9 +677,9 @@ impl Interval {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Interval> for Range {
|
||||
fn into(self) -> Interval {
|
||||
Interval::Range(self)
|
||||
impl From<Range> for Interval {
|
||||
fn from(range: Range) -> Self {
|
||||
Interval::Range(range)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ pub fn generate_table<'cont, T, I: iter::Iterator<Item = &'cont T>, H: Fn(&T) ->
|
||||
let mut table = vec![None; size];
|
||||
|
||||
for i in items {
|
||||
let mut h = hash_function(&i) % size;
|
||||
let mut h = hash_function(i) % size;
|
||||
let mut s = 0;
|
||||
while table[h].is_some() {
|
||||
s += 1;
|
||||
|
||||
@@ -700,7 +700,7 @@ fn get_constraint<'entries, 'table>(
|
||||
if let Some(free_typevar) = type_var.free_typevar() {
|
||||
if ctrl_typevar.is_some() && free_typevar != *ctrl_typevar.unwrap() {
|
||||
assert!(type_var.base.is_none());
|
||||
return format!("Free({})", type_sets.add(&type_var.get_raw_typeset()));
|
||||
return format!("Free({})", type_sets.add(type_var.get_raw_typeset()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -809,7 +809,7 @@ fn gen_type_constraints(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
||||
fmt.indent(|fmt| {
|
||||
for inst in all_inst.iter() {
|
||||
let (ctrl_typevar, ctrl_typeset) = if let Some(poly) = &inst.polymorphic_info {
|
||||
let index = type_sets.add(&*poly.ctrl_typevar.get_raw_typeset());
|
||||
let index = type_sets.add(poly.ctrl_typevar.get_raw_typeset());
|
||||
(Some(&poly.ctrl_typevar), index)
|
||||
} else {
|
||||
(None, TYPESET_LIMIT)
|
||||
@@ -857,7 +857,7 @@ fn gen_type_constraints(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")));
|
||||
if let Some(poly) = &inst.polymorphic_info {
|
||||
fmt.comment(format!("Polymorphic over {}", typeset_to_string(&poly.ctrl_typevar.get_raw_typeset())));
|
||||
fmt.comment(format!("Polymorphic over {}", typeset_to_string(poly.ctrl_typevar.get_raw_typeset())));
|
||||
}
|
||||
|
||||
// Compute the bit field encoding, c.f. instructions.rs.
|
||||
@@ -1730,7 +1730,7 @@ fn gen_builder(
|
||||
fmt.line("pub trait InstBuilder<'f>: InstBuilderBase<'f> {");
|
||||
fmt.indent(|fmt| {
|
||||
for inst in instructions.iter() {
|
||||
gen_inst_builder(inst, &*inst.format, fmt);
|
||||
gen_inst_builder(inst, &inst.format, fmt);
|
||||
fmt.empty_line();
|
||||
}
|
||||
for (i, format) in formats.iter().enumerate() {
|
||||
|
||||
@@ -267,10 +267,10 @@ fn gen_getters(group: &SettingGroup, fmt: &mut Formatter) {
|
||||
}
|
||||
|
||||
for setting in &group.settings {
|
||||
gen_getter(&setting, fmt);
|
||||
gen_getter(setting, fmt);
|
||||
}
|
||||
for predicate in &group.predicates {
|
||||
gen_pred_getter(&predicate, &group, fmt);
|
||||
gen_pred_getter(predicate, group, fmt);
|
||||
}
|
||||
});
|
||||
fmtln!(fmt, "}");
|
||||
@@ -364,8 +364,8 @@ fn gen_descriptors(group: &SettingGroup, fmt: &mut Formatter) {
|
||||
|
||||
// Generate hash table.
|
||||
let mut hash_entries: Vec<SettingOrPreset> = Vec::new();
|
||||
hash_entries.extend(group.settings.iter().map(|x| SettingOrPreset::Setting(x)));
|
||||
hash_entries.extend(group.presets.iter().map(|x| SettingOrPreset::Preset(x)));
|
||||
hash_entries.extend(group.settings.iter().map(SettingOrPreset::Setting));
|
||||
hash_entries.extend(group.presets.iter().map(SettingOrPreset::Preset));
|
||||
|
||||
let hash_table = generate_table(hash_entries.iter(), hash_entries.len(), |entry| {
|
||||
simple_hash(entry.name())
|
||||
@@ -399,9 +399,9 @@ fn gen_descriptors(group: &SettingGroup, fmt: &mut Formatter) {
|
||||
fmt.comment(format!(
|
||||
"{}: {}",
|
||||
preset.name,
|
||||
preset.setting_names(&group).collect::<Vec<_>>().join(", ")
|
||||
preset.setting_names(group).collect::<Vec<_>>().join(", ")
|
||||
));
|
||||
for (mask, value) in preset.layout(&group) {
|
||||
for (mask, value) in preset.layout(group) {
|
||||
fmtln!(fmt, "(0b{:08b}, 0b{:08b}),", mask, value);
|
||||
}
|
||||
}
|
||||
@@ -502,7 +502,7 @@ pub(crate) fn generate(
|
||||
out_dir: &str,
|
||||
) -> Result<(), error::Error> {
|
||||
let mut fmt = Formatter::new();
|
||||
gen_group(&settings, parent_group, &mut fmt);
|
||||
gen_group(settings, parent_group, &mut fmt);
|
||||
fmt.update_file(filename, out_dir)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ pub fn generate(isas: &[isa::Isa], out_dir: &str, isle_dir: &str) -> Result<(),
|
||||
&shared_defs.settings,
|
||||
gen_settings::ParentGroup::None,
|
||||
"settings.rs",
|
||||
&out_dir,
|
||||
out_dir,
|
||||
)?;
|
||||
gen_types::generate("types.rs", &out_dir)?;
|
||||
gen_types::generate("types.rs", out_dir)?;
|
||||
|
||||
// - per ISA definitions.
|
||||
let target_isas = isa::define(isas, &mut shared_defs);
|
||||
@@ -49,7 +49,7 @@ pub fn generate(isas: &[isa::Isa], out_dir: &str, isle_dir: &str) -> Result<(),
|
||||
"inst_builder.rs",
|
||||
"clif_opt.isle",
|
||||
"clif_lower.isle",
|
||||
&out_dir,
|
||||
out_dir,
|
||||
isle_dir,
|
||||
)?;
|
||||
|
||||
@@ -58,7 +58,7 @@ pub fn generate(isas: &[isa::Isa], out_dir: &str, isle_dir: &str) -> Result<(),
|
||||
&isa.settings,
|
||||
gen_settings::ParentGroup::Shared,
|
||||
&format!("settings-{}.rs", isa.name),
|
||||
&out_dir,
|
||||
out_dir,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ impl Definitions {
|
||||
// Check name.
|
||||
if let Some(existing_format) = format_names.get(&inst.format.name) {
|
||||
assert!(
|
||||
Rc::ptr_eq(&existing_format, &inst.format),
|
||||
Rc::ptr_eq(existing_format, &inst.format),
|
||||
"formats must uniquely named; there's a\
|
||||
conflict on the name '{}', please make sure it is used only once.",
|
||||
existing_format.name
|
||||
@@ -80,7 +80,7 @@ impl Definitions {
|
||||
}
|
||||
}
|
||||
|
||||
let mut result = Vec::from_iter(format_structures.into_iter().map(|(_, v)| v));
|
||||
let mut result = Vec::from_iter(format_structures.into_values());
|
||||
result.sort_by_key(|format| format.name);
|
||||
result
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ fn _indent(s: &str) -> Option<usize> {
|
||||
fn parse_multiline(s: &str) -> Vec<String> {
|
||||
// Convert tabs into spaces.
|
||||
let expanded_tab = format!("{:-1$}", " ", SHIFTWIDTH);
|
||||
let lines: Vec<String> = s.lines().map(|l| l.replace("\t", &expanded_tab)).collect();
|
||||
let lines: Vec<String> = s.lines().map(|l| l.replace('\t', &expanded_tab)).collect();
|
||||
|
||||
// Determine minimum indentation, ignoring the first line and empty lines.
|
||||
let indent = lines
|
||||
|
||||
@@ -13,7 +13,7 @@ pub struct ControlPlane {
|
||||
/// disabled. It doesn't consume any bytes and always returns a default
|
||||
/// control plane.
|
||||
impl arbitrary::Arbitrary<'_> for ControlPlane {
|
||||
fn arbitrary<'a>(_u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
fn arbitrary(_u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
|
||||
Ok(Self::default())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ impl<'a> Codegen<'a> {
|
||||
}
|
||||
|
||||
fn generate_ctx_trait(&self, code: &mut String) {
|
||||
writeln!(code, "").unwrap();
|
||||
writeln!(code).unwrap();
|
||||
writeln!(
|
||||
code,
|
||||
"/// Context during lowering: an implementation of this trait"
|
||||
@@ -287,7 +287,7 @@ impl<'a> Codegen<'a> {
|
||||
for field in &variant.fields {
|
||||
let name = &self.typeenv.syms[field.name.index()];
|
||||
let ty_name =
|
||||
self.typeenv.types[field.ty.index()].name(&self.typeenv);
|
||||
self.typeenv.types[field.ty.index()].name(self.typeenv);
|
||||
writeln!(code, " {}: {},", name, ty_name).unwrap();
|
||||
}
|
||||
writeln!(code, " }},").unwrap();
|
||||
@@ -301,9 +301,9 @@ impl<'a> Codegen<'a> {
|
||||
}
|
||||
|
||||
fn type_name(&self, typeid: TypeId, by_ref: bool) -> String {
|
||||
match &self.typeenv.types[typeid.index()] {
|
||||
&Type::Primitive(_, sym, _) => self.typeenv.syms[sym.index()].clone(),
|
||||
&Type::Enum { name, .. } => {
|
||||
match self.typeenv.types[typeid.index()] {
|
||||
Type::Primitive(_, sym, _) => self.typeenv.syms[sym.index()].clone(),
|
||||
Type::Enum { name, .. } => {
|
||||
let r = if by_ref { "&" } else { "" };
|
||||
format!("{}{}", r, self.typeenv.syms[name.index()])
|
||||
}
|
||||
@@ -620,7 +620,7 @@ impl<'a> Codegen<'a> {
|
||||
&self.typeenv.syms[field.name.index()],
|
||||
)?;
|
||||
self.emit_expr(ctx, *value)?;
|
||||
if ctx.is_ref.contains(&value) {
|
||||
if ctx.is_ref.contains(value) {
|
||||
write!(ctx.out, ".clone()")?;
|
||||
}
|
||||
writeln!(ctx.out, ",")?;
|
||||
|
||||
@@ -19,13 +19,13 @@ impl std::fmt::Debug for Errors {
|
||||
}
|
||||
let diagnostics = Vec::from_iter(self.errors.iter().map(|e| {
|
||||
let message = match e {
|
||||
Error::IoError { context, .. } => format!("{}", context),
|
||||
Error::IoError { context, .. } => context.clone(),
|
||||
Error::ParseError { msg, .. } => format!("parse error: {}", msg),
|
||||
Error::TypeError { msg, .. } => format!("type error: {}", msg),
|
||||
Error::UnreachableError { msg, .. } => format!("unreachable rule: {}", msg),
|
||||
Error::OverlapError { msg, .. } => format!("overlap error: {}", msg),
|
||||
Error::ShadowedError { .. } => {
|
||||
format!("more general higher-priority rule shadows other rules")
|
||||
"more general higher-priority rule shadows other rules".to_string()
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ impl<'a> Lexer<'a> {
|
||||
let mut buf = String::new();
|
||||
for text in &file_texts {
|
||||
file_starts.push(buf.len());
|
||||
buf += &text;
|
||||
buf += text;
|
||||
buf += "\n";
|
||||
}
|
||||
|
||||
@@ -316,18 +316,12 @@ impl<'a> Lexer<'a> {
|
||||
impl Token {
|
||||
/// Is this an `Int` token?
|
||||
pub fn is_int(&self) -> bool {
|
||||
match self {
|
||||
Token::Int(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Token::Int(_))
|
||||
}
|
||||
|
||||
/// Is this a `Sym` token?
|
||||
pub fn is_sym(&self) -> bool {
|
||||
match self {
|
||||
Token::Symbol(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Token::Symbol(_))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
fn is<F: Fn(&Token) -> bool>(&self, f: F) -> bool {
|
||||
if let Some(&(_, ref peek)) = self.lexer.peek() {
|
||||
if let Some((_, peek)) = self.lexer.peek() {
|
||||
f(peek)
|
||||
} else {
|
||||
false
|
||||
@@ -99,7 +99,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
fn is_const(&self) -> bool {
|
||||
self.is(|tok| match tok {
|
||||
&Token::Symbol(ref tok_s) if tok_s.starts_with("$") => true,
|
||||
Token::Symbol(tok_s) if tok_s.starts_with('$') => true,
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
@@ -123,7 +123,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
fn eat_sym_str(&mut self, s: &str) -> Result<bool> {
|
||||
self.eat(|tok| match tok {
|
||||
&Token::Symbol(ref tok_s) if tok_s == s => true,
|
||||
Token::Symbol(ref tok_s) if tok_s == s => true,
|
||||
_ => false,
|
||||
})
|
||||
.map(|token| token.is_some())
|
||||
@@ -202,8 +202,7 @@ impl<'a> Parser<'a> {
|
||||
fn parse_const(&mut self) -> Result<Ident> {
|
||||
let pos = self.pos();
|
||||
let ident = self.parse_ident()?;
|
||||
if ident.0.starts_with("$") {
|
||||
let s = &ident.0[1..];
|
||||
if let Some(s) = ident.0.strip_prefix('$') {
|
||||
Ok(Ident(s.to_string(), ident.1))
|
||||
} else {
|
||||
Err(self.error(
|
||||
@@ -216,9 +215,8 @@ impl<'a> Parser<'a> {
|
||||
fn parse_pragma(&mut self) -> Result<Pragma> {
|
||||
let ident = self.parse_ident()?;
|
||||
// currently, no pragmas are defined, but the infrastructure is useful to keep around
|
||||
match ident.0.as_str() {
|
||||
pragma => Err(self.error(ident.1, format!("Unknown pragma '{}'", pragma))),
|
||||
}
|
||||
let pragma = ident.0.as_str();
|
||||
Err(self.error(ident.1, format!("Unknown pragma '{}'", pragma)))
|
||||
}
|
||||
|
||||
fn parse_type(&mut self) -> Result<Type> {
|
||||
@@ -472,7 +470,7 @@ impl<'a> Parser<'a> {
|
||||
self.expect_rparen()?;
|
||||
Ok(ret)
|
||||
} else {
|
||||
self.parse_expr().map(|expr| IfLetOrExpr::Expr(expr))
|
||||
self.parse_expr().map(IfLetOrExpr::Expr)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -595,14 +595,14 @@ pub trait PatternVisitor {
|
||||
impl Pattern {
|
||||
/// Get this pattern's type.
|
||||
pub fn ty(&self) -> TypeId {
|
||||
match self {
|
||||
&Self::BindPattern(t, ..) => t,
|
||||
&Self::Var(t, ..) => t,
|
||||
&Self::ConstInt(t, ..) => t,
|
||||
&Self::ConstPrim(t, ..) => t,
|
||||
&Self::Term(t, ..) => t,
|
||||
&Self::Wildcard(t, ..) => t,
|
||||
&Self::And(t, ..) => t,
|
||||
match *self {
|
||||
Self::BindPattern(t, ..) => t,
|
||||
Self::Var(t, ..) => t,
|
||||
Self::ConstInt(t, ..) => t,
|
||||
Self::ConstPrim(t, ..) => t,
|
||||
Self::Term(t, ..) => t,
|
||||
Self::Wildcard(t, ..) => t,
|
||||
Self::And(t, ..) => t,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,14 +614,14 @@ impl Pattern {
|
||||
termenv: &TermEnv,
|
||||
vars: &mut HashMap<VarId, V::PatternId>,
|
||||
) {
|
||||
match self {
|
||||
&Pattern::BindPattern(_ty, var, ref subpat) => {
|
||||
match *self {
|
||||
Pattern::BindPattern(_ty, var, ref subpat) => {
|
||||
// Bind the appropriate variable and recurse.
|
||||
assert!(!vars.contains_key(&var));
|
||||
vars.insert(var, input);
|
||||
subpat.visit(visitor, input, termenv, vars);
|
||||
}
|
||||
&Pattern::Var(ty, var) => {
|
||||
Pattern::Var(ty, var) => {
|
||||
// Assert that the value matches the existing bound var.
|
||||
let var_val = vars
|
||||
.get(&var)
|
||||
@@ -629,9 +629,9 @@ impl Pattern {
|
||||
.expect("Variable should already be bound");
|
||||
visitor.add_match_equal(input, var_val, ty);
|
||||
}
|
||||
&Pattern::ConstInt(ty, value) => visitor.add_match_int(input, ty, value),
|
||||
&Pattern::ConstPrim(ty, value) => visitor.add_match_prim(input, ty, value),
|
||||
&Pattern::Term(ty, term, ref args) => {
|
||||
Pattern::ConstInt(ty, value) => visitor.add_match_int(input, ty, value),
|
||||
Pattern::ConstPrim(ty, value) => visitor.add_match_prim(input, ty, value),
|
||||
Pattern::Term(ty, term, ref args) => {
|
||||
// Determine whether the term has an external extractor or not.
|
||||
let termdata = &termenv.terms[term.index()];
|
||||
let arg_values = match &termdata.kind {
|
||||
@@ -673,12 +673,12 @@ impl Pattern {
|
||||
pat.visit(visitor, val, termenv, vars);
|
||||
}
|
||||
}
|
||||
&Pattern::And(_ty, ref children) => {
|
||||
Pattern::And(_ty, ref children) => {
|
||||
for child in children {
|
||||
child.visit(visitor, input, termenv, vars);
|
||||
}
|
||||
}
|
||||
&Pattern::Wildcard(_ty) => {
|
||||
Pattern::Wildcard(_ty) => {
|
||||
// Nothing!
|
||||
}
|
||||
}
|
||||
@@ -719,12 +719,12 @@ pub trait ExprVisitor {
|
||||
impl Expr {
|
||||
/// Get this expression's type.
|
||||
pub fn ty(&self) -> TypeId {
|
||||
match self {
|
||||
&Self::Term(t, ..) => t,
|
||||
&Self::Var(t, ..) => t,
|
||||
&Self::ConstInt(t, ..) => t,
|
||||
&Self::ConstPrim(t, ..) => t,
|
||||
&Self::Let { ty: t, .. } => t,
|
||||
match *self {
|
||||
Self::Term(t, ..) => t,
|
||||
Self::Var(t, ..) => t,
|
||||
Self::ConstInt(t, ..) => t,
|
||||
Self::ConstPrim(t, ..) => t,
|
||||
Self::Let { ty: t, .. } => t,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,10 +736,10 @@ impl Expr {
|
||||
vars: &HashMap<VarId, V::ExprId>,
|
||||
) -> V::ExprId {
|
||||
log!("Expr::visit: expr {:?}", self);
|
||||
match self {
|
||||
&Expr::ConstInt(ty, val) => visitor.add_const_int(ty, val),
|
||||
&Expr::ConstPrim(ty, val) => visitor.add_const_prim(ty, val),
|
||||
&Expr::Let {
|
||||
match *self {
|
||||
Expr::ConstInt(ty, val) => visitor.add_const_int(ty, val),
|
||||
Expr::ConstPrim(ty, val) => visitor.add_const_prim(ty, val),
|
||||
Expr::Let {
|
||||
ty: _ty,
|
||||
ref bindings,
|
||||
ref body,
|
||||
@@ -751,8 +751,8 @@ impl Expr {
|
||||
}
|
||||
body.visit(visitor, termenv, &vars)
|
||||
}
|
||||
&Expr::Var(_ty, var_id) => *vars.get(&var_id).unwrap(),
|
||||
&Expr::Term(ty, term, ref arg_exprs) => {
|
||||
Expr::Var(_ty, var_id) => *vars.get(&var_id).unwrap(),
|
||||
Expr::Term(ty, term, ref arg_exprs) => {
|
||||
let termdata = &termenv.terms[term.index()];
|
||||
let arg_values_tys = arg_exprs
|
||||
.iter()
|
||||
@@ -957,23 +957,21 @@ impl TypeEnv {
|
||||
|
||||
// Now collect types for extern constants.
|
||||
for def in &defs.defs {
|
||||
match def {
|
||||
&ast::Def::Extern(ast::Extern::Const {
|
||||
ref name,
|
||||
ref ty,
|
||||
pos,
|
||||
}) => {
|
||||
let ty = match tyenv.get_type_by_name(ty) {
|
||||
Some(ty) => ty,
|
||||
None => {
|
||||
tyenv.report_error(pos, "Unknown type for constant");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let name = tyenv.intern_mut(name);
|
||||
tyenv.const_types.insert(name, ty);
|
||||
}
|
||||
_ => {}
|
||||
if let &ast::Def::Extern(ast::Extern::Const {
|
||||
ref name,
|
||||
ref ty,
|
||||
pos,
|
||||
}) = def
|
||||
{
|
||||
let ty = match tyenv.get_type_by_name(ty) {
|
||||
Some(ty) => ty,
|
||||
None => {
|
||||
tyenv.report_error(pos, "Unknown type for constant");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let name = tyenv.intern_mut(name);
|
||||
tyenv.const_types.insert(name, ty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1221,7 +1219,6 @@ impl TermEnv {
|
||||
.map(|id| {
|
||||
tyenv.get_type_by_name(id).ok_or_else(|| {
|
||||
tyenv.report_error(id.1, format!("Unknown arg type: '{}'", id.0));
|
||||
()
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>();
|
||||
|
||||
2
crates/cache/build.rs
vendored
2
crates/cache/build.rs
vendored
@@ -2,7 +2,7 @@ use std::process::Command;
|
||||
use std::str;
|
||||
|
||||
fn main() {
|
||||
let git_rev = match Command::new("git").args(&["rev-parse", "HEAD"]).output() {
|
||||
let git_rev = match Command::new("git").args(["rev-parse", "HEAD"]).output() {
|
||||
Ok(output) => str::from_utf8(&output.stdout).unwrap().trim().to_string(),
|
||||
Err(_) => env!("CARGO_PKG_VERSION").to_string(),
|
||||
};
|
||||
|
||||
@@ -117,7 +117,7 @@ fn parse_source(source: &Option<Source>) -> anyhow::Result<(Resolve, PackageId,
|
||||
let root = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||
let mut parse = |path: &Path| -> anyhow::Result<_> {
|
||||
if path.is_dir() {
|
||||
let (pkg, sources) = resolve.push_dir(&path)?;
|
||||
let (pkg, sources) = resolve.push_dir(path)?;
|
||||
files = sources;
|
||||
Ok(pkg)
|
||||
} else {
|
||||
@@ -128,10 +128,10 @@ fn parse_source(source: &Option<Source>) -> anyhow::Result<(Resolve, PackageId,
|
||||
};
|
||||
let pkg = match source {
|
||||
Some(Source::Inline(s)) => resolve.push(
|
||||
UnresolvedPackage::parse("macro-input".as_ref(), &s)?,
|
||||
UnresolvedPackage::parse("macro-input".as_ref(), s)?,
|
||||
&Default::default(),
|
||||
)?,
|
||||
Some(Source::Path(s)) => parse(&root.join(&s))?,
|
||||
Some(Source::Path(s)) => parse(&root.join(s))?,
|
||||
None => parse(&root.join("wit"))?,
|
||||
};
|
||||
|
||||
|
||||
@@ -151,9 +151,9 @@ impl Wasmtime {
|
||||
let mut gen = InterfaceGenerator::new(self, resolve);
|
||||
let import = match item {
|
||||
WorldItem::Function(func) => {
|
||||
gen.generate_function_trait_sig(TypeOwner::None, &func);
|
||||
gen.generate_function_trait_sig(TypeOwner::None, func);
|
||||
let sig = mem::take(&mut gen.src).into();
|
||||
gen.generate_add_function_to_linker(TypeOwner::None, &func, "linker");
|
||||
gen.generate_add_function_to_linker(TypeOwner::None, func, "linker");
|
||||
let add_to_linker = gen.src.into();
|
||||
Import::Function { sig, add_to_linker }
|
||||
}
|
||||
@@ -203,7 +203,7 @@ impl Wasmtime {
|
||||
let (_name, getter) = gen.extract_typed_function(func);
|
||||
assert!(gen.src.is_empty());
|
||||
self.exports.funcs.push(body);
|
||||
(format!("wasmtime::component::Func"), getter)
|
||||
("wasmtime::component::Func".to_string(), getter)
|
||||
}
|
||||
WorldItem::Type(_) => unreachable!(),
|
||||
WorldItem::Interface(id) => {
|
||||
@@ -1051,9 +1051,9 @@ impl<'a> InterfaceGenerator<'a> {
|
||||
uwriteln!(self.src, "}}");
|
||||
|
||||
let where_clause = if self.gen.opts.async_ {
|
||||
format!("T: Send, U: Host + Send")
|
||||
"T: Send, U: Host + Send".to_string()
|
||||
} else {
|
||||
format!("U: Host")
|
||||
"U: Host".to_string()
|
||||
};
|
||||
uwriteln!(
|
||||
self.src,
|
||||
@@ -1259,7 +1259,7 @@ impl<'a> InterfaceGenerator<'a> {
|
||||
|
||||
let ret = (snake, mem::take(&mut self.src).to_string());
|
||||
self.src = prev;
|
||||
return ret;
|
||||
ret
|
||||
}
|
||||
|
||||
fn define_rust_guest_export(&mut self, ns: Option<&str>, func: &Function) {
|
||||
|
||||
@@ -235,7 +235,7 @@ pub trait RustGenerator<'a> {
|
||||
if self.uses_two_names(&info) {
|
||||
result.push((self.param_name(ty), TypeMode::AllBorrowed("'a")));
|
||||
}
|
||||
return result;
|
||||
result
|
||||
}
|
||||
|
||||
/// Writes the camel-cased 'name' of the passed type to `out`, as used to name union variants.
|
||||
|
||||
@@ -95,7 +95,7 @@ impl Types {
|
||||
_ => continue,
|
||||
};
|
||||
if let Some(Type::Id(id)) = err {
|
||||
self.type_info.get_mut(&id).unwrap().error = true;
|
||||
self.type_info.get_mut(id).unwrap().error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user