8000 Merge pull request #1 from RustPython/master · RustPython/RustPython@b4c28ad · GitHub
[go: up one dir, main page]

Skip to content

Commit b4c28ad

Browse files
authored
Merge pull request #1 from RustPython/master
Sync with master

2 parents dc8c9d7 + ad111b0 commit b4c28ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3612
-3232
lines changed

.github/workflows/cron-ci.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,33 @@ jobs:
5656
uses: codecov/codecov-action@v1
5757
with:
5858
file: ${{ steps.coverage.outputs.report }}
59+
60+
testdata:
61+
name: Collect regression test data
62+
runs-on: ubuntu-latest
63+
steps:
64+
- uses: actions/checkout@master
65+
- name: build rustpython
66+
uses: actions-rs/cargo@v1
67+
with:
68+
command: build
69+
args: --release --verbose --all
70+
- name: collect tests data
71+
run: cargo run --release tests/jsontests.py
72+
env:
73+
RUSTPYTHONPATH: ${{ github.workspace }}/Lib
74+
- name: upload tests data to the website
75+
env:
76+
SSHKEY: ${{ secrets.ACTIONS_TESTS_DATA_DEPLOY_KEY }}
77+
GITHUB_ACTOR: ${{ github.actor }}
78+
run: |
79+
echo "$SSHKEY" >~/github_key
80+
chmod 600 ~/github_key
81+
export GIT_SSH_COMMAND="ssh -i ~/github_key"
82+
83+
git clone git@github.com:RustPython/rustpython.github.io.git website
84+
cd website
85+
cp ../tests/cpython_tests_results.json ./_data/regrtests_results.json
86+
git add ./_data/regrtests_results.json
87+
git -c user.name="Github Actions" -c user.email="actions@github.com" commit -m "Update regression test results" --author="$GITHUB_ACTOR"
88+
git push

Lib/test/string_tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ def test_rsplit(self):
500500
self.checkraises(ValueError, 'hello', 'rsplit', '')
501501
self.checkraises(ValueError, 'hello', 'rsplit', '', 0)
502502

503-
@unittest.skip("TODO: RUSTPYTHON test_bytes")
504503
def test_replace(self):
505504
EQ = self.checkequal
506505

Lib/test/test_bytes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,8 @@ def test_delitem(self):
12911291
del b[4]
12921292
self.assertEqual(b, bytearray([1, 2, 3, 4, 6, 7, 8]))
12931293

1294-
@unittest.skip("TODO: RUSTPYTHON")
1294+
# TODO: RUSTPYTHON
1295+
@unittest.expectedFailure
12951296
def test_setslice(self):
12961297
b = bytearray(range(10))
12971298
self.assertEqual(list(b), list(range(10)))

Lib/types.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ async def _c(): pass
2424
CoroutineType = type(_c)
2525
_c.close() # Prevent ResourceWarning
2626

27-
# XXX RUSTPYTHON TODO: async generators
28-
# async def _ag():
29-
# yield
30-
# _ag = _ag()
31-
# AsyncGeneratorType = type(_ag)
27+
async def _ag():
28+
yield
29+
_ag = _ag()
30+
AsyncGeneratorType = type(_ag)
3231

3332
class _C:
3433
def _m(self): pass

compiler/src/peephole.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<O: OutputStream> PeepholeOptimizer<O> {
9292
}
9393

9494
fn optimize(&mut self) {
95-
apply_optimizations!(self, operator, unpack);
95+
apply_optimizations!(self, operator /* , unpack */);
9696
}
9797
}
9898

compiler/src/peephole/optimizations.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,27 @@ pub fn operator(buf: &mut impl OptimizationBuffer) {
7373
}
7474
}
7575

76-
pub fn unpack(buf: &mut impl OptimizationBuffer) {
77-
let (instruction, meta) = buf.pop();
78-
if let Instruction::UnpackSequence { size } = instruction {
79-
let (arg, arg_meta) = buf.pop();
80-
match arg {
81-
Instruction::BuildTuple {
82-
size: tup_si 55F ze,
83-
unpack,
84-
} if !unpack && tup_size == size => {
85-
buf.emit(
86-
Instruction::Reverse { amount: size },
87-
vec![arg_meta, meta].into(),
88-
);
89-
}
90-
arg => {
91-
buf.emit(arg, arg_meta);
92-
buf.emit(instruction, meta);
93-
}
94-
}
95-
} else {
96-
buf.emit(instruction, meta)
97-
}
98-
}
76+
// TODO: make a version of this that doesn't miscompile `a, b = (1, 2) if True else (3, 4)`
77+
// pub fn unpack(buf: &mut impl OptimizationBuffer) {
78+
// let (instruction, meta) = buf.pop();
79+
// if let Instruction::UnpackSequence { size } = instruction {
80+
// let (arg, arg_meta) = buf.pop();
81+
// match arg {
82+
// Instruction::BuildTuple {
83+
// size: tup_size,
84+
// unpack,
85+
// } if !unpack && tup_size == size => {
86+
// buf.emit(
87+
// Instruction::Reverse { amount: size },
88+
// vec![arg_meta, meta].into(),
89+
// );
90+
// }
91+
// arg => {
92+
// buf.emit(arg, arg_meta);
93+
// buf.emit(instruction, meta);
94+
// }
95+
// }
96+
// } else {
97+
// buf.emit(instruction, meta)
98+
// }
99+
// }

