|
1 | 1 | """Generate C code for a Python C extension module from Python source code.""" |
2 | 2 |
|
3 | 3 | # FIXME: Basically nothing in this file operates on the level of a |
4 | | -# single module and it should be renamed. |
| 4 | +# single module and it should be renamed. |
5 | 5 |
|
6 | 6 | from __future__ import annotations |
7 | 7 |
|
|
71 | 71 | from mypyc.transform.spill import insert_spills |
72 | 72 | from mypyc.transform.uninit import insert_uninit_checks |
73 | 73 |
|
74 | | -# All of the modules being compiled are divided into "groups". A group |
| 74 | +# All the modules being compiled are divided into "groups". A group |
75 | 75 | # is a set of modules that are placed into the same shared library. |
76 | 76 | # Two common configurations are that every module is placed in a group |
77 | 77 | # by itself (fully separate compilation) and that every module is |
@@ -164,7 +164,7 @@ def report_config_data(self, ctx: ReportConfigContext) -> tuple[str | None, list |
164 | 164 | if hash_digest(meta_json) != ir_data["meta_hash"]: |
165 | 165 | return None |
166 | 166 |
|
167 | | - # Check that all of the source files are present and as |
| 167 | + # Check that all the source files are present and as |
168 | 168 | # expected. The main situation where this would come up is the |
169 | 169 | # user deleting the build directory without deleting |
170 | 170 | # .mypy_cache, which we should handle gracefully. |
@@ -215,8 +215,8 @@ def compile_scc_to_ir( |
215 | 215 | ) -> ModuleIRs: |
216 | 216 | """Compile an SCC into ModuleIRs. |
217 | 217 |
|
218 | | - Any modules that this SCC depends on must have either compiled or |
219 | | - loaded from a cache into mapper. |
| 218 | + Any modules that this SCC depends on must have either been compiled, |
| 219 | + type checked, or loaded from a cache into mapper. |
220 | 220 |
|
221 | 221 | Arguments: |
222 | 222 | scc: The list of MypyFiles to compile |
@@ -244,11 +244,11 @@ def compile_scc_to_ir( |
244 | 244 |
|
245 | 245 | for module in modules.values(): |
246 | 246 | for fn in module.functions: |
247 | | - # Insert uninit checks. |
| 247 | + # Insert checks for uninitialized values. |
248 | 248 | insert_uninit_checks(fn) |
249 | 249 | # Insert exception handling. |
250 | 250 | insert_exception_handling(fn) |
251 | | - # Insert refcount handling. |
| 251 | + # Insert reference count handling. |
252 | 252 | insert_ref_count_opcodes(fn) |
253 | 253 |
|
254 | 254 | if fn in env_user_functions: |
@@ -369,7 +369,7 @@ def write_cache( |
369 | 369 | cache are in sync and refer to the same version of the code. |
370 | 370 | This is particularly important if mypyc crashes/errors/is |
371 | 371 | stopped after mypy has written its cache but before mypyc has. |
372 | | - * The hashes of all of the source file outputs for the group |
| 372 | + * The hashes of all the source file outputs for the group |
373 | 373 | the module is in. This is so that the module will be |
374 | 374 | recompiled if the source outputs are missing. |
375 | 375 | """ |
@@ -429,7 +429,7 @@ def compile_modules_to_c( |
429 | 429 | Each shared library module provides, for each module in its group, |
430 | 430 | a PyCapsule containing an initialization function. |
431 | 431 | Additionally, it provides a capsule containing an export table of |
432 | | - pointers to all of the group's functions and static variables. |
| 432 | + pointers to all the group's functions and static variables. |
433 | 433 |
|
434 | 434 | Arguments: |
435 | 435 | result: The BuildResult from the mypy front-end |
@@ -504,16 +504,15 @@ def __init__( |
504 | 504 |
|
505 | 505 | The code for a compilation group contains an internal and an |
506 | 506 | external .h file, and then one .c if not in multi_file mode or |
507 | | - one .c file per module if in multi_file mode.) |
| 507 | + one .c file per module if in multi_file mode. |
508 | 508 |
|
509 | 509 | Arguments: |
510 | 510 | modules: (name, ir) pairs for each module in the group |
511 | 511 | source_paths: Map from module names to source file paths |
512 | 512 | group_name: The name of the group (or None if this is single-module compilation) |
513 | 513 | group_map: A map of modules to their group names |
514 | 514 | names: The name generator for the compilation |
515 | | - multi_file: Whether to put each module in its own source file regardless |
516 | | - of group structure. |
| 515 | + compiler_options: Mypyc specific options, including multi_file mode |
517 | 516 | """ |
518 | 517 | self.modules = modules |
519 | 518 | self.source_paths = source_paths |
@@ -642,7 +641,7 @@ def generate_c_for_modules(self) -> list[tuple[str, str]]: |
642 | 641 | decls = ext_declarations if declaration.is_type else declarations |
643 | 642 | if not declaration.is_type: |
644 | 643 | decls.emit_lines(f"extern {declaration.decl[0]}", *declaration.decl[1:]) |
645 | | - # If there is a definition, emit it. Otherwise repeat the declaration |
| 644 | + # If there is a definition, emit it. Otherwise, repeat the declaration |
646 | 645 | # (without an extern). |
647 | 646 | if declaration.defn: |
648 | 647 | emitter.emit_lines(*declaration.defn) |
@@ -770,13 +769,13 @@ def generate_export_table(self, decl_emitter: Emitter, code_emitter: Emitter) -> |
770 | 769 | def generate_shared_lib_init(self, emitter: Emitter) -> None: |
771 | 770 | """Generate the init function for a shared library. |
772 | 771 |
|
773 | | - A shared library contains all of the actual code for a |
| 772 | + A shared library contains all the actual code for a |
774 | 773 | compilation group. |
775 | 774 |
|
776 | 775 | The init function is responsible for creating Capsules that |
777 | 776 | wrap pointers to the initialization function of all the real |
778 | 777 | init functions for modules in this shared library as well as |
779 | | - the export table containing all of the exported functions and |
| 778 | + the export table containing all the exported functions and |
780 | 779 | values from all the modules. |
781 | 780 |
|
782 | 781 | These capsules are stored in attributes of the shared library. |
|
0 commit comments