Skip to content

Commit 2b8fdf3

Browse files
authored
Switch the prelude to use ref instead of addr (#6359)
1 parent 55e5675 commit 2b8fdf3

File tree

199 files changed

+1757
-2576
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+1757
-2576
lines changed

core/prelude/destroy.carbon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ package Core library "prelude/destroy";
1313
// it does not deallocate memory.
1414
interface Destroy {
1515
// TODO: This should be `final fn Op[ref self: Self]() = "type.destroy"`.
16-
fn Op[addr self: Self*]();
16+
fn Op[ref self: Self]();
1717
}
1818

1919
// Returns a constraint that matches all types that should have a `Destroy` impl.
2020
private fn CanDestroy() -> type = "type.can_destroy";
2121

2222
// Destroys an instance of `DestroyT`. This is also used for trivial types.
2323
final impl forall [DestroyT:! CanDestroy()] DestroyT as Destroy {
24-
fn Op[addr self: Self*]() = "type.destroy";
24+
fn Op[ref self: Self]() = "type.destroy";
2525
}

core/prelude/operators/arithmetic.carbon

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ interface AddWith(Other:! type) {
2626

2727
// Addition with assignment: `a += b`.
2828
interface AddAssignWith(Other:! type) {
29-
fn Op[addr self: Self*](other: Other);
29+
fn Op[ref self: Self](other: Other);
3030
}
3131

3232
// Increment: `++a`.
3333
interface Inc {
34-
fn Op[addr self: Self*]();
34+
fn Op[ref self: Self]();
3535
}
3636

3737
// Negation: `-a`.
@@ -48,12 +48,12 @@ interface SubWith(Other:! type) {
4848

4949
// Subtraction with assignment: `a -= b`.
5050
interface SubAssignWith(Other:! type) {
51-
fn Op[addr self: Self*](other: Other);
51+
fn Op[ref self: Self](other: Other);
5252
}
5353

5454
// Decrement: `--a`.
5555
interface Dec {
56-
fn Op[addr self: Self*]();
56+
fn Op[ref self: Self]();
5757
}
5858

5959
// Multiplication: `a * b`.
@@ -64,7 +64,7 @@ interface MulWith(Other:! type) {
6464

6565
// Multiplication with assignment: `a *= b`.
6666
interface MulAssignWith(Other:! type) {
67-
fn Op[addr self: Self*](other: Other);
67+
fn Op[ref self: Self](other: Other);
6868
}
6969

7070
// Division: `a / b`.
@@ -75,7 +75,7 @@ interface DivWith(Other:! type) {
7575

7676
// Division with assignment: `a /= b`.
7777
interface DivAssignWith(Other:! type) {
78-
fn Op[addr self: Self*](other: Other);
78+
fn Op[ref self: Self](other: Other);
7979
}
8080

8181
// Modulo: `a % b`.
@@ -86,7 +86,7 @@ interface ModWith(Other:! type) {
8686

8787
// Modulo with assignment: `a %= b`.
8888
interface ModAssignWith(Other:! type) {
89-
fn Op[addr self: Self*](other: Other);
89+
fn Op[ref self: Self](other: Other);
9090
}
9191

9292

core/prelude/operators/bitwise.carbon

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface BitAndWith(Other:! type) {
3232

3333
// Bitwise AND with assignment: `a &= b`.
3434
interface BitAndAssignWith(Other:! type) {
35-
fn Op[addr self: Self*](other: Other);
35+
fn Op[ref self: Self](other: Other);
3636
}
3737

3838
// Bitwise OR: `a | b`.
@@ -43,7 +43,7 @@ interface BitOrWith(Other:! type) {
4343

4444
// Bitwise OR with assignment: `a |= b`.
4545
interface BitOrAssignWith(Other:! type) {
46-
fn Op[addr self: Self*](other: Other);
46+
fn Op[ref self: Self](other: Other);
4747
}
4848

4949
// Bitwise XOR: `a ^ b`.
@@ -54,7 +54,7 @@ interface BitXorWith(Other:! type) {
5454

5555
// Bitwise XOR with assignment: `a ^= b`.
5656
interface BitXorAssignWith(Other:! type) {
57-
fn Op[addr self: Self*](other: Other);
57+
fn Op[ref self: Self](other: Other);
5858
}
5959

6060
// Left shift: `a << b`.
@@ -65,7 +65,7 @@ interface LeftShiftWith(Other:! type) {
6565

6666
// Left shift with assignment: `a <<= b`.
6767
interface LeftShiftAssignWith(Other:! type) {
68-
fn Op[addr self: Self*](other: Other);
68+
fn Op[ref self: Self](other: Other);
6969
}
7070

7171
// Right shift: `a >> b`.
@@ -76,7 +76,7 @@ interface RightShiftWith(Other:! type) {
7676

7777
// Right shift with assignment: `a >>= b`.
7878
interface RightShiftAssignWith(Other:! type) {
79-
fn Op[addr self: Self*](other: Other);
79+
fn Op[ref self: Self](other: Other);
8080
}
8181

8282

core/prelude/types/float.carbon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ final impl forall [N:! IntLiteral()]
7777
// Compound assignments.
7878
final impl forall [N:! IntLiteral()]
7979
Float(N) as AddAssignWith(Self) {
80-
fn Op[addr self: Self*](other: Self) = "float.add_assign";
80+
fn Op[ref self: Self](other: Self) = "float.add_assign";
8181
}
8282

8383
final impl forall [N:! IntLiteral()]
8484
Float(N) as DivAssignWith(Self) {
85-
fn Op[addr self: Self*](other: Self) = "float.div_assign";
85+
fn Op[ref self: Self](other: Self) = "float.div_assign";
8686
}
8787

8888
final impl forall [N:! IntLiteral()]
8989
Float(N) as MulAssignWith(Self) {
90-
fn Op[addr self: Self*](other: Self) = "float.mul_assign";
90+
fn Op[ref self: Self](other: Self) = "float.mul_assign";
9191
}
9292

9393
final impl forall [N:! IntLiteral()]
9494
Float(N) as SubAssignWith(Self) {
95-
fn Op[addr self: Self*](other: Self) = "float.sub_assign";
95+
fn Op[ref self: Self](other: Self) = "float.sub_assign";
9696
}

core/prelude/types/int.carbon

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -272,72 +272,72 @@ impl forall [N:! IntLiteral(), T:! ImplicitAs(Int(N))]
272272

273273
impl forall [N:! IntLiteral(), U:! ImplicitAs(Int(N))]
274274
Int(N) as AddAssignWith(U) {
275-
fn Op[addr self: Self*](other: Self) = "int.sadd_assign";
275+
fn Op[ref self: Self](other: Self) = "int.sadd_assign";
276276
}
277277

278278
impl forall [N:! IntLiteral(), U:! ImplicitAs(Int(N))]
279279
Int(N) as BitAndAssignWith(U) {
280-
fn Op[addr self: Self*](other: Self) = "int.and_assign";
280+
fn Op[ref self: Self](other: Self) = "int.and_assign";
281281
}
282282

283283
impl forall [N:! IntLiteral(), U:! ImplicitAs(Int(N))]
284284
Int(N) as BitOrAssignWith(U) {
285-
fn Op[addr self: Self*](other: Self) = "int.or_assign";
285+
fn Op[ref self: Self](other: Self) = "int.or_assign";
286286
}
287287

288288
impl forall [N:! IntLiteral(), U:! ImplicitAs(Int(N))]
289289
Int(N) as BitXorAssignWith(U) {
290-
fn Op[addr self: Self*](other: Self) = "int.xor_assign";
290+
fn Op[ref self: Self](other: Self) = "int.xor_assign";
291291
}
292292

293293
impl forall [N:! IntLiteral(), U:! ImplicitAs(Int(N))]
294294
Int(N) as DivAssignWith(U) {
295-
fn Op[addr self: Self*](other: Self) = "int.sdiv_assign";
295+
fn Op[ref self: Self](other: Self) = "int.sdiv_assign";
296296
}
297297

298298
impl forall [N:! IntLiteral(), U:! ImplicitAs(Int(N))]
299299
Int(N) as LeftShiftAssignWith(U) {
300-
fn Op[addr self: Self*](other: Self) = "int.left_shift_assign";
300+
fn Op[ref self: Self](other: Self) = "int.left_shift_assign";
301301
}
302302

303303
impl forall [N:! IntLiteral(), U:! ImplicitAs(Int(N))]
304304
Int(N) as ModAssignWith(U) {
305-
fn Op[addr self: Self*](other: Self) = "int.smod_assign";
305+
fn Op[ref self: Self](other: Self) = "int.smod_assign";
306306
}
307307

308308
impl forall [N:! IntLiteral(), U:! ImplicitAs(Int(N))]
309309
Int(N) as MulAssignWith(U) {
310-
fn Op[addr self: Self*](other: Self) = "int.smul_assign";
310+
fn Op[ref self: Self](other: Self) = "int.smul_assign";
311311
}
312312

313313
impl forall [N:! IntLiteral(), U:! ImplicitAs(Int(N))]
314314
Int(N) as RightShiftAssignWith(U) {
315-
fn Op[addr self: Self*](other: Self) = "int.right_shift_assign";
315+
fn Op[ref self: Self](other: Self) = "int.right_shift_assign";
316316
}
317317

318318
impl forall [N:! IntLiteral(), U:! ImplicitAs(Int(N))]
319319
Int(N) as SubAssignWith(U) {
320-
fn Op[addr self: Self*](other: Self) = "int.ssub_assign";
320+
fn Op[ref self: Self](other: Self) = "int.ssub_assign";
321321
}
322322

323323
// Increment and decrement.
324324

325325
// TODO: Add builtins for these to avoid emitting a call.
326326

327327
impl forall [N:! IntLiteral()] Int(N) as Dec {
328-
fn Op[addr self: Self*]() {
329-
// TODO: `*self -= 1;` should work, but fails because the `impl IntLiteral
328+
fn Op[ref self: Self]() {
329+
// TODO: `self -= 1;` should work, but fails because the `impl IntLiteral
330330
// as ImplicitAs(Int(N))` is not final, which causes us to not attempt the
331331
// conversion from `1` to `Int(N)` until runtime, when we've lost the
332332
// constant value.
333333
fn AsInt(n: IntLiteral()) -> Int(N) = "int.convert_checked";
334-
*self -= AsInt(1);
334+
self -= AsInt(1);
335335
}
336336
}
337337

338338
impl forall [N:! IntLiteral()] Int(N) as Inc {
339-
fn Op[addr self: Self*]() {
339+
fn Op[ref self: Self]() {
340340
fn AsInt(n: IntLiteral()) -> Int(N) = "int.convert_checked";
341-
*self += AsInt(1);
341+
self += AsInt(1);
342342
}
343343
}

core/prelude/types/uint.carbon

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -313,72 +313,72 @@ impl forall [N:! IntLiteral(), T:! ImplicitAs(UInt(N))]
313313

314314
impl forall [N:! IntLiteral(), U:! ImplicitAs(UInt(N))]
315315
UInt(N) as AddAssignWith(U) {
316-
fn Op[addr self: Self*](other: Self) = "int.uadd_assign";
316+
fn Op[ref self: Self](other: Self) = "int.uadd_assign";
317317
}
318318

319319
impl forall [N:! IntLiteral(), U:! ImplicitAs(UInt(N))]
320320
UInt(N) as BitAndAssignWith(U) {
321-
fn Op[addr self: Self*](other: Self) = "int.and_assign";
321+
fn Op[ref self: Self](other: Self) = "int.and_assign";
322322
}
323323

324324
impl forall [N:! IntLiteral(), U:! ImplicitAs(UInt(N))]
325325
UInt(N) as BitOrAssignWith(U) {
326-
fn Op[addr self: Self*](other: Self) = "int.or_assign";
326+
fn Op[ref self: Self](other: Self) = "int.or_assign";
327327
}
328328

329329
impl forall [N:! IntLiteral(), U:! ImplicitAs(UInt(N))]
330330
UInt(N) as BitXorAssignWith(U) {
331-
fn Op[addr self: Self*](other: Self) = "int.xor_assign";
331+
fn Op[ref self: Self](other: Self) = "int.xor_assign";
332332
}
333333

334334
impl forall [N:! IntLiteral(), U:! ImplicitAs(UInt(N))]
335335
UInt(N) as DivAssignWith(U) {
336-
fn Op[addr self: Self*](other: Self) = "int.udiv_assign";
336+
fn Op[ref self: Self](other: Self) = "int.udiv_assign";
337337
}
338338

339339
impl forall [N:! IntLiteral(), U:! ImplicitAs(UInt(N))]
340340
UInt(N) as LeftShiftAssignWith(U) {
341-
fn Op[addr self: Self*](other: Self) = "int.left_shift_assign";
341+
fn Op[ref self: Self](other: Self) = "int.left_shift_assign";
342342
}
343343

344344
impl forall [N:! IntLiteral(), U:! ImplicitAs(UInt(N))]
345345
UInt(N) as ModAssignWith(U) {
346-
fn Op[addr self: Self*](other: Self) = "int.umod_assign";
346+
fn Op[ref self: Self](other: Self) = "int.umod_assign";
347347
}
348348

349349
impl forall [N:! IntLiteral(), U:! ImplicitAs(UInt(N))]
350350
UInt(N) as MulAssignWith(U) {
351-
fn Op[addr self: Self*](other: Self) = "int.umul_assign";
351+
fn Op[ref self: Self](other: Self) = "int.umul_assign";
352352
}
353353

354354
impl forall [N:! IntLiteral(), U:! ImplicitAs(UInt(N))]
355355
UInt(N) as RightShiftAssignWith(U) {
356-
fn Op[addr self: Self*](other: Self) = "int.right_shift_assign";
356+
fn Op[ref self: Self](other: Self) = "int.right_shift_assign";
357357
}
358358

359359
impl forall [N:! IntLiteral(), U:! ImplicitAs(UInt(N))]
360360
UInt(N) as SubAssignWith(U) {
361-
fn Op[addr self: Self*](other: Self) = "int.usub_assign";
361+
fn Op[ref self: Self](other: Self) = "int.usub_assign";
362362
}
363363

364364
// Increment and decrement.
365365

366366
// TODO: Add builtins for these to avoid emitting a call.
367367

368368
impl forall [N:! IntLiteral()] UInt(N) as Dec {
369-
fn Op[addr self: Self*]() {
370-
// TODO: `*self -= 1;` should work, but fails because the `impl IntLiteral
369+
fn Op[ref self: Self]() {
370+
// TODO: `self -= 1;` should work, but fails because the `impl IntLiteral
371371
// as ImplicitAs(Int(N))` is not final, which causes us to not attempt the
372372
// conversion from `1` to `Int(N)` until runtime, when we've lost the
373373
// constant value.
374374
fn AsUInt(n: IntLiteral()) -> UInt(N) = "int.convert_checked";
375-
*self -= AsUInt(1);
375+
self -= AsUInt(1);
376376
}
377377
}
378378

379379
impl forall [N:! IntLiteral()] UInt(N) as Inc {
380-
fn Op[addr self: Self*]() {
380+
fn Op[ref self: Self]() {
381381
fn AsUInt(n: IntLiteral()) -> UInt(N) = "int.convert_checked";
382-
*self += AsUInt(1);
382+
self += AsUInt(1);
383383
}
384384
}

toolchain/check/handle_function.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -616,22 +616,13 @@ static auto IsValidBuiltinDeclaration(Context& context,
616616
call_params.consume_back();
617617
}
618618

619-
// Form the list of parameter types for the declaration.
620-
llvm::SmallVector<SemIR::TypeId> param_type_ids;
621-
param_type_ids.reserve(call_params.size());
622-
for (auto param_id : call_params) {
623-
// TODO: We also need to track whether the parameter is declared with
624-
// `var`.
625-
param_type_ids.push_back(context.insts().Get(param_id).type_id());
626-
}
627-
628619
// Get the return type. This is `()` if none was specified.
629620
auto return_type_id = function.GetDeclaredReturnType(context.sem_ir());
630621
if (!return_type_id.has_value()) {
631622
return_type_id = GetTupleType(context, {});
632623
}
633624

634-
return builtin_kind.IsValidType(context.sem_ir(), param_type_ids,
625+
return builtin_kind.IsValidType(context.sem_ir(), call_params,
635626
return_type_id);
636627
}
637628

0 commit comments

Comments
 (0)