[rust] Autofix lints

This commit is contained in:
Joe Savona
2023-08-10 10:59:50 -04:00
parent b8f1d37b6a
commit 74a062ba9d
13 changed files with 34 additions and 1442 deletions
@@ -2,9 +2,8 @@ use std::collections::HashSet;
use forget_diagnostics::Diagnostic;
use forget_estree::{
AssignmentTarget, BinaryExpression, BlockStatement, Expression, ExpressionOrSpread,
ExpressionOrSuper, ForInit, ForStatement, Function, FunctionExpression, IfStatement,
IntoFunction, JsValue, Literal, Number, Pattern, Statement, VariableDeclaration,
AssignmentTarget, BlockStatement, Expression, ExpressionOrSpread, ExpressionOrSuper, ForInit,
Function, IntoFunction, JsValue, Pattern, Statement, VariableDeclaration,
VariableDeclarationKind,
};
use forget_hir::{
@@ -13,7 +12,7 @@ use forget_hir::{
Operand, PlaceOrSpread, TerminalValue,
};
use crate::builder::{Binding, Builder, LoopScope};
use crate::builder::{Builder, LoopScope};
use crate::context::get_context_identifiers;
use crate::error::BuildHIRError;
@@ -490,9 +489,7 @@ fn lower_function<T: IntoFunction>(
_builder: &mut Builder,
function: &T,
) -> Result<forget_hir::FunctionExpression, Diagnostic> {
println!("get_context_identifiers() ...");
let context_identifiers = get_context_identifiers(env, function);
println!("ok");
let mut context = Vec::new();
let mut seen = HashSet::new();
for declaration_id in context_identifiers {
@@ -526,7 +523,7 @@ fn lower_jsx_element(
.iter()
.map(|attr| lower_jsx_attribute(env, builder, attr))
.collect();
let props = props?;
let _props = props?;
let children: Result<Vec<Operand>, Diagnostic> = expr
.children
.iter()
@@ -535,7 +532,7 @@ fn lower_jsx_element(
Ok(Operand { effect: None, ix })
})
.collect();
let children = children?;
let _children = children?;
todo!("lower jsx element");
// Ok(JSXElement {
// tag: todo!(),
@@ -549,17 +546,17 @@ fn lower_jsx_element(
}
fn lower_jsx_attribute(
env: &Environment,
builder: &mut Builder,
attr: &forget_estree::JSXAttributeOrSpread,
_env: &Environment,
_builder: &mut Builder,
_attr: &forget_estree::JSXAttributeOrSpread,
) -> Result<JSXAttribute, Diagnostic> {
todo!("lower jsx attribute")
}
fn lower_jsx_child(
env: &Environment,
builder: &mut Builder,
child: &forget_estree::JSXChildItem,
_env: &Environment,
_builder: &mut Builder,
_child: &forget_estree::JSXChildItem,
) -> Result<InstrIx, Diagnostic> {
todo!("lower jsx child")
}
@@ -603,7 +600,7 @@ fn lower_assignment_pattern(
fn lower_identifier_for_assignment(
env: &Environment,
builder: &mut Builder,
_builder: &mut Builder,
kind: InstructionKind,
node: &forget_estree::Identifier,
) -> Result<IdentifierOperand, Diagnostic> {
@@ -3,9 +3,9 @@ use std::rc::Rc;
use forget_diagnostics::Diagnostic;
use forget_hir::{
initialize_hir, BasicBlock, BlockId, BlockKind, Blocks, Environment, GotoKind, Identifier,
IdentifierData, InstrIx, Instruction, InstructionIdGenerator, InstructionValue, Terminal,
TerminalValue, Type, HIR,
initialize_hir, BasicBlock, BlockId, BlockKind, Blocks, Environment, GotoKind, IdentifierData,
InstrIx, Instruction, InstructionIdGenerator, InstructionValue, Terminal, TerminalValue, Type,
HIR,
};
use crate::BuildHIRError;
@@ -42,12 +42,6 @@ pub(crate) struct WipBlock {
pub instructions: Vec<InstrIx>,
}
pub(crate) enum Binding {
Local(Identifier),
Module(Identifier),
Global,
}
#[derive(Clone, PartialEq, Eq, Debug)]
enum ControlFlowScope {
Loop(LoopScope),
@@ -9,10 +9,6 @@ pub(crate) fn get_context_identifiers<T: IntoFunction>(
node: &T,
) -> Vec<DeclarationId> {
let function_scope = env.scope(node.function()).unwrap();
println!(
"get_context_identifiers for function scope {:?}",
function_scope.id()
);
let mut free = FreeVariables::default();
let mut seen = HashSet::new();
populate_free_variable_references(&mut free, &mut seen, function_scope);
@@ -28,28 +24,11 @@ fn populate_free_variable_references(
) {
for reference in scope.references() {
if !seen.insert(reference.declaration().id()) {
println!(
"skip {}${:?}",
reference.declaration().name(),
reference.declaration().id()
);
continue;
}
let declaration_scope = reference.declaration().scope();
if !declaration_scope.is_descendant_of(scope) {
println!(
"free variable: not descendant {}${:?}",
reference.declaration().name(),
reference.declaration().id()
);
free.push(reference.declaration().id())
} else {
println!(
"local variable: descendant {}${:?} scope={:?}",
reference.declaration().name(),
reference.declaration().id(),
reference.declaration().scope().id()
);
}
}
for child in scope.children() {
@@ -1,5 +1,8 @@
// @generated
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
use std::num::NonZeroU32;
use serde::ser::{Serializer, SerializeMap};
use serde::{Serialize, Deserialize};
File diff suppressed because it is too large Load Diff
@@ -145,7 +145,7 @@ pub trait Visitor_DEPRECATED<'ast> {
self.visit_variable_declarator(declarator)
}
}
Declaration::TSTypeAliasDeclaration(declaration) => {
Declaration::TSTypeAliasDeclaration(_declaration) => {
todo!("visit TSTypeAliasDeclaration")
}
}
@@ -268,7 +268,7 @@ pub trait Visitor_DEPRECATED<'ast> {
self.visit_expression(&stmt.object);
self.visit_statement(&stmt.body);
}
Statement::TSTypeAliasDeclaration(stmt) => {
Statement::TSTypeAliasDeclaration(_stmt) => {
todo!("visit TSTypeAliasDeclaration")
}
}
@@ -88,10 +88,11 @@ impl Grammar {
.map(|(name, operator)| operator.codegen(name))
.collect();
// println!("{}", quote! {#(#node_visitors)*});
// println!("{}", quote! {#(#enum_visitors)*});
quote! {
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
use std::num::NonZeroU32;
use serde::ser::{Serializer, SerializeMap};
use serde::{Serialize,Deserialize};
@@ -406,9 +407,7 @@ impl Node {
if let Some(convert_with) = &field.hermes_convert_with {
let convert_with = format_ident!("{}", convert_with);
return quote! {
// println!("read {}.{}", #name_str, #name);
let #field_name = #convert_with(cx, unsafe { hermes::parser::#helper(node) } );
// println!("ok");
}
}
match type_kind {
@@ -416,30 +415,22 @@ impl Node {
match type_name_str.as_ref() {
"bool" => {
quote! {
// println!("read {}.{}", #name_str, #name);
let #field_name = unsafe { hermes::parser::#helper(node) };
// println!("ok");
}
}
"Number" => {
quote! {
// println!("read {}.{}", #name_str, #name);
let #field_name = convert_number(unsafe { hermes::parser::#helper(node) });
// println!("ok");
}
}
"String" => {
quote! {
// println!("read {}.{}", #name_str, #name);
let #field_name = convert_string(cx, unsafe { hermes::parser::#helper(node) });
// println!("ok");
}
}
_ => {
quote! {
// println!("read {}.{}", #name_str, #name);
let #field_name = #type_name::convert(cx, unsafe { hermes::parser::#helper(node) });
// println!("ok");
}
}
}
@@ -448,32 +439,24 @@ impl Node {
match type_name_str.as_ref() {
"String" => {
quote! {
// println!("read {}.{}", #name_str, #name);
let #field_name = convert_option_string(cx, unsafe { hermes::parser::#helper(node) });
// println!("ok");
}
}
_ => {
quote! {
// println!("read {}.{}", #name_str, #name);
let #field_name = convert_option(unsafe { hermes::parser::#helper(node) }, |node| #type_name::convert(cx, node));
// println!("ok");
}
}
}
}
TypeKind::Vec => {
quote! {
// println!("read {}.{}", #name_str, #name);
let #field_name = convert_vec(unsafe { hermes::parser::#helper(node) }, |node| #type_name::convert(cx, node));
// println!("ok");
}
}
TypeKind::VecOfOption => {
quote! {
// println!("read {}.{}", #name_str, #name);
let #field_name = convert_vec_of_option(unsafe { hermes::parser::#helper(node) }, |node| #type_name::convert(cx, node));
// println!("ok");
}
}
}
@@ -22,7 +22,6 @@ fn fixtures() {
let mut output = String::new();
let analysis = analyze(&ast);
// println!("{:#?}", analysis.debug());
let environment = Environment::new(
Features {
validate_frozen_lambdas: true,
@@ -38,10 +37,6 @@ fn fixtures() {
}
match build(&environment, &fun.function) {
Ok(mut fun) => {
// println!("{fun:#?}");
// let mut out = String::new();
// fun.print(&fun.body, &mut out).unwrap();
// println!("{out}");
println!("ok build");
enter_ssa(&environment, &mut fun).unwrap();
println!("ok enter_ssa");
@@ -1,10 +1,9 @@
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::process::id;
use std::rc::Rc;
use forget_estree::{BindingId, ESTreeNode};
use forget_semantic_analysis::{AstNode, DeclarationId, ScopeManager, ScopeView};
use forget_estree::ESTreeNode;
use forget_semantic_analysis::{DeclarationId, ScopeManager, ScopeView};
use crate::{
BlockId, Features, Identifier, IdentifierData, IdentifierId, Registry, Type, TypeVarId,
@@ -1,9 +1,8 @@
use forget_diagnostics::Diagnostic;
use forget_estree::{
AssignmentOperator, AssignmentPropertyOrRestElement, AssignmentTarget, Expression,
ExpressionOrSuper, ForInInit, ForInit, Function, FunctionBody, Identifier, IntoFunction,
JSXElementName, Pattern, Program, SourceRange, SourceType, Statement, VariableDeclarationKind,
Visitor,
ExpressionOrSuper, ForInInit, ForInit, FunctionBody, Identifier, IntoFunction, JSXElementName,
Pattern, Program, SourceRange, SourceType, Statement, VariableDeclarationKind, Visitor,
};
use crate::{AstNode, DeclarationKind, LabelKind, ReferenceKind, ScopeId, ScopeKind, ScopeManager};
@@ -180,11 +180,11 @@ impl ScopeManager {
}
}
pub fn lookup_break(&self, scope: ScopeId) -> Option<&Label> {
pub fn lookup_break(&self, _scope: ScopeId) -> Option<&Label> {
todo!()
}
pub fn lookup_continue(&self, scope: ScopeId) -> Option<&Label> {
pub fn lookup_continue(&self, _scope: ScopeId) -> Option<&Label> {
todo!()
}
@@ -142,6 +142,7 @@ impl<'m> std::fmt::Debug for ScopeView<'m> {
#[derive(Clone, Copy)]
pub struct LabelView<'m> {
#[allow(dead_code)]
pub(crate) manager: &'m ScopeManager,
pub(crate) label: &'m Label,
}
@@ -184,9 +184,9 @@ impl<'e, 'f> Builder<'e, 'f> {
// Else we have to look at predecessor blocks: bail if no predecessors
let block = self.blocks.block(block_id);
if block.predecessors.is_empty() {
println!("Unable to find previous id for {old_identifier:?}");
self.unknown.insert(old_identifier.id);
return old_identifier.clone();
panic!("Unable to find previous id for {old_identifier:?}");
// self.unknown.insert(old_identifier.id);
// return old_identifier.clone();
}
// If we haven't visited all predecessors, synthesize a new identifier
// and save it as an incomplete phi