Commit Graph
100 Commits
Author SHA1 Message Date
db2e26ba86 Updates to member access (#7697)
Update the rules for member access:
-   Simple member access `a.b`
- If `a` names a scope, performs name lookup and optionally `impl`
lookup.
- Otherwise, `a.b` is shorthand for `a.(typeof(a).b)` and always
performs instance binding.
- Compound member access `a.(m)` does optional `impl` lookup and always
performs instance binding.
- This is a change from only performing instance binding if `m` is an
instance member.
- New operation `a.impl(m)` is introduced. It always performs `impl`
lookup, and nothing else.
- The `BindToType` interface is removed. Only instance binding may be
customized (using the `BindToValue` and `BindToRef` interfaces).

As a result, member access doesn't use whether the right operand is an
instance member anymore. Instead, instance binding is performed whenever
it would be plausible, and a new syntax is used to opt out.

Assisted-by: Gemini via Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2026-09-15 00:03:41 +00:00
josh11bandJosh L fe14c83731 Use jj_prek.sh to run prek in new_proposal.py with jj (#7699)
Recently noticed this issue when creating a proposal using
`new_proposal.py` in a `jj` workspace.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-09-02 00:22:38 +00:00
josh11bandJosh L 4e77f9b6c8 Add slide and video links for NDC 2026 talks (#7572)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-07-27 22:50:58 +00:00
josh11bandJosh L 1cef214e6a Move adapters from generics to class design docs (#7561)
Assisted-by: Gemini via Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-07-27 22:33:37 +00:00
josh11bandJosh L a48d14e451 Add memory safety talk links to README (#7520)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-07-21 21:43:44 +00:00
73744544fc Merge functions.md and lambdas.md design documents (#7425)
Implements suggestion from
https://github.com/carbon-language/carbon-lang/pull/7355#discussion_r3416055969
.

Assisted-by: Gemini via Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
2026-06-29 18:24:16 +00:00
2ec915eab6 Update functions design doc (#7355)
Incorporates changes from these proposals:

- #2022 
- #2875 
- #3262 
- #3763 
- #3848 
- #5434 

A small amount of updating was done to lambdas.md and variadics.md to
harmonize with these changes.

Assisted-by: Gemini via Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
2026-06-18 22:58:51 +00:00
josh11bandJosh L cbd79529b2 Update design docs to reflect proposal #1885: for statement and user types (#7350)
Assisted-by: Gemini via Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-06-18 20:55:07 +00:00
josh11bandJosh L a7f8df0383 Update svg code snippets to reflect changes from #7354 (#7370)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-06-17 15:13:23 +00:00
josh11bandJosh L 988c47631e Update design docs to reflect #6177: C++ Interop: Mapping std::string_view to Core.Str (#7349)
Assisted-by: Gemini via Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-06-15 22:19:45 +00:00
ed51ba4b1a Update design docs to reflect proposal #4682: The Core.Array type... (#7354)
Also:

- Introduce `buf` so that existing examples using arrays can be updated
to use it.
- Update the examples linked to on the Carbon front page to something
closer to what we expect, moving away from old array syntax. Uses
`slice` though that name hasn't been settled. Updating the SVGs actually
referenced will need to be done as a separate step.
- Update links to the expression operators while I'm touching that
section.

Assisted-by: Gemini via Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Nicholas Bishop <nbishop@nbishop.net>
2026-06-15 17:36:06 +00:00
d173121dc6 Name lookup design doc update (#7317)
Assisted-by: Gemini via Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Dana Jansens <danakj@orodu.net>
2026-06-09 16:50:18 +00:00
josh11bandJosh L efb78c593c Update design for proposal #6395: Type completeness in extend (#7315)
Assisted-by: Gemini via Antigravity

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-06-08 21:27:48 +00:00
341069fdcf Add design doc for proposal #6676: Importing C/C++ object-like macros (#7291)
Assisted-by: Gemini via Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
2026-06-04 20:07:42 +00:00
josh11bandJosh L 358df53c48 Add design doc for proposal #6668: C++ interop type mapping for integer and floating-point literals (#7295)
Assisted-by: Gemini via Antigravity

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-06-03 14:22:17 +00:00
d01e1d2d06 Update design docs for proposal #6710: char redesign (#7281)
Note that #7266 has already updated the toolchain for `char`, but not
`Core.CharLiteral`.

Assisted-by: Gemini via Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
2026-06-01 19:34:35 +00:00
josh11bandJosh L 832d46f01b Update LLVM (#7221)
Assisted-by: Google Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-05-18 17:06:58 +00:00
josh11bandJosh L 4f2b3b644c Support jj workspaces in suggested jj abandon-untagged alias (#7222)
`@` refers to the current workspace's working copy, but if we want the
command to respect the working copies of other workspaces, we should use
`working_copies()` instead; see
https://docs.jj-vcs.dev/latest/revsets/#functions .

Also remove `all() &` while here, since it is always redundant.

Assisted-by: Google Antigravity

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-05-17 23:03:22 +00:00
f0aa561bd6 Support jj workspaces (#7219)
In particular, bazel builds would previously fail in
`workspace_status.py` if you didn't have a `.git` with this error:

> ```
> ERROR: <builtin>: BazelWorkspaceStatusAction stable-status.txt failed:
Failed to determine workspace status: Process exited with status 1
> fatal: not a git repository (or any of the parent directories): .git
> ```

Assisted-by: Google Antigravity

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2026-05-17 03:38:31 +00:00
9fb0e4a7ae Add sufficiency of declaration to the information accumulation principle (#7179)
Adding to the information accumulation principle instead of creating new
principle #5990.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2026-05-08 22:38:34 +00:00
josh11bandJosh L c837c004bc Fix comment to match case of parameter name (#6839)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-03-05 21:20:44 +00:00
josh11bandJosh L 77caf3b9d8 Add Core.PrintStr and a "hello world" example (#6493)
Thanks to @ammaralassal for #6329 which did the heavy lifting to make
this possible!

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-12-12 20:07:05 +00:00
josh11bandJosh L c329bce240 PrintChar from "io" library takes a char (#6264)
As [observed in
#toolchain](https://discord.com/channels/655572317891461132/655578254970716160/1428791603786416351),
this makes demo code nicer.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-10-23 16:38:20 +00:00
ac98870e67 ref parameters, arguments, returns and val returns (#5434)
- A parameter binding can be marked `ref` instead of `var` or the
default. It will bind to reference argument expressions in the caller
and produces a reference expression in the callee.
- Unlike pointers, a `ref` binding can't be rebound to a different
object.
- This replaces `addr`, and is not restricted to the `self` parameter.
- A `ref` binding, like a value binding, can't be used in fields of
classes or structs.
- When calling functions, arguments to non-`self` `ref` parameters are
also marked with `ref`.
- The return of a function can optionally be marked `ref`, `val`, or
`var`. These control the category of the call expression invoking the
function, and how the return expression is returned.
- These may be mixed for functions returning tuple or struct forms.
-   The address of a `ref` binding is `nocapture` and `noalias`.
- We mark parameters of a function that may be referenced by the return
value with `bound`.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2025-08-01 17:43:41 +00:00
josh11bandJosh L 09ca0b8308 Update LLVM (#5605)
Some updates required for
https://github.com/llvm/llvm-project/pull/139584.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-06-04 00:43:40 +00:00
df36a555e8 Interface extension and final impl update (#5337)
We make 5 changes:

- Allow `require Self impls I` in an `interface` or `constraint` scope
to omit the `Self`, so it can be written `require impls I`.
- Rename `extend I` to `extend require impls I` in an `interface` or
`constraint` scope.
- Define `extend impl as I` and `extend final impl as I` in an
`interface` scope to copy the members of `I` and define an `impl` of `I`
in terms of the extending interface.
- Allow a non-final `impl` to overlap a final `impl` as long as it isn't
subsumed by the final `impl`. The final `impl` will be given priority on
the overlap.
- Allow `final` on a `match_first` block, used to declare overlapping
final impls.

These features work together to allow a form of interface extension
where:

- Types only need to `impl` the extending interface to also get an
`impl` of the extended interface.
-   Multiple interfaces can extend the same interface.
-   An interface can extend multiple interfaces.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Dana Jansens <danakj@orodu.net>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2025-05-20 20:03:56 +00:00
josh11bandJosh L 1769062c1c Clean up bazel config comment change made in #5459 (#5470)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-05-13 17:55:33 +00:00
8c4ff33cb1 The name of an impl in class scope (#5366)
```
class C {
  impl as I;
}
```

is redeclared

```
impl C.(as I)
```

for purposes of `match_first`/`impl_priority` blocks and definitions.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2025-05-07 17:30:51 +00:00
josh11bandJosh L c455dbef54 Clean up KeywordModifierSet after #5345 (#5425)
See comment
https://github.com/carbon-language/carbon-lang/pull/5345#discussion_r2074260967

> `Impl` is already a part of `Method` and refers to using `impl` as a
modifier keyword on virtual methods (to be replaced by `override`, see
#5253 ), as opposed to `ImplDecl` which is the modifiers allowed on an
`impl` declaration. It would make more sense to delete this than use
`Impl` here.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-05-06 16:56:06 +00:00
ed863d6eae Forward impl declaration of an incomplete interface (#5168)
Revise rules for what is required and provided by declarations and
definitions of interfaces and impls. In particular:

-   allow `impl` declarations of incomplete interfaces, and
- shift from a "use the information from the type definition if it
happens to be complete" model to a "only use the information from the
definition in contexts where it is required to be defined or complete"
model.

Resolves questions-for-leads issues
[#4566](https://github.com/carbon-language/carbon-lang/issues/4566),
[#4672](https://github.com/carbon-language/carbon-lang/issues/4672),
[#4579](https://github.com/carbon-language/carbon-lang/issues/4579).

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
2025-05-03 19:42:33 +00:00
josh11bandJosh L e52b51e66a Forbid virtual methods with compile-time parameters in the design (#5365)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-04-26 03:30:25 +00:00
josh11bandJosh L 367c210871 Test clean up follow up to #5320 (#5344)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-04-23 20:03:36 +00:00
josh11bandJosh L b477797239 Clarify generic design about the type before as (#5341)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-04-22 00:04:48 +00:00
josh11bandJosh L 034e374f0a Add TODOs re: pattern_block_id to inst_namer.cpp (#5331)
From
https://github.com/carbon-language/carbon-lang/pull/5310#discussion_r2045291737

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-04-18 00:58:31 +00:00
josh11bandJosh L dfd5fe368d Fix comment typo in toolchain/sem_ir/inst_kind.h (#5330)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-04-17 22:54:13 +00:00
josh11bandJosh L ecb99e55e7 definitions_required -> definitions_required_by_decl in toolchain/check/check_unit.cpp (#5329)
Updates message to reflect changes in #5090 .

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-04-17 22:48:37 +00:00
4af0c8f8d1 Implement ...where .Self impls... (#5238)
* Also remove facet type deduction, since we decided against it on
[2025-04-02](https://docs.google.com/document/d/1Iut5f2TQBrtBNIduF4vJYOKfw7MbS8xH_J01_Q4e6Rk/edit?pli=1&resourcekey=0-mc_vh5UzrzXfU4kO-3tOjA&tab=t.0#heading=h.95phmuvxog9n).

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-04-07 20:45:45 +00:00
e9c90af92e Reduce redundant diagnostics (#5234)
* "extending non-facet-type constraint" is already diagnosed by
`ImplAsNonFacetType`
* `impl` declarations with errors in the facet type no longer require
definitions

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-04-02 16:36:14 +00:00
bc439ad092 Forward impl declarations of incomplete facet types (#5219)
Implements some of the changes from proposal #5168.

* The data structure for complete facet types has been repurposed for
identified facet types. Identified facet types are now a concept in the
toolchain, but without named constraint support they are not
substantially different from incomplete facet types.
* Identified facet types keep the list of required specific interfaces
in sorted order, for efficiency improvements in impl lookup. Found
another way to identify the interface to impl (or number of impls if not
1).
* Forward `impl` declarations of identified but incomplete facet types
are allowed unless the facet type has rewrites. An incomplete facet type
with rewrites is already either an error or has more than one interface
and so can't be implemented, so this case can't be exercised very well
yet.
* Forward `impl` declarations of interface without rewrites use a
placeholder inst block for the witness.
* Changed some machinery to use RequireIdentifiedFacetType to access the
interfaces of the facet type so we only need to add support for
expanding named constraints into interfaces in one place.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-04-02 01:46:27 +00:00
josh11bandJosh L df958940c3 Builtin facet type conversion is final (#5220)
Don't look for a user-defined conversion (implementation of `As` or
`ImplicitAs`) if the builtin conversion to a facet type fails impl
lookup. This is the behavior we want, and reduces noise in diagnostics.

Partial implementation of #5122. Still to do:
* Give an error if the users tries to implement such a conversion, since
it is now unreachable.
* Add notes to the diagnostic explaining why impl lookup failed.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-31 16:11:07 +00:00
0ebe031dac More Dump() output for constants, generics, specifics (#5222)
Example output:

Symbolic `constant_id`:

```
(std::string) $2 = "symbolic_constant36: {inst: inst74, generic: generic3, index: generic_inst_in_decl2, kind: checked}
inst74: {kind: FacetType, arg0: facet_type3, type: type(TypeType)}
  - type: type(TypeType): type; {kind: TypeType, type: type(TypeType)}
  - value: symbolic_constant26
generic3: {decl: inst75, bindings: inst_block41}
inst75: {kind: ImplDecl, arg0: impl0, arg1: inst_block39}
  - value: concrete_constant(inst75)"
```

`generic_id`:

```
(std::string) $3 = "generic3: {decl: inst75, bindings: inst_block41}
inst75: {kind: ImplDecl, arg0: impl0, arg1: inst_block39}
  - value: concrete_constant(inst75)
inst_block41:
  - inst60: {kind: BindSymbolicName, arg0: entity_name4, arg1: inst<none>, type: type(TypeType)}
generic decl block: inst_block46:
  - inst85: {kind: BindSymbolicName, arg0: entity_name4, arg1: inst<none>, type: type(TypeType)}
  - inst86: {kind: ClassType, arg0: class0, arg1: specific7, type: type(TypeType)}
  - inst87: {kind: FacetType, arg0: facet_type4, type: type(TypeType)}
  - inst88: {kind: RequireCompleteType, arg0: type(symbolic_constant36), type: type(inst(WitnessType))}
  - inst89: {kind: ImplWitness, arg0: inst_block42, arg1: specific9, type: type(inst(WitnessType))}"
```

`specific_id`:

```
(std::string) $1 = "specific8: {generic: generic0, args: inst_block67}
inst_block67:
  - inst255: {kind: BindSymbolicName, arg0: entity_name67, arg1: inst<none>, type: type(inst(IntLiteralType))}
generic0: {decl: inst51, bindings: inst_block7}
inst51: {kind: ClassDecl, arg0: class0, arg1: inst_block_empty, type: type(inst52)}
  - type: type(inst52): <type of Int>; {kind: GenericClassType, arg0: class0, arg1: specific<none>, type: type(TypeType)}
  - value: concrete_constant(inst54): {kind: StructValue, arg0: inst_block_empty, type: type(inst52)}
specific decl block: inst_block68:
  - inst255: {kind: BindSymbolicName, arg0: entity_name67, arg1: inst<none>, type: type(inst(IntLiteralType))}
  - inst255: {kind: BindSymbolicName, arg0: entity_name67, arg1: inst<none>, type: type(inst(IntLiteralType))}"
```

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-03-31 15:58:32 +00:00
josh11bandJosh L 384be1dbe3 Change conversion diagnostic from saying "value" to "expression" (#5221)
Avoids TODO to make the message change based on the expression category.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-31 15:45:58 +00:00
josh11bandJosh L c7a338be59 Replace uses of "defined" with "complete" (#5196)
As of #5087, these terms are no longer synonyms. This change preserves
the original meaning.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-27 18:14:26 +00:00
josh11bandJosh L a7d9ac576c Narrowing facet type conversion tests (#5172)
Merges in the "subtyping" tests from the `impl/lookup` directory along
with some new tests into
`convert_facet_value_to_narrowed_facet_type.carbon` in the `facet`
directory.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-25 00:11:00 +00:00
josh11bandJosh L a62a8cfd84 Add test with example from 2025-03-19 discussion (#5157)
This example motivated a decision to add a feature where we do impl
lookup to see if there is a matching `final` impl even in some cases
where it is already established that the type implements the interface.
I don't know when we plan on implementing this, but I wanted to capture
the example as test so we would have a TODO to address it.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-20 17:17:27 +00:00
josh11bandJosh L d431e1fbf4 Never perform instance binding with implicit Self in an interface (#5121)
Resolves TODO by creating new function `GetAssociatedValue` with the
logic from `PerformCompoundMemberAccess` restricted to the
non-instance-binding case.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-20 04:25:35 +00:00
josh11bandJosh L fb3721df9a Impl lookup allowed for incomplete facet types (#5132)
New planned direction is to not require completeness. Updated comments
to reflect that some care will be needed once named constraints are
supported. Long term plan is [discussed in
#5089](https://github.com/carbon-language/carbon-lang/pull/5089#discussion_r1985908453):

> We have some options. In our last conversation, it sounded like it
would be beneficial for named constraints to have their own witnesses,
with entries in declaration order. This would allow accesses to the
named constraint while it was being defined. So there would be something
of a hierarchy in a facet type witness, with a named constraint taking a
single slot in a facet type witness, independent of its definition.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-15 02:21:49 +00:00
josh11bandJosh L 5966fbc758 Get impl witnesses from facets cast to type (#5115)
Addresses a TODO in `impl_lookup.cpp`.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-12 20:55:07 +00:00
josh11bandJosh L ebaf62efb9 Associated constants can be used in member function signatures (#5089)
This required allowing incomplete facet types where previously
completeness was required. Once we support named constraints, we will
need a way to consistently go from an interface to a facet type witness
index without requiring the interface to be complete in these cases.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-12 00:33:46 +00:00
josh11bandJosh L 176f9f1cc4 Improve debug Dump for NameScopeIds (#5088)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-10 15:38:56 +00:00
josh11bandJosh L b3be298f7f Fix test that used i32 in a no_prelude directory (#5086)
Exclude SemIR since the point of the test is that it diagnoses something
invalid, not that any particular SemIR is produced.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-08 06:18:18 +00:00
josh11bandJosh L 820ace95e8 Update LLVM (#5082)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-07 19:34:31 +00:00
josh11bandJosh L aa90ab3862 Fix non-instance compound member access (#5059)
Implements the rule:

> For compound member access `a.(b)` where `b` names a _non-instance_
member of an interface `I`:
> * `a` is implicitly converted to `I`
> * let `T` be the result of symbolically evaluating the converted
expression
> * `impl` lookup is performed for `T as I`.
>
> Instance binding is never performed.

See
https://docs.carbon-lang.dev/docs/design/expressions/member_access.html#impl-lookup-for-compound-member-access.
Before this PR, non-instance members were treated as instance members.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-07 01:37:07 +00:00
josh11bandJosh L 331f55f0a2 Handle impl with bad interface on import (#5051)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-06 18:02:29 +00:00
ea1a0c8b84 Find impl witnesses in facets (#5060)
Impl lookup for an interface `I` for a facet with facet type requiring
an interface `I` will now succeed, getting the witness from the facet.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-03-06 17:58:53 +00:00
josh11bandJosh L c2281d1250 Update tests for upcoming #5059 and #5060 on member access and finding impl witnesses in facets (#5054)
Here are some test changes so the diffs that come from my upcoming
functionality changes are easier to see. Upcoming functionality
includes:
* Compound member access with non-instance associated constants will
change to comply with the design
https://docs.carbon-lang.dev/docs/design/expressions/member_access.html#impl-lookup-for-compound-member-access
in #5059 .
* Impl lookup will add support for finding impl witnesses in facets
#5060

I'm also making the toolchain/check/testdata/impl/compound.carbon test
into a no_prelude version, and adding a version that tests with
importing.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-04 17:59:30 +00:00
josh11bandJosh L 4fd273a928 2 small simplifications in member access (#5055)
* `IsInstanceMethod` can look in the function's `self_param_id` instead
of iterating through all of the implicit parameter patterns.
* An associated entity is always associated with a single interface, so
we don't need to handle the case when it isn't.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-03 23:11:38 +00:00
josh11bandJosh L 900052fcf1 Clarify conversion diagnostic (#5052)
TODO to resolve whether it should conditionally say "object of"
depending on the category

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-03-03 22:09:48 +00:00
josh11bandJosh L 29c1f552c7 InvalidIndex -> NoneIndex in comments (#5012)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-02-25 18:22:03 +00:00
3ebd098597 Completing a type no longer ignores facet types (#5004)
Make facet types complete like other types. This means that in the body
of an interface, the type of `Self` is incomplete. This involved fixing
an issue where eval of a specific_id that was already canonical was not
resolving the specific declaration, which could occur as part of
substituting into a facet type.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-02-22 21:40:43 +00:00
fc7b0016ce Tuples and structs with abstract types are abstract (#4986)
Expands the CompleteTypeInfo to include information about abstract
classes and computes that information as part of completing the type.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-02-20 22:26:10 +00:00
josh11bandJosh L cb2257e678 Should-fail tests using abstract tuples and structs (#4985)
Currently the toolchain does not recognize that tuples and structs with
abstract elements should be considered abstract.

Also make the existing `fail_abstract` test into a `no_prelude` test.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-02-20 16:56:41 +00:00
eb69d7420e First iteration of completing and resolving facet types (#4920)
* Add `RequireCompleteFacetType` and `ResolveFacetTypeImplWitness` to
`check::Context`. Goal was to move code from `impl.cpp` (mostly) without
functional changes.
* Complete type information is cached with the facet type, and is stored
in a `complete_facet_types()` table.
* Main functional change is to diagnose attempts to use a rewrite
constraint on an associated function. Some existing diagnostics have
been updated.
* Remove `check::Context::RequireDefinedType`:
  * For class types, use `RequireCompleteType`
  * For facet types, use `RequireCompleteFacetType`
* Introduce a `SemIR::SpecificInterface` to hold an interface and
specific id pair.
* Keep the specific interface ids in the impl object.
* Avoid some extra copies in `Dump` functions.
* Future work missing from this PR:
  * Resolving for member access or actions that require impl lookup.
  * Resolving rewrites constraints that refer to non-concrete values.
* Any support for adding implied constraints that result from a `where`
clause (though TODOs have been added).

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-02-19 22:10:11 +00:00
josh11bandJosh L 50b3c825e4 Handle extend impl in function body (#4924)
Crash bug found by fuzzer.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-02-11 21:19:55 +00:00
5abe5a3c21 Stop allowing impl redeclarations to differ syntactically in where clause (#4850)
Based on [the lastest thinking on
#4672](https://github.com/carbon-language/carbon-lang/issues/4672#issuecomment-2606209281)
, require a full syntactic match for impl redeclaration, instead of
excluding the `where` restriction. This means no updates to the impl
witness on redeclaration, and no diagnostics that those updates are
consistent.

Not included in this PR, but will need to be done in the future:
* Support for assigning values to associated constants in the body of
the impl definition. This will require moving the checking that
non-function associated constants are set from the definition start to
definition end.
* Identify semantic redeclarations that are not syntactic matches to
give a failed redeclaration diagnostic. This should be done once we are
already identifying impl declarations with the same type structure in
order to require they be identified in an impl_priority/match_first
block.
* Merging of the functions in `check/impl.cpp` that are now always
called together.

Also add some test coverage of `where` parsing I developed in PR I've
now abandoned because of this new simplification of the impl
redeclaration semantics.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-01-28 06:00:34 +00:00
josh11bandJosh L 3a44b65b95 Support importing associated constant declarations (#4794)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-01-13 19:20:28 +00:00
230a8ee598 Support associated constants in impl witnesses (#4770)
With this change, we now support impl of interfaces with non-function
associated constants.

Also:
* Make impl diagnostics use more consistent names
* Make some impl tests "no_prelude"

Still to do:
* Facet type resolution as a separate, reusable step
* Using the assigned values of associated constants (see
`fail_todo_use_assoc_const.carbon`)

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2025-01-11 01:59:06 +00:00
josh11bandJosh L 1d379ff7f8 Syntactic impl declaration matching updates (#4762)
* Implement ignoring the difference between `Self as` and `as`, as well
as `where` clauses at the end of an `impl` declaration when checking
whether `impl` declarations match, from #3763.
* Allow impl declarations with different constraint ids to match, as
long as the facet type of the constraint has the same interface_id and
specific_id.
* Add some TODOs reflecting future facet type resolution.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-01-07 23:31:31 +00:00
josh11bandJosh L fa9a07b6cc Add Make...Id functions for debugging (#4759)
In practice, I am unable to call constructors like `SemIR::InstId` from
a debugger. I first tried to use
https://clang.llvm.org/docs/AttributeReference.html#noinline to make
some non-inline calls to the constructor, but that didn't work:

```
toolchain/sem_ir/dump.cpp:245:23: error: 'noinline' attribute is ignored because there exists no call expression inside the statement [-Werror,-Wignored-attributes]
  245 |   [[clang::noinline]] return InstId(inst);
      |          
```

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-01-07 01:10:21 +00:00
josh11bandJosh L 7edb0b8f59 Add more Dump methods for debugging (#4747)
Follow-on to #4669 . Did some manual testing, but may have not exercised
all code paths.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2025-01-06 17:26:28 +00:00
725e80f0d3 Fix a bug importing declarations in generics (#4752)
Imported declarations that are contained within a generic, such as an
`impl forall...` would be given an abstract symbolic constant value
instead of a concrete generic value in some cases where the function was
used in an api file and impl file of the same library. This caused #4679
to fail using `ImplicitAs.Convert` transitively imported from the
prelude.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2025-01-02 23:56:43 +00:00
c5fd8f42b8 ImplWitness (#4679)
* Change `InterfaceWitness` -> `ImplWitness`
* Include a `SpecificId` in the `ImplWitness`. This allows the
`InstBlock` it contains to have its own identity, allowing it to be
changed as the impl is processed. Evaluation only updates the specific.
* Create the `ImplWitness` at the start of the impl definition. In the
future, this will be populated with the values of non-function
associated constants. For now, it starts full of invalid instruction
ids.
* Implements the model suggested in #4672 .

Note that the non-SemIR testdata changes are to these file:
* `toolchain/check/testdata/impl/lookup/fail_todo_undefined_impl.carbon`
* `toolchain/check/testdata/struct/import.carbon`
* `toolchain/check/testdata/tuple/import.carbon`

The last two are due to an import of generics bug exposed by this PR,
which will be fixed in a follow-on.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2025-01-02 23:03:11 +00:00
josh11bandJosh L 89df77707b Drop references to deleted explorer fuzzer (#4745)
Follow up to delete that happened in #4731 .

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-12-28 02:09:40 +00:00
josh11bandJosh L 1a5107efa4 Clarify the logic for invalid impl redeclarations (#4738)
Follow up to #4179, specifically re:
https://github.com/carbon-language/carbon-lang/pull/4719#discussion_r1894364691
.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-12-23 23:05:12 +00:00
josh11bandJosh L 01ca9f05dd has_definition_started accessor for entities (#4730)
Note that I left some calls to `is_defined()` where I thought they were
interchangeable.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-12-20 22:29:50 +00:00
josh11bandJosh L 5169a1862e Require a definition in the same file as an impl declaration (#4719)
This PR detects the failures that #4709 fixes.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-12-20 17:00:53 +00:00
josh11bandJosh L 661ba36119 Remove stale comment (#4727)
Comment became out of date with #4698 . Seems better to delete instead
of update this comment.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-12-20 16:58:39 +00:00
josh11bandJosh L c130fe8d51 Fix VSCode language extension configuration instructions (#4725)
The instructions did not match the example. The VSCode settings suggests
the example is the correct one.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-12-20 07:16:35 +00:00
josh11bandJosh L 85ea848879 Fix syntactic match of impl decl to definition (#4709)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-12-20 00:31:38 +00:00
6b3307c520 Support StructValue in StringifyTypeExpr (#4696)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-12-17 19:19:52 +00:00
josh11bandJosh L b25117b508 Do not resolve the declaration when forming a specific for use in an eval block (#4692)
When substituting into a generic in order to form a generic eval block,
we form `SpecificId`s to track the list of arguments that should
eventually be used to form a specific referenced by the eval block.
Values within that specific are not needed and won't ever be used, so
it's safe to skip forming them in the first place.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-12-17 00:39:48 +00:00
josh11bandJosh L bd0f620583 Add more tests of indexing a tuple with a non-literal (#4650)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-12-06 23:22:21 +00:00
josh11bandJosh L 6260f0fecf Fix bug introduced in #4613 (#4624)
Issue was not properly handling `ImportRef` instructions in
`AddAssociatedEntities` in `check/import_ref.cpp`. Using `CARBON_CHECK`
instead of `CARBON_FATAL` was hiding the error.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-12-04 21:16:54 +00:00
33110d096c Facet types support rewrite (where .A =...) constraints (#4613)
* Rewrite constraints are stored in a facet type, substituted, imported,
and formatted.
* We now distinguish `.Self` from other symbolic bindings in two ways:
* `.Self` itself now has an invalid compile time binding index (since it
doesn't bind to any of the generic parameters). As a result, we no
longer need to create a generic region in `handle_where.cpp`.
* There is a new phase tracking values that are only symbolic because
they transitively depend on `.Self`. This allows us to give the result
of a `where` expression template phase as long as it doesn't use any
symbolic constants other than `.Self` or other designators.
* `AddConstant` has been removed from `check/context` since it was only
used from `eval`. This meant less plumbing of the phase change.
* Evaluation of `BindSymbolicName` now also performs substitution into
its type.
* Include a bit more information in some diagnostics.
* `StringifyTypeExpr` outputs rewrites, which required adding support
for associated entities as well.
  * Associated entities now have an entity name set when importing.
* Adds tests for some interesting cases with rewrites and uses of
`.Self` mixed with other symbolic constants.

Still to do:
* There is no validation that any particular type satisfies rewrite
constraints.
  * Access to members of a facet type do not see the rewritten values.
* Impls don't recognize whether associated constants have rewrites
setting their values.
  * No support for resolving facet types.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-12-03 22:44:39 +00:00
josh11bandJosh L 5d1b39e1f2 More instructions get named (#4615)
Goal is to reduce churn in names in test updates (by churning a lot of
them in this PR).

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-12-03 20:47:53 +00:00
josh11bandJosh L b894d4e62c Refactor StringifyTypeExpr (#4597)
* Make the step stack into a class
* Make the operations on the stack (pushing, popping, test for done)
into methods on the stack class.
* Add more kinds of steps (array bound and name).
* Rewrite cases to use the new kinds of steps. Afterward, none use
`Step::Next()` or the step index, so those get removed.
* Add another convenience method `PushTypeId`.
* Remove the `SemIR::File&` member from the steps, since it doesn't
change.

Hopefully using `step_stack.Push`... calls makes it clear that they are
resolved in the reverse order they are executed.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-27 02:20:31 +00:00
4d3b962029 Symbolic aggregate access (#4590)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-11-26 19:33:44 +00:00
4ba6a6efc1 Link to video for 2024 CppNorth talk (#4578)
* Change format:
  * previously there was a single link per talk, the video if available
  * now there are separate "video" and "slide" links
* Adds link to video for 2024 CppNorth talk
* Adds link to slides for 2024 LLVM Developers' Meeting
* Restores links to slides from past years

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2024-11-26 02:03:54 +00:00
josh11bandJosh L 01ea408d75 Simplify logic in StringifyTypeExpr using push_string (#4561)
Follow-on to #4511.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-26 01:59:55 +00:00
josh11bandJosh L ed80cd2f15 Facet member access (#4371)
Adds `FacetAccessWitness` instruction and uses it in `member_access.cpp`
to support accessing members of facets. Still to do: interface witness
access is producing runtime values when it should produce symbolic
values.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-26 01:12:46 +00:00
josh11bandJosh L 0b209c3fbc Make facet type deduction more restrictive and correct (#4589)
Previously it would allow interface mismatches. We only need to support
the case where there is a single interface, though, which makes checking
much more straightforward.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-25 23:50:56 +00:00
josh11bandJosh L d5e022d53c Mark instructions that can be deduced through in typed_insts.h (#4588)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-25 23:50:41 +00:00
josh11bandJosh L e42b377cf6 Fix comment in test (#4569)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-22 00:48:50 +00:00
67f2c9ce26 Add a FacetValue instruction (#4545)
The new `FacetValue` instruction represents `C as I` for some type `C`
and facet type `I`. It is named `FacetValue` instead of just `Facet` to
parallel the `FacetType` instruction.

This PR uses this instruction represent the facet value `Self` in an
`impl` declaration. This instruction will be used in the future to also
support things like:

* `C as I` where `C` is a class; and
* forming a specific for a generic with a `T:! I` parameter where `T` is
being given a concrete value.

(Here `I` is an interface or other non-`type` facet type.)

Also do some renaming and add some comments to make things a bit more
clear.

* `FacetTypeAccess` -> `FacetAccessType` to clarify this is not access
of a facet type, but access of the type of a facet
* `.facet_id` -> `.facet_value_inst_id` to parallel the `FacetValue`
instruction

`FacetAccessWitness` will be in a future PR.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-11-21 22:29:53 +00:00
josh11bandJosh L 47bfa375af Propagate llvm::vfs::FileSystem from driver_env to Clang (#4537)
As discussed in #4530 . This required switching to using
`llvm::IntrusiveRefCntPtr` in a number of places.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-18 18:24:19 +00:00
josh11bandJosh L 93169c30b1 Update LLVM (#4530)
Includes updates to reflect these LLVM changes:
* https://github.com/llvm/llvm-project/pull/112517
* https://github.com/llvm/llvm-project/pull/113331

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-15 00:09:10 +00:00
josh11bandJosh L abd12c18c7 Support extended scopes that are parameterized types (#4524)
* The `extended_scopes` in a `NameScope` were represented by a
`NameScopeId`. Replace that with an `InstId` of an instruction returning
the type that is extending this name scope.
* `Context::LookupQualifiedName` now can take multiple scopes to look
in.
* `GetAsLookupScope` was moved out of `member_access.cpp` and is now
`Context::AppendLookupScopesForConstant`

This PR also fixes some existing issues that were revealed as part of
writing and testing this PR:
* Additional validation and handling of invalid ids.
* `extend impl` in a class is not properly imported yet, but at least
now it doesn't crash.

The change to use an `InstId` also allowed some diagnostics and
formatting to be improved.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-13 23:48:02 +00:00
josh11bandJosh L 39ed62dad7 Add facet_types() accessor to Check::Context (#4518)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-13 01:20:07 +00:00
josh11bandJosh L 3824c5fd30 Look in libraries associated with the interface (#4510)
This was broken by #4499 .

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-12 20:35:32 +00:00
josh11bandJosh L ada9564077 Add missing #include (#4513)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-11-12 16:53:41 +00:00