From a43a8c546ed6fda1c8dfef7730d80834e6807a15 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 11 May 2023 04:34:20 +0900 Subject: [PATCH] Revert a few .as_str() calls by adding it to ast --- Cargo.lock | 15 ++++++--------- Cargo.toml | 8 ++++---- compiler/codegen/src/compile.rs | 8 ++++---- compiler/codegen/src/symboltable.rs | 4 ++-- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cac8cb546b..5e9ae3b52a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1804,7 +1804,7 @@ dependencies = [ [[package]] name = "ruff_source_location" version = "0.0.0" -source = "git+https://github.com/youknowone/RustPython-parser.git?rev=aa101e4f2693624eddabe35eaf3067bba65331df#aa101e4f2693624eddabe35eaf3067bba65331df" +source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119" dependencies = [ "memchr", "once_cell", @@ -1814,10 +1814,7 @@ dependencies = [ [[package]] name = "ruff_text_size" version = "0.0.0" -source = "git+https://github.com/youknowone/RustPython-parser.git?rev=aa101e4f2693624eddabe35eaf3067bba65331df#aa101e4f2693624eddabe35eaf3067bba65331df" -dependencies = [ - "serde", -] +source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119" [[package]] name = "rustc-hash" @@ -1875,7 +1872,7 @@ dependencies = [ [[package]] name = "rustpython-ast" version = "0.2.0" -source = "git+https://github.com/youknowone/RustPython-parser.git?rev=aa101e4f2693624eddabe35eaf3067bba65331df#aa101e4f2693624eddabe35eaf3067bba65331df" +source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119" dependencies = [ "num-bigint", "rustpython-literal", @@ -1999,7 +1996,7 @@ dependencies = [ [[package]] name = "rustpython-literal" version = "0.2.0" -source = "git+https://github.com/youknowone/RustPython-parser.git?rev=aa101e4f2693624eddabe35eaf3067bba65331df#aa101e4f2693624eddabe35eaf3067bba65331df" +source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119" dependencies = [ "hexf-parse", "lexical-parse-float", @@ -2010,7 +2007,7 @@ dependencies = [ [[package]] name = "rustpython-parser" version = "0.2.0" -source = "git+https://github.com/youknowone/RustPython-parser.git?rev=aa101e4f2693624eddabe35eaf3067bba65331df#aa101e4f2693624eddabe35eaf3067bba65331df" +source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119" dependencies = [ "anyhow", "itertools", @@ -2032,7 +2029,7 @@ dependencies = [ [[package]] name = "rustpython-parser-core" version = "0.2.0" -source = "git+https://github.com/youknowone/RustPython-parser.git?rev=aa101e4f2693624eddabe35eaf3067bba65331df#aa101e4f2693624eddabe35eaf3067bba65331df" +source = "git+https://github.com/youknowone/RustPython-parser.git?rev=5b2af304a2baa53598e594097824165d4ac7a119#5b2af304a2baa53598e594097824165d4ac7a119" dependencies = [ "itertools", "lz4_flex", diff --git a/Cargo.toml b/Cargo.toml index 60674bd0a9..b80cd29c6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,10 +29,10 @@ rustpython-pylib = { path = "pylib" } rustpython-stdlib = { path = "stdlib" } rustpython-doc = { git = "https://github.com/RustPython/__doc__", branch = "main" } -rustpython-literal = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "aa101e4f2693624eddabe35eaf3067bba65331df" } -rustpython-parser-core = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "aa101e4f2693624eddabe35eaf3067bba65331df" } -rustpython-parser = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "aa101e4f2693624eddabe35eaf3067bba65331df" } -rustpython-ast = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "aa101e4f2693624eddabe35eaf3067bba65331df" } +rustpython-literal = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "5b2af304a2baa53598e594097824165d4ac7a119" } +rustpython-parser-core = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "5b2af304a2baa53598e594097824165d4ac7a119" } +rustpython-parser = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "5b2af304a2baa53598e594097824165d4ac7a119" } +rustpython-ast = { git = "https://github.com/youknowone/RustPython-parser.git", rev = "5b2af304a2baa53598e594097824165d4ac7a119" } # rustpython-literal = { path = "../RustPython-parser/literal" } # rustpython-parser-core = { path = "../RustPython-parser/core" } # rustpython-parser = { path = "../RustPython-parser/parser" } diff --git a/compiler/codegen/src/compile.rs b/compiler/codegen/src/compile.rs index 148b996eb2..e65f70e24f 100644 --- a/compiler/codegen/src/compile.rs +++ b/compiler/codegen/src/compile.rs @@ -582,16 +582,16 @@ impl Compiler { value: num_traits::Zero::zero(), }); self.emit_constant(ConstantData::None); - let idx = self.name(name.name.as_str()); + let idx = self.name(&name.name); emit!(self, Instruction::ImportName { idx }); if let Some(alias) = &name.asname { - for part in name.name.as_str().split('.').skip(1) { + for part in name.name.split('.').skip(1) { let idx = self.name(part); emit!(self, Instruction::LoadAttr { idx }); } self.store_name(alias.as_str())? } else { - self.store_name(name.name.as_str().split('.').next().unwrap())? + self.store_name(name.name.split('.').next().unwrap())? } } } @@ -600,7 +600,7 @@ impl Compiler { module, names, }) => { - let import_star = names.iter().any(|n| n.node.name.as_str() == "*"); + let import_star = names.iter().any(|n| &n.node.name == "*"); let from_list = if import_star { if self.ctx.in_func() { diff --git a/compiler/codegen/src/symboltable.rs b/compiler/codegen/src/symboltable.rs index d5243d09c4..bfbc933661 100644 --- a/compiler/codegen/src/symboltable.rs +++ b/compiler/codegen/src/symboltable.rs @@ -646,7 +646,7 @@ impl SymbolTableBuilder { if let ImportFrom(StmtImportFrom { module, names, .. }) = &statement.node { if module.as_ref().map(|id| id.as_str()) == Some("__future__") { for feature in names { - if feature.node.name.as_str() == "annotations" { + if &feature.node.name == "annotations" { self.future_annotations = true; } } @@ -752,7 +752,7 @@ impl SymbolTableBuilder { } else { // `import module` self.register_name( - name.node.name.as_str().split('.').next().unwrap(), + name.node.name.split('.').next().unwrap(), SymbolUsage::Imported, location, )?;