Commit Graph
247 Commits
Author SHA1 Message Date
Jon Ross-PerkinsandChandler Carruth 10a87c045a Destructor syntax (#5017)
Fix destructor syntax ambiguity by switching to `fn destroy` mirroring
standard function syntax. This is a purely syntactic change, maintaining
destructor semantics.

This comes from leads question #4999

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2025-03-05 16:38:44 +00:00
Jon Ross-Perkins d843cc53fb Small rephrasing of 'partial' interaction with final classes (#5000)
I believe this reflects the intent, but the phrasing of "even if
`MyBaseClass` is not" implies that `MyBaseClass` _can_ be final in
`partial MyBaseClass`. Also, make clear it's allowed on `abstract`
classes, not only `base` (this seems explicitly intended from the
`MyAbstractClass` example around line 1482).
2025-02-21 21:52:45 +00:00
Dana Jansens 88283bfc56 Make open question on class variables more explicit (#4988) 2025-02-20 18:56:10 +00:00
Geoff Romerandjosh11b 09b06b4234 Document grammar of field and associated constant decls (#4980)
Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
2025-02-20 01:28:01 +00:00
Richard SmithandChandler Carruth e257051612 No predeclared identifiers, Core is a keyword (#4864)
Introduce a principle that the Carbon language should not encroach on
the
developer's namespace. Satisfy this principle by making `Core` a
keyword.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2025-02-01 03:03:30 +00:00
Richard Smith bc952b1a4b Document numeric type literals in lexical conventions. (#4842)
Also improve the precision of some other nearby documentation.
2025-01-24 01:57:42 +00:00
Jon Ross-Perkins 6f6e46ef57 Migrate tree-sitter support to MODULE.bazel (#4783)
The WORKSPACE file is deprecated; support is already off by default, and
it'll be removed in the next major bazel release. Our main dependency is
tree-sitter, and I'm trying to address that here.

We're currently using https://github.com/elliottt/rules_tree_sitter, but
that hasn't been updated in a couple years, meaning it lacks
MODULE.bazel support. In the registry, there's
https://registry.bazel.build/modules/tree-sitter-bazel, but this is only
the *parser* libraries of tree-sitter, not the *generator*. I'm using it
for that much, at least.

For the *generator*, which transforms grammar.js to parser.c/h, I'm just
requiring a non-hermetic invocation (i.e., people who want to work on it
will need to install tree-sitter; see the README.md updates). I tried
running it manually, but parser.c is about 600 KB; pre-commit rejects
files that large and I don't think an exception makes sense to override
for this (it'd probably also grow substantially if the grammar were
updated to cover more syntax). In order to make the non-hermetic call
not break "bazel build //..." for most developers, I'm marking most
targets in the package as manual.

Note, I did look long and hard at using `aspect_rules_js`/`rules_nodejs`
to invoke npm. This took a lot of time, and I have a commit that's
mostly working, except I hit a point where it uses `declare_symlink`
which we disallow for compatibility reasons (commit "Lots of work for
figuring out rule_js uses declare_symlink" on the PR). As a consequence,
I think we can't use the primary supported ways to have hermetic npm
calls.

Also, `treesitter` -> `tree_sitter` because it's generally called
`tree-sitter`, two words. We even had a `treesitter/src/tree_sitter`
directory so it's a bit inconsistent.

As far as bugs here, the parser library breaks bazel queries, e.g. the
error:
```
ERROR: Evaluation of query "somepath(//..., @llvm-project//third-party/unittest:gtest)" failed: preloading transitive closure failed: no such package '@@[unknown repo 'platforms' requested from @@tree-sitter-bazel+]//': The repository '@@[unknown repo 'platforms' requested from @@tree-sitter-bazel+]' could not be resolved: No repository visible as '@platforms' from repository '@@tree-sitter-bazel+'
```

I'm just excluding tree_sitter from queries where I can to work around
the error.
2025-01-13 19:04:10 +00:00
8e8d570571 Proposal: Variadics (#2240)
Proposes a set of core features for declaring and implementing generic
variadic
functions.

A "pack expansion" is a syntactic unit beginning with `...`, which is a
kind of
compile-time loop over sequences called "packs". Packs are initialized
and
referred to using "pack bindings", which are marked with the `each`
keyword at
the point of declaration and the point of use.

The syntax and behavior of a pack expansion depends on its context, and
in some
cases by a keyword following the `...`:

- In a tuple literal expression (such as a function call argument list),
`...`
iteratively evaluates its operand expression, and treats the values as
    successive elements of the tuple.
- `...and` and `...or` iteratively evaluate a boolean expression,
combining
the values using `and` and `or`, and ending the loop early if the
underlying
    operator short-circuits.
-   In a statement context, `...` iteratively executes a statement.
- In a tuple literal pattern (such as a function parameter list), `...`
iteratively matches the elements of the scrutinee tuple. In conjunction
with
    pack bindings, this enables functions to take an arbitrary number of
    arguments.

---------

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
2024-12-11 01:58:40 +00:00
Dana Jansens 4cf2c07f7d Explain more on the difference of where constraints (#4551)
This adds language to explain where the types of constraints can or can
not appear (attached-to an impl-as vs in-a type expression). And
describes the impact of using a rewrite vs same-type constraint inside
the body of the affected code, and thus why a rewrite is preferable when
the constraint is of a single facet type.
2024-11-21 18:33:17 +00:00
Jon Ross-Perkins b5368b3078 Change prettier to a direct node use. (#4550)
The prettier pre-commit mirror is no longer supported
(https://github.com/pre-commit/mirrors-prettier). This switches to a
direct call, and updates to 3.3.3. And I'm now specifying types for it
to apply to, rather than letting it ignore unknown files; overall just
trying to separate out which linter sees what.

To comment on formatting changes:

- In most cases, seems to be getting confused by `[]` use in markdown
when it's not part of a link. This looks like a regression, but not one
we're broadly affected by.
- p0107.md - caught an issue with a malformed broken bad link which I've
tried to fix.
- p3720.md - looks like a fix.

Note, prettier has a 4.0.0 alpha release. As best as I could tell, that
only affected the .prettierrc.yaml processing. I changed the glob there
for forwards compatibility.
2024-11-18 23:02:10 +00:00
Jon Ross-Perkins d8ecc72d9d Update pre-commit config (#4549)
Skipping prettier because the relevant repo is archived and not working
well. Issues being fixed are from codespell.
2024-11-18 21:29:30 +00:00
Dana Jansens 825714f06b Use a single = in 'impl as where' to assign an associated constant (#4548)
This was written as `==` but is inconsistent with the rest of the
documentation for assigning associated constants.
2024-11-18 17:22:17 +00:00
Dana Jansens f2479321fc Correct name of ComparableFromDifference in Generics details (#4547)
The name ComparableFromDifferenceFn comes from the next example. In this
example ComparableFromDifference is the name of the class that will be
implictly cast to a Facet matching Comparable.
2024-11-18 17:18:59 +00:00
josh11bandJosh L 4994e13068 Document that extend base must appear early in a class definition (#4401)
Note: some of this is from the principle of information accumulation,
and some is from [proposal
#2760](https://github.com/carbon-language/carbon-lang/blob/trunk/proposals/p2760.md#class-inheritance).

Also: change terminology from "virtual override keywords" to "virtual
modifier keywords", to be consistent with our other modifier keywords.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-10-11 19:51:15 +00:00
josh11bandJosh L b0cde707f8 Rename "partial facet" and to "partial class type" (#4402)
See [2024-10-01 discussion on #typesystem in
Discord](https://discord.com/channels/655572317891461132/708431657849585705/1290774105498325122).

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-10-11 18:25:18 +00:00
josh11bandJosh L db78450c61 Fix singular/plural mismatch in design README (#4326)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-09-19 20:58:57 +00:00
David Blaikie 2971e129ad Add TODO breadcrumb from for design to semantics proposal (#4271) 2024-09-03 19:17:37 +00:00
5d73743971 Add link for coherence appendix to Swift forums (#4241)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2024-08-24 19:44:07 +00:00
Jon Ross-Perkinsandjosh11b 89be57ffc3 Add documentation for entity declaration design work (#4230)
Trying to pull in key elements of #3762, #3763, and #3980 (decl matching
and `extern`, essentially). These aren't specific to any particular
declaration type, but are common to entities, so suggesting a new doc
oriented on that.

There's probably more that could be said here, I'm just focused on
getting the recent formal discussion mirrored into the design.

---------

Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
2024-08-21 22:21:07 +00:00
Jon Ross-PerkinsandChandler Carruth 0a4b0f33e3 Add docs for raw identifier syntax. (#4223)
Feature approved in #3797

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2024-08-19 21:50:13 +00:00
Jon Ross-PerkinsandChandler Carruth d5ac724266 Document the export keyword (#4224)
This was approved in #3938

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2024-08-19 20:51:37 +00:00
Jon Ross-Perkins 56332fcfac Fix a couple fn declarations in generics details (#4214)
I think this is just a typo.
2024-08-13 18:09:59 +00:00
c5b5d36e8b Change operator precedence (#4075)
Update the operator precedence to achieve a few goals:

-   Form operators into groups which behave similarly
- Make the group of operators ("top-level operators") that capture
everything to the right, like `if`...`then`...`else`, behave similarly
to the left, so that rearranging expressions won't change how they
group.
- Add the `where` operator, used to specify constraints on facet types,
to the precedence chart, to define how it interacts with other
operators.
- Make the operator precedence diagram prettier, so that it eventually
can be made into a poster that Carbon programmers can hang on their
walls.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-08-10 00:15:37 +00:00
4132c6a65f Merge the suffix ops into a single box in the operator precedence mermaid diagram (#4067)
The current approach was done to work-around a limitation that we can
only have a single link per box, but is unscalable. Instead have a
single link to a new sections of the document that describes the box,
and has multiple links.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-06-20 21:17:25 +00:00
74d7d49bcf Include function call and subscripting/indexing in the operator list and precedence chart (#4052)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-06-17 22:19:02 +00:00
Richard Smith 6bbbd4ec1f More consistent package syntax (#3927)
Change the syntax for `package` declarations from:

```carbon
[package Foo] [library "bar"] api;
[package Foo] [library "bar"] impl;
```

to

```carbon
[package Foo] [library "bar"];
impl [package Foo] [library "bar"];
```
2024-05-16 00:55:37 +00:00
21fb6f5802 Update broken links (#3786)
Update broken links to aid in following links while perusing the
documentation. Closes #3778

I don't imagine I got every one of these right. Some 404s may be
reported due to permissions.

Using the lychee command in #3778, only the following link is reported
as not found, but it's just a permission issue:

```
[proposals/p1367.md]:
✗ [404] https://github.com/carbon-language/carbon-lang/settings/access | Failed: Network error: Not Found
```

I tried to get it down to as few as possible, partially so that future
link scans won't run into repeat errors.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
2024-03-22 18:42:20 +00:00
Nathan Youngman 10189bbb78 rephrase a few sentences (#3766)
Minor tweaks while reading through the docs to hopefully improve
readability.
2024-03-13 22:03:34 +00:00
cui fliter fea2651e7c chore: fix typos (#3738)
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-04 16:27:31 +00:00
Jon Ross-Perkins 0a117f6e73 Switch example code from Create to Make (#3705)
There's not explicit guidance about this, but there was an [old
discussion](https://discord.com/channels/655572317891461132/963846118964350976/998010464237785189)
that loosely settled on Make for now.
2024-02-21 16:43:52 +00:00
Richard Smith cb849cf165 Integrate description of tuple indexing into member access better. (#3679)
Improve the exposition of the design changes from #3646 to integrate
better into the overall description of member access design.

This fixes the incorrect description of the rules for `->` by instead
relying on the general rule that `->` is rewritten to use `*` and `.`
before any other processing is done, and generally makes
*integer-literal* names be less of a special case.
2024-02-03 08:40:03 +00:00
Richard Smith a1655b6858 Tuples and tuple indexing (#3646)
Add support for extracting elements of a tuple by their numerical index.

Also formally add the well-established basic syntactic and semantic
rules for
tuples, for which we have had leads issues but no proposal, into the
design.
2024-01-31 23:42:11 +00:00
Chandler Carruth 01e12111a8 Auto-update pre-commit repositories and fix. (#3427)
The version of `flake8` was too old to support with Python 3.12 -- there
is new F-string support that caused false positives sadly. The updated
version has fixes for all of these.

This in turn updates codespell which has picked up several new fixes
that actually fire in our code, so also fix everything. While we don't
do more in-depth updates to old proposals, similar to simply fixing
broken links, fixing automatically detected typos seems scalable and
fine.

All edits were automatically generated here.
2023-11-28 17:17:28 +00:00
6c812db05c Clarify name bindings in namespaces. (#3407)
-   Require namespace members be declared in the same name scope as the
    namespace is declared.
-   Allow binding patterns to directly declare names in namespaces.
-   Disallow using different namespaces in the same binding pattern.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-11-22 22:52:08 +00:00
Geoff Romer af9b323aad Rephrase to clarify paren expression terminology (#3417)
Avoids the confusion of saying that an expression that's parenthesized
isn't necessarily a "parenthesized expression".
2023-11-22 22:44:54 +00:00
Jon Ross-PerkinsandChandler Carruth 5943208f75 Change Main//default to an api file (#3403)
When there is no `package` directive, default to `Main//default api`
instead of
`Main//default impl`. This means:

- The extension will be `.carbon`, not `.impl.carbon`.
- There can only be one such file when compiling.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2023-11-16 18:57:45 +00:00
josh11b 09b5ab14d8 Link to Swift undecidable type-system problems (#3394) 2023-11-14 00:15:25 +00:00
josh11bandRichard Smith 88e87b86b9 Updates to generics design details, part 2 (#3253)
Continued from part 1: #3231. Second step updating
`docs/design/generics/details.md`. There remains some work to
incorporate proposal #2200.

- The biggest changes are incorporating much of the text of proposals:
  - #2173
  - #2687
- It incorporates changes from proposals:
  - #989
  - #1178
  - #2138
  - #2200
  - #2360
  - #2964
  - #3162
- It also updates the text to reflect the latest thinking from leads
issues:
  - #996
  - #2153 -- most notably deleting the section on `TypeId`.
- Update to rule for prioritization blocks with mixed type structures
from [discussion on
2023-07-18](https://docs.google.com/document/d/1gnJBTfY81fZYvI_QXjwKk1uQHYBNHGqRLI2BS_cYYNQ/edit?resourcekey=0-ql1Q1WvTcDvhycf8LbA9DQ#heading=h.7jxges9ojgy3)
- Adds reference links to proposals, issues, and discussions relevant to
the text.
- Also tries to use more precise language when talking about
implementations, to avoid confusing `impl` declaration and definitions
with the `impls` operator used in `where` clauses, an issue brought up
in
  - #2495 
  - #2483

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-10-03 00:03:07 +00:00
josh11bandChandler Carruth 58c106010c Updates to design docs to reflect accepted proposals (#3254)
Includes proposals:
- #990
- #2188
- #2138
- #2200
- #2360
- #2760
- #2964
- #3162

Also tries to use more precise language when talking about:
- implementations, to avoid confusing `impl` declaration and definitions
with the `impls` operator used in `where` clauses, an issue brought up
in #2495 and #2483;
- "binding patterns", like `x: i32`, and "bindings" like `x`.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2023-09-23 15:53:07 +00:00
josh11bandRichard Smith a8ca499450 Updates to generics design details, part 1 (#3231)
First step in updating `docs/design/generics/details.md`. It
incorporates changes from proposals: #989 #2138 #2173 #2200 #2360 #2964
#3162 , but there are still more changes from those proposals to be
made.

It also switches away from suggesting static-dispatch witness tables,
and creates an appendix to describe that decision.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-09-19 19:06:47 +00:00
josh11bandRichard Smith 71f2eecec5 Update design overview to reflect submitted proposals (#3180)
Incorporates proposals: #1885, #2138, #2188, #2200, #2360, #2760, #2964,
and #3162.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-09-08 22:04:48 +00:00
josh11b dc394b6d95 Clarify some points in Member Access design (#3177)
Follow-on to #3160. Incorporates decision about template specialization
from #2200.
2023-09-06 22:23:52 +00:00
josh11bandRichard Smith d5d6945f85 Update member_access.md to reflect accepted proposals (#3160)
Most changes are due to proposal #2360, but this also includes changes
to reflect: #1136, #2138, #2006, #2550, and #2964.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-08-31 00:17:00 +00:00
josh11b 9600030a05 Reduce ambiguity in terminology (#3162)
Change terminology away from terms that are ambiguous:

- Reserve "generic type" for types with (compile-time) parameters, like
`Vector` in `Vector(T:! type)`. Don't use that term to refer to `T`, as
it would with
[#2360](https://github.com/carbon-language/carbon-lang/blob/trunk/proposals/p2360.md#terminology).
- Use the term "compile-time" instead of "constant" to mean "template or
symbolic." Expand the term "constant" to include values, such as from
`let` bindings.
2023-08-30 17:13:40 +00:00
Richard Smith 84ea453161 Add semicolon to description of return var; statement. (#3131)
The semicolon is part of the statement's syntax, and including it will
hopefully help clarify that we're not using `var` as a placeholder and
talking about `return` _variablename_ `;`.
2023-08-22 19:11:14 +00:00
josh11bandRichard Smith e15bdbb36c Update generics overview (#3061)
This reflects changes from a number of approved proposals:

- #2138 : "generic" -> "checked generic", "template" -> "template
generic"
- #2360 : "type", "facet type", "facet". Note: I am not using the term
"generic type" from #2360 since that meaning conflicts with the
generally accepted meaning of "generic type" of a type with a
compile-time parameter.
- #2760 / #2770 : internal/external impl -> extending impl
- #2964 : "symbolic constant" and "template constant"

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-08-15 19:58:23 +00:00
Richard Smith 7b22173cba Add precedence rules for assignment operators to the precedence diagram. (#3083)
Also indicate what can appear within parentheses.

This is intended to be a clarification, not a design change. Note that
while we previously described the operand of `++` or `--` as being
simply an expression, the operand can never be anything other than the
kinds of expression the diagram now shows due to the expression category
rules added in #2006.

Fixes #3079.
2023-08-10 22:35:51 +00:00
Chandler Carruth 6d3a4b84cb Mark unary operators as repeating. (#3074)
Currently, they are marked as left-associative which isn't completely
obvious for unary operators and wouldn't match the fact that we have
both prefix and postfix unary operators we intend to allow to repeat
without parentheses: `***x` and `T***`.

This fixes the graph by making the left-associative marker only for
binary operators, and using a separate marker for repeating unary
operators: a diamond.

It also adds a note that Carbon currently only has left-associativity
because the right-associative operators like assignment are statements
in Carbon.

This isn't intended ta be a change of anything in Carbon's design, just
an improvement to the documentation.
2023-08-08 17:57:25 +00:00
0d1e6bd84d Values, variables, pointers, and references (#2006)
Introduce a concrete design for how Carbon values, objects, storage,
variables,
and pointers will work. This includes fleshing out the design for:

- The expression categories used in Carbon to represent values and
objects,
how they interact, and terminology that anchors on their expression
nature.
-   An expression category model for readonly, abstract values that can
    efficiently support function inputs.
- A customization system for value expression representations,
especially as
    seen on function boundaries in the calling convention.
- An expression category model for references instead of a type system
model.
-   How patterns match different expression categories.
-   How initialization works in conjunction with function returns.
- Specific pointer syntax, semantics, and library customization
mechanisms.
- A `const` type qualifier for use when the value expression category
system
    is too abstracted from the underlying objects in storage.

---------

Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
Co-authored-by: Adrien Leravat <Pixep@users.noreply.github.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-08-08 07:27:44 +00:00
josh11b 916bb4022a Update generics goals doc (#3060)
This reflects changes from #2138 , plus a number of other updates,
including reflecting that we have decided to include templates in
Carbon.
2023-08-05 05:39:34 +00:00