Ignore:
Timestamp:
Jun 11, 2024, 5:08:11 PM (2 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
3eb5f993, 5144898, f30be51f
Parents:
2ab31fd
Message:

Updates to the module proposal. Just an assortment of clean-up and things I missed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/modules.md

    r2ab31fd rf1d2c44  
    99Note that terminology is not fixed across languages. For instance, some languages use the word package or library instead. Module was chosen as the generic term because it seems to have the least amount of other uses (for example, a package is sometimes a group of modules).
    1010
    11 In C there is no formal definition of module, but informally modules are a pair of files, the body file (.c) and the header (.h). The header provides the interface and the body file gives the implementation. (A translation unit is a source file, usually a .c file, and all the recursively included files.) Some modules, like the main module,
     11In C there is no formal definition of module, but informally modules are a pair of files, the body file (.c) and the header (.h). The header provides the interface and the body file gives the implementation. (A translation unit is a source file, usually a .c file, and all the recursively included files.) Some modules, like the main module, may only be the body and others may only be the header.
    1212
    1313Uses of Modules
    1414---------------
    15 This section covers the features module system to allow for the separatation of code across modules and why
     15This section covers the features module system. What are the components that allow for seprate compliation? And then what are the common ways it is implemented, as a baseline.
    1616
    17 Modules are often, but not always, the means by which a language views source files. There is almost always some kind of parity between modules and source files, with modules being mapped onto one (or a few) source files. Sometimes the use of modules is used to find the approprate source files, requring this parity to be enforced in the language. Other times the parity is just a convention or is enforced for other reasons.
     17Modules are often, but not always, how a language views and manages source files. There is an overlap in purpose, reuse and organization, between modules and files, so it is a natural fit.
    1818
    19 []
     19In almost all languages, there is some kind of parity between modules and source files, with modules being mapped onto one (or a few) source files. Sometimes the use of modules is used to find the approprate source files, requring this parity to be enforced in the language. Other times the parity is just a convention or is enforced for other reasons.
    2020
    2121If there is a universal feature of modules, it is information visibility. Modules decide what information within them is visible to other modules. Here visibility is the course grained sense of "visible in another module for any purpose".
    2222
    23 []
     23Visibility can be implemented different ways, but most can be conidered to be an explicit or implicit export list, that is some way to list declarations that are visible to other modules. This may be an explicit listing of modules, another direct system, such as specifiers an the declarations, or some implicit style that calls out certain declarations as visible.
    2424
    2525Accessablity is the more fine grained partner to visibility, allowing for information to be visible, but only usable for certain purposes. This includes privacy and friendship - only usable in certain parts of the program - or inlining information - only usable by the optimizer.
    2626
     27Accessablity is usually implemented by notes as part of a declaration.
     28
    2729In languages that have namespacing/qualified-names, modules will often interact with namespaces. Such as each module placing its declarations in a namespace of the same name.
     30
     31When this does happen, the module name is treated as a namespace name after the module is imported.
    2832
    2933C Comparisons
     
    3135To be 99% compatible with C, Cforall pretty much has to use the C-preprocessor (or replace it with a Cforall-preprocessor, that is in turn backwards compatible). To this end, how well does the C-preprocessor operate in these areas?
    3236
    33 C is very good at separate compilation. Parallel computation is completely unhindered and recompilation is good, although sometimes a bit preemptive. Information sharing is a bit weaker, C has a tendency to overshare because its copy-and-paste rule gets the entire file. This is also why its recompilation can be preemptive. It is on the user to follow conventions and figure out what information needs to/should be shared. (On a personal note, I have spent a lot of time working to remove extra includes from the Cforall compiler.)
     37Separate compilation can be broken into two parts, parallel compliation and reducing recompilation.
     38The C-preprocessor is almost ideal in terms of parallel computation, it has no compilation order dependences between modules, reguardless of the logical dependeces between the modules.
     39Reducing recompliation is a bit more mixed. A file is recompiled if it or any file it directly or indirectly includes. This is a reasonable approximation, but has many false positives from generally irrelivant changes (ex. to a comment) or recursive includes that are not needed in this particular module, only for other header information incidentally included.
    3440
    35 C doesn't use modules to implement any behaviour. Except for preserved source location information used in error messages, they are completely erased by the preprocessor.
     41Of the supporting features, C only uses visibility. All information in a header is visible and anything only in the body is not. Modules are erased (except for source locations used in error messages) and cannot be used after the preprocessor.
     42
     43This leads to a very particular limitation of modules in C (and C++), no declaration remembers which module it came from. In early C this meant that nothing in a header could cause anything to be added to a translation unit, only to help give meaning to declarations in bodies. Now there are cases where that is allowed, but only if redundent copies are allowed or the linker has to be able to remove all but one copy (and which one is left is the linker's decision).
    3644
    3745Module Linkage Specification
Note: See TracChangeset for help on using the changeset viewer.