Skip to content

Commit 03c4998

Browse files
authored
Add Phobos 3 Documentation (#9068)
* Add documentation from the Phobos 3 Design repo. Add section on Template Reduction by request of Walter. Split up documents for clarity. * Add README.md. Update documents using documents from the V3 Design Repo. * Move numeric to the math package.
1 parent 1417cc5 commit 03c4998

File tree

4 files changed

+247
-0
lines changed

4 files changed

+247
-0
lines changed

phobos/CONTRIBUTING.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Phobos 3 Contributors Guide
2+
3+
This document refers to contributions specific to Phobos 3. For the full documentation on contributing please see the guide here: [D Contributors Guide](https://github.com/dlang/phobos/blob/master/CONTRIBUTING.md).
4+
5+
## Naming and Style Guidelines
6+
7+
Names should follow the existing naming guidelines here: [D Style Guide](https://dlang.org/dstyle.html)
8+
9+
When selecting a name for a type or method, a quick survey of how other popular languages name the equivalent type/method should be performed. For example, in .NET and Java, the `currTime()` method would be named `now()`. Using the same names as popular languages reduces the friction experienced by the engineer when migrating to D. Be prepared to provide examples from your survey in the Pull Request. In cases where there is no clear agreement or two examples are equally represented an alias *may* be appropriate for the purposes of moving past the block.
10+
11+
Prefer whole words over abbreviations and dropped letters. For example, prefer `writeLine` over `writeln`. Choose the shortest name that accurately describes the feature. Abbreviations are acceptable where the abbreviation is in common usage and/or would result in a cumbersome name. Furthermore, non-standard abbreviations make it more difficult for non-English speakers to adopt the library.
12+
13+
Phobos will use a 100 soft and 120 hard character column limit. This will be enforced via `dfmt` and `.editorconfig` files provided with the distribution.
14+
15+
## Guidelines for Reviewers
16+
17+
### Silence is Approval
18+
19+
One of the complaints the community has made about D in general and Phobos in particular is that many PRs go un-reviewed and are left to rot. Therefore, in Phobos 3, if you are listed as a reviewer on a PR and you do not respond to a within 7 days to a pull request, your silence will be considered an approval. If the required reviewer is unavailable for any reason (ex: vacation, emergency, etc.), another reviewer can bypass them. Once they return they can provide comments and submit PR's to address any feedback on the PR's assigned to them that they missed.
20+
21+
### Disagreement Without Providing a Fix or Alternative is Approval
22+
23+
Another major community complaint is that PR's are routinely abandoned because somebody disagrees with how the PR does something, or believes that it will cause a problem, causing the PR to stall out. While the reviewer may be correct, simple disagreement cannot be sufficient reason to block a PR without providing any alternative implementation. Therefore, the disagreeing reviewer must either provide a PR/patch to the primary PR or provide an alternative implementation in a new PR that addresses their concern. The disagreeing reviewer must ensure that their PR references the original PR. If no alternatives are provided, the PR will be merged and the disagreeing reviewer is welcome to base their future alternative implementation on the merged work.

phobos/Design.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Phobos 3 Design Goals
2+
3+
## Rationale
4+
5+
Phobos v2 is well over a decade old. As time goes by, best practices have evolved, mistakes have become apparent, needs have changed, and better ideas have appeared.
6+
7+
Phobos must also evolve.
8+
9+
## History
10+
11+
* Phobos v1 was for D1
12+
* Phobos v2 was for D2
13+
14+
## Phobos 2
15+
16+
When Phobos v2 was developed, Phobos v1 was obsoleted. This broke a lot of existing code and was a wrenching change for the entire community. Old code needed to be rewritten to use Phobos v2. Some of the discarded v1 modules were restored in the unDead library for the convenience of older code, but the damage had been done.
17+
18+
The existing roots of `core` for the Runtime, `etc` for C Interfaces, and `std` for the v2 Standard Library are to remain reserved for the foreseeable future. Both v2 and v3 will share usage of the `core` and `etc` roots. The `std` root is to be maintained for compatibility but no new features will be added.
19+
20+
Therefore, v2 will continue to be supported following these rules moving forward:
21+
22+
- Will continue to be supported for compatibility purposes.
23+
- Will receive bug fixes and enhancements to adapt to new operating systems and new D Compiler Editions.
24+
- Will not add new functionality.
25+
- Existing Phobos v2 roots remain reserved indefinitely.
26+
- User code must be able to use v2 and v3 capabilities in the same project, however, there may be instances of incompatibility as v2 types are not support in v3 and vice versa.
27+
28+
## Phobos 3
29+
30+
This section is a list of design principles and goals that we have established for Phobos 3.
31+
32+
### Hybrid single-root/multi-trunk package design
33+
34+
Phobos v3 will use a single package root `phobos.` with multiple 'trunk' packages. This allows us to keep the old `std` package root while splitting up the new library into smaller, more manageable, components. Splitting the library into multiple packages provides the following benefits:
35+
36+
1. Only pay for what you use. Different roots can be compiled as separate static/shared libraries and linked as needed, reducing the overall weight of executables. This offers some relief to the long standing community request to break Phobos into individual packages. While we do not agree with atomizing Phobos to the extreme degree of one package per module, multiple package roots allow us to achieve some of that goal in a logical manner.
37+
2. Multiple trunks allow for layering components. The core roots form a foundation upon which to build higher-level packages.
38+
3. Multiple trunks allow for an expanded feature set without adding to package depth.
39+
4. Not all trunks need to be implemented for a given platform to be considered "supported". If only the core roots are required for a platform to be considered supported it becomes significantly less complicated to port D to new platforms.
40+
5. Rules can be applied differently to core vs. non-core roots/trunks. For example, a possible rule could be that core roots/trunks may not throw exceptions under any circumstance, but non-core roots/trunks can. This is not intended to imply that throwing exceptions is encouraged, merely made available to allow more implementation flexibility for more complex constructs.
41+
6. The old `std` root can continue to be maintained and built independently of the new Phobos root.
42+
7. Multiple trunk packages allows Phobos to expand normally without running into the 64k DLL symbol limit on Windows.
43+
44+
Currently the core roots/trunks for Phobos v3 are `core`, `etc`, and `phobos.sys`. As a rule, the `phobos.sys` trunk is not allowed to import from non-core trunks.
45+
46+
[Proposed Package Structure for Phobos 3](PackageMap.md)
47+
48+
### Strings
49+
50+
#### No Autodecoding
51+
52+
Autodecoding turned out to be a mistake because it is pervasive and impractical to disable. The user will need to specifically ask for decoding using a filter such as `utf.byDchar`.
53+
54+
#### No Support For wchar And dchar
55+
56+
Since v2 was designed, the programming world has more or less standardized on UTF-8. The internals of algorithms, ranges, and functions will only work with UTF-8. Support for `wchar` and `dchar` will come in the form of algorithms `utf.byChar`, `utf.byWchar` and `utf.byDchar`.
57+
58+
#### Invalid Unicode
59+
60+
v2 throws an Exception when encountering invalid Unicode. Throwing an Exception entails using the GC, meaning string code cannot be `@nogc` nor `nothrow`. Besides, common processing of strings means being tolerant of invalid Unicode rather than failing. For example, invalid Unicode is commonplace in web pages, and throwing an Exception when rendering such pages is unacceptable.
61+
62+
Removal of autodecoding will in itself address most of the problem. When decoding code units into code points is needed, APIs should allow callers to specify the desired behavior, such as returning an "error" result, or replacing invalid sequences with the Unicode substitution character. Applications which need to handle untrusted data should be encouraged to use functions such as `std.utf.validate` (which return a `string` from `ubyte[]` only when it is valid UTF-8), or by-code-point decoding which reports errors for individual decoding operations.
63+
64+
### Memory Management
65+
66+
#### Minimize Memory Allocation
67+
68+
Enormous troubles and inefficiencies stem from general purpose library code allocating memory as the library sees fit. This makes the library code far less usable. Memory allocation strategies should be decided upon by the user of the library, not the library.
69+
70+
The easiest way to achieve this is to design the library to not use memory allocation at all. For example, std.path assembles paths from parts without doing allocations - it returns Voldemort ranges that the user can then use to emit the result into a buffer of the user's choosing.
71+
72+
Library routines may allocate memory internally, but not in a way that affects the user.
73+
74+
#### Minimize Exceptions
75+
76+
Exceptions are inefficient, use the GC, and they cannot be used in `nothrow` code. Examine each use of an Exception to see if it can be designed out of existence, like the Replacement Character method above. Design the return value such that an error is not necessary - for example, a string search function can return an empty string if not found rather than throw an Exception.
77+
78+
Investigate the use of Option/Sum types for error returns.
79+
80+
#### Split-Level Design
81+
82+
To achieve the twin goals of minimizing allocations and exceptions we will pursue a "split-level" design. The low-level function will take in a buffer instead of allocating and will return an error code instead of throwing exceptions. Then the high-level function can then call the low-level function with the appropriate buffers and can convert the error codes into exceptions. This allows us to maintain the simplicity of the high-level API while offering a low-level API those who need the additional performance.
83+
84+
### Additional Goals
85+
86+
#### Reduce Template Layering
87+
88+
Phobos 2 frequently over-uses templates resulting in situations such as `std.conv.to`, which has over 10 layers of templates before the actual implementation is reached. This makes the code virtually impossible to comprehend and significantly increases compile times. Templates in Phobos 2 were often used as a way to add in new functionality without breaking existing code or as premature optimizations, this led to haphazard and frequently unnecessary layering of templates. When porting code from Phobos 2 into Phobos 3, care should be taken to audit the usage of template and determine where reductions can be made.
89+
90+
#### Source Only
91+
92+
Currently, Phobos is distributed as a separately compiled library with "header" files that contain only the necessary Template implementations. The net result is that Phobos is primarily a source-only library in practice. By formalizing the library as a source only library, it becomes inured against variations in compiler flags. Whether it's a static or dynamic library becomes irrelevant, and there won't be impedance mismatches. DRuntime will remain a separately compiled library.
93+
94+
#### Single Script Builds
95+
96+
The current Phobos build process is convoluted and relies on old or niche tools. This makes the process of building Phobos tedious and discourages active community participation. Phobos 3 will use a single build script written in D. For example, running unittests would be accomplished with the command: `dmd -run build_v3.d unittests`.
97+
98+
### Versioning and Release Schedule
99+
100+
Phobos3 versions will be versioned and distributed on the same schedule as the corresponding Compiler Edition. This allows Phobos to adopt the latest features from the in-development edition during the development of that edition. However, while Phobos will follow the same release schedule as the compiler editions, Phobos itself will not use the 'edition' terminology and will instead retain the use of the term 'version'.
101+
102+
Phobos will use a slightly modified SemVer. The major version will increment with each Phobos release that is tied to a compiler edition, the minor version will increment with the monthly compiler releases, and the patch version will be incremented on any out-of-band bugfix releases that occur.
103+
104+
## Specific Issues
105+
106+
### std.stdio
107+
108+
This module merges file I/O with formatting. Those should be split apart. File I/O should be done with ranges, and the formatting should work with any ranges. `stdin`, `stdout`, and `stderr` match the `stdin`, `stdout` and `stderr` of `core.stdc.stdio`. This causes terrible confusion and will be renamed to `stdIn`, `stdOut`, and `stdErr`.
109+
110+
#### std.stdio.File
111+
112+
Does way, way too much. It's incomprehensible. Should be redesigned using building blocks.
113+
114+
### isXXXX templates
115+
116+
Are generally very hard to figure out what they do, such as `isSomeChar`. What the heck does that mean? The string ones are even worse.

phobos/PackageMap.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
## Phobos 3 Package Map
2+
3+
### Open Questions
4+
5+
1. `std.container`: Does it belong in `sys` or it's own root? This likely hinges on the status of [DIP1000](https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md) and whether or not it needs a ground up rewrite.
6+
2. `std.concurrency`: It is possible that not all platforms support Concurrency mechanics. Should `std.concurrency` be required in the core roots or moved to a non-core root?
7+
3. `std.parallelism`: It is possible that not all platforms support Task Parallelism mechanics. Should `std.parallelism` be required in the core roots or moved to a non-core root?
8+
4. `std.digest`: Cryptography routines have unique requirements that would be best served by providing them in their own root. But in all cases providing bespoke implementations of cryptography routines is never recommended. Third-party trusted implementations should be used instead. This could be from OpenSSL/LibreSSL (POSIX), SChannel/BCrypt (Windows), or CryptoKit (MacOS/IOS). It is acceptable to provide implementations of Non-Cryptographic routines such as CRC and Murmur. This would entail removing all the digests except CRC and Murmur from this package and building a separate cryptography package.
9+
5. Which, if any, modules should be removed? This could be either a permanent removal or pending replacement with ground-up rewrites.
10+
11+
### Proposed Package Structure (Existing Modules Only)
12+
13+
```
14+
core.*
15+
etc.*
16+
std.*
17+
phobos.sys
18+
| algorithm
19+
| comparison
20+
| iteration
21+
| mutation
22+
| searching
23+
| setops
24+
| sorting
25+
| array
26+
| bigint
27+
| bitmanip
28+
| checkedint
29+
| compiler
30+
| complex
31+
| conv
32+
| datetime
33+
| date
34+
| interval
35+
| stopwatch
36+
| systime
37+
| timezone
38+
| demangle
39+
| exception
40+
| functional
41+
| getopt
42+
| int128
43+
| io
44+
| console (stdio)
45+
| file
46+
| mmfile
47+
| path
48+
| math
49+
| algebraic
50+
| constants
51+
| exponential
52+
| hardware
53+
| operations
54+
| remainder
55+
| rounding
56+
| traits
57+
| trigonometry
58+
| special
59+
| numeric
60+
| meta
61+
| outbuffer
62+
| process
63+
| random
64+
| range
65+
| signals
66+
| stdint
67+
| string
68+
| sumtype
69+
| system
70+
| traits
71+
| typecons
72+
| uuid
73+
| variant
74+
phobos.data
75+
| base64
76+
| csv
77+
| json
78+
| zip
79+
phobos.text
80+
| ascii
81+
| encoding
82+
| uni
83+
| utf
84+
phobos.net
85+
| socket
86+
| uri
87+
```

phobos/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Phobos 3
2+
3+
This repo contains all the code required to build the Phobos Standard Library. This library will supersede the Phobos 2 library contained in the `std` folder when completed.
4+
5+
## Goals
6+
7+
Phobos 3 is currently under active development and is not ready for use at any level. Aside from the DLang forums, the Phobos goals
8+
* [Design Goals](Design.md) This document discusses what the established goals are for Phobos 3.
9+
* [Phobos V3 Discussions](https://github.com/dlang/PhobosV3-Design/discussions) Visit the GitHub Discussions to discuss additional design goals as well as specific feature ideas for V3 and beyond.
10+
11+
## How can I contribute?
12+
13+
We welcome contributions! Many people all over the world have helped make this project better.
14+
15+
* [D Lanaguage Contributors Guide](https://github.com/dlang/phobos/blob/master/CONTRIBUTING.md) explains the general guidelines for contributing to the D Programming Language.
16+
* [Phobos 3 Contributors Guide](CONTRIBUTING.md) explains the specific guidelines for contributing to Phobos 3.
17+
<!--* [Bug Reports](https://github.com/dlang/phobos/issues) Phobos 3 uses GitHub Issues to track bug reports. If you have a problem, please report it here. If you wnat to contribute but don't where to start, issues marked as "Easy"-->
18+
19+
## License
20+
21+
Phobos is licensed under the [Boost](https://github.com/dlang/phobos/blob/master/LICENSE_1_0.txt) license.

0 commit comments

Comments
 (0)