compiler/src/symboltable.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ pub struct Symbol {
9595
pub name: String,
9696
// pub table: SymbolTableRef,
9797
pub scope: SymbolScope,
98-
pub is_param: bool,
9998
pub is_referenced: bool,
10099
pub is_assigned: bool,
101100
pub is_parameter: bool,
@@ -108,7 +107,6 @@ impl Symbol {
108107
name: name.to_owned(),
109108
// table,
110109
scope: SymbolScope::Unknown,
111-
is_param: false,
112110
is_referenced: false,
113111
is_assigned: false,
114112
is_parameter: false,
@@ -741,7 +739,6 @@ impl SymbolTableBuilder {
741739
Ok(())
742740
}
743741

744-
#[allow(clippy::single_match)]
745742
fn register_name(&mut self, name: &str, role: SymbolUsage) -> SymbolTableResult {
746743
let scope_depth = self.tables.len();
747744
let table = self.tables.last_mut().unwrap();
@@ -777,13 +774,11 @@ impl SymbolTableBuilder {
777774

778775
// Some more checks:
779776
match role {
780-
SymbolUsage::Nonlocal => {
781-
if scope_depth < 2 {
782-
return Err(SymbolTableError {
783-
error: format!("cannot define nonlocal '{}' at top level.", name),
784-
location,
785-
});
786-
}
777+
SymbolUsage::Nonlocal if scope_depth < 2 => {
778+
return Err(SymbolTableError {
779+
error: format!("cannot define nonlocal '{}' at top level.", name),
780+
location,
781+
})
787782
}
788783
_ => {
789784
// Ok!

derive/src/from_args.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ enum ParameterKind {
1616

1717
impl ParameterKind {
1818
fn from_ident(ident: &Ident) -> Option<ParameterKind> {
19-
if ident == "positional_only" {
20-
Some(ParameterKind::PositionalOnly)
21-
} else if ident == "positional_or_keyword" {
22-
Some(ParameterKind::PositionalOrKeyword)
23-
} else if ident == "keyword_only" {
24-
Some(ParameterKind::KeywordOnly)
25-
} else {
26-
None
19+
match ident.to_string().as_str() {
20+
"positional_only" => Some(ParameterKind::PositionalOnly),
21+
"positional_or_keyword" => Some(ParameterKind::PositionalOrKeyword),
22+
"keyword_only" => Some(ParameterKind::KeywordOnly),
23+
_ => None,
2724
}
2825
}
2926
}
@@ -150,6 +147,13 @@ fn generate_field(field: &Field) -> Result<TokenStream2, Diagnostic> {
150147
};
151148

152149
let name = &field.ident;
150+
if let Some(name) = name {
151+
if name.to_string().starts_with("_phantom") {
152+
return Ok(quote! {
153+
#name: std::marker::PhantomData,
154+
});
155+
}
156+
}
153157
let middle = quote! {
154158
.map(|x| ::rustpython_vm::pyobject::TryFromObject::try_from_object(vm, x)).transpose()?
155159
};
@@ -210,8 +214,9 @@ pub fn impl_from_args(input: DeriveInput) -> Result<TokenStream2, Diagnostic> {
210214
};
211215

212216
let name = input.ident;
217+
let (impl_generics, ty_generics D96B , where_clause) = input.generics.split_for_impl();
213218
let output = quote! {
214-
impl ::rustpython_vm::function::FromArgs for #name {
219+
impl #impl_generics ::rustpython_vm::function::FromArgs for #name #ty_generics #where_clause {
215220
fn from_args(
216221
vm: &::rustpython_vm::VirtualMachine,
217222
args: &mut ::rustpython_vm::function::PyFuncArgs

derive/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod error;
1212
mod compile_bytecode;
1313
mod from_args;
1414
mod pyclass;
15+
mod pymodule;
1516
mod util;
1617

1718
use error::{extract_spans, Diagnostic};
@@ -44,6 +45,13 @@ pub fn pyimpl(attr: TokenStream, item: TokenStream) -> TokenStream {
4445
result_to_tokens(pyclass::impl_pyimpl(attr, item))
4546
}
4647

48+
#[proc_macro_attribute]
49+
pub fn pymodule(attr: TokenStream, item: TokenStream) -> TokenStream {
50+
let attr = parse_macro_input!(attr as AttributeArgs);
51+
let item = parse_macro_input!(item as Item);
52+
result_to_tokens(pymodule::impl_pymodule(attr, item))
53+
}
54+
4755
#[proc_macro_attribute]
4856
pub fn pystruct_sequence(attr: TokenStream, item: TokenStream) -> TokenStream {
4957
let attr = parse_macro_input!(attr as AttributeArgs);

0 commit comments

Comments
 (0)
